-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #15 - Complete * Add .Net 5 to pipeline setups
- Loading branch information
Showing
26 changed files
with
636 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 7 additions & 8 deletions
15
src/BuilderGenerator.Test.Core/Models/Entities/AuditableEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
using System; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
namespace BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
public abstract class AuditableEntity : Entity | ||
{ | ||
public abstract class AuditableEntity : Entity | ||
{ | ||
public DateTime CreatedAt { get; set; } | ||
public string CreatedBy { get; set; } | ||
public DateTime UpdatedAt { get; set; } | ||
public string UpdatedBy { get; set; } | ||
} | ||
public DateTime CreatedAt { get; set; } | ||
public string CreatedBy { get; set; } | ||
public DateTime UpdatedAt { get; set; } | ||
public string UpdatedBy { get; set; } | ||
} |
27 changes: 13 additions & 14 deletions
27
src/BuilderGenerator.Test.Core/Models/Entities/CollectionTypesSample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
namespace BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
public class CollectionTypesSample | ||
{ | ||
public class CollectionTypesSample | ||
{ | ||
public string[] ReadOnlyArray { get; } = Array.Empty<string>(); | ||
public ICollection<string> ReadOnlyCollection { get; } = new List<string>(); | ||
public IEnumerable<string> ReadOnlyEnumerable { get; } = new List<string>(); | ||
public HashSet<string> ReadOnlyHashSet { get; } = new HashSet<string>(); | ||
public List<string> ReadOnlyList { get; } = new List<string>(); | ||
public string[] ReadOnlyArray { get; } = Array.Empty<string>(); | ||
public ICollection<string> ReadOnlyCollection { get; } = new List<string>(); | ||
public IEnumerable<string> ReadOnlyEnumerable { get; } = new List<string>(); | ||
public HashSet<string> ReadOnlyHashSet { get; } = new(); | ||
public List<string> ReadOnlyList { get; } = new(); | ||
|
||
public string[] ReadWriteArray { get; set; } = Array.Empty<string>(); | ||
public string[] ReadWriteArray { get; set; } = Array.Empty<string>(); | ||
|
||
public ICollection<string> ReadWriteCollection { get; set; } = new List<string>(); | ||
public ICollection<string> ReadWriteCollection { get; set; } = new List<string>(); | ||
|
||
public IEnumerable<string> ReadWriteEnumerable { get; set; } = new List<string>(); | ||
public IEnumerable<string> ReadWriteEnumerable { get; set; } = new List<string>(); | ||
|
||
public HashSet<string> ReadWriteHashSet { get; set; } = new HashSet<string>(); | ||
public HashSet<string> ReadWriteHashSet { get; set; } = new(); | ||
|
||
public List<string> ReadWriteList { get; set; } = new List<string>(); | ||
} | ||
public List<string> ReadWriteList { get; set; } = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
using System; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
namespace BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
public abstract class Entity | ||
{ | ||
public abstract class Entity | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
public Guid Id { get; set; } | ||
|
||
// The Builders should only expose this in builder classes where the attribute has enabled it | ||
internal string InternalString { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
src/BuilderGenerator.Test.Core/Models/Entities/OrderItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
using System; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
namespace BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
public class OrderItem : AuditableEntity | ||
{ | ||
public class OrderItem : AuditableEntity | ||
{ | ||
public Guid ItemId { get; set; } | ||
public decimal Price { get; set; } | ||
public int Quantity { get; set; } | ||
} | ||
public Guid ItemId { get; set; } | ||
public decimal Price { get; set; } | ||
public int Quantity { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/BuilderGenerator.Test.Net50/BuilderGenerator.Test.Net50.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BuilderGenerator.Test.Core\BuilderGenerator.Test.Core.csproj" /> | ||
<ProjectReference Include="..\BuilderGenerator\BuilderGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
<PackageReference Include="Shouldly" Version="4.0.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/BuilderGenerator.Test.Net50/Builders/CollectionTypeSampleBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
namespace BuilderGenerator.Test.Net50.Builders; | ||
|
||
[BuilderFor(typeof(CollectionTypesSample))] | ||
public partial class CollectionTypeSampleBuilder | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
namespace BuilderGenerator.Test.Net50.Builders; | ||
|
||
[BuilderFor(typeof(Order), true)] | ||
public partial class OrderBuilder | ||
{ | ||
public static OrderBuilder Simple() | ||
{ | ||
var builder = new OrderBuilder() | ||
.WithId(Guid.NewGuid); | ||
|
||
return builder; | ||
} | ||
|
||
public static OrderBuilder Typical() | ||
{ | ||
var builder = Simple() | ||
.WithItems( | ||
() => new List<OrderItem> | ||
{ | ||
OrderItemBuilder.Simple().Build(), | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/BuilderGenerator.Test.Net50/Builders/OrderItemBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
namespace BuilderGenerator.Test.Net50.Builders; | ||
|
||
[BuilderFor(typeof(OrderItem))] | ||
public partial class OrderItemBuilder | ||
{ | ||
public static OrderItemBuilder Simple() | ||
{ | ||
var builder = new OrderItemBuilder() | ||
.WithId(Guid.NewGuid); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Partial Builders # | ||
|
||
This folder contains the hand-written half of any builders. Create static factory methods for each well-known or named object instance you want to create. | ||
|
||
## Suggestions ## | ||
|
||
In addition to specific factory methods, you should define some general-purpose methods such as: | ||
|
||
### Simple/Minimal ### | ||
|
||
Creates the simplest, most minimal instance that will pass validation. Only fill in the required fields, and leave everything else at their default values. This can serve as the starting point for other, more specific factory methods. For instance, a minimal Customer may be missing address information, and would have no orders. | ||
|
||
### Typical ### | ||
|
||
This method should return a "typical" example of the class. For a Customer entity, this might mean that the shipping and billing addresses are filled in, and the Customer has multiple orders in various states. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
namespace BuilderGenerator.Test.Net50.Builders; | ||
|
||
[BuilderFor(typeof(User))] | ||
public partial class UserBuilder | ||
{ | ||
public static UserBuilder Simple() | ||
{ | ||
var builder = new UserBuilder() | ||
.WithId(Guid.NewGuid) | ||
.WithFirstName(() => Guid.NewGuid().ToString()) | ||
.WithMiddleName(() => Guid.NewGuid().ToString()) | ||
.WithLastName(() => Guid.NewGuid().ToString()); | ||
|
||
return builder; | ||
} | ||
|
||
public static UserBuilder Typical() | ||
{ | ||
var builder = Simple() | ||
.WithOrders( | ||
() => new List<Order> | ||
{ | ||
OrderBuilder.Simple().Build(), | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# BuilderGenerator.Test.Net60 # | ||
|
||
This project provides tests the BuilderGenerator package being used in a .Net 6.0 project using a simple series of inter-related classes defined in the BuiderGenerator.Test.Core project. | ||
|
||
The reference to the BuilderGenerator is a direct project reference, so it can be used to rapidly check the results of changes, but does not represent the real-world usage of the generator. It tests the functionality of the builder, but not the deployment mechanism. |
66 changes: 66 additions & 0 deletions
66
src/BuilderGenerator.Test.Net50/Tests/OrderBuilderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
using BuilderGenerator.Test.Core.Models.Enums; | ||
using BuilderGenerator.Test.Net50.Builders; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
namespace BuilderGenerator.Test.Net50.Tests; | ||
|
||
[TestFixture] | ||
public class OrderBuilderTests | ||
{ | ||
private Guid _id; | ||
private string _internalString; | ||
private DateTime _orderDate; | ||
private Order _result; | ||
private OrderStatus _status; | ||
|
||
[Test] | ||
public void OrderBuilder_can_set_properties() | ||
{ | ||
_result.Id.ShouldBe(_id); | ||
_result.InternalString.ShouldBe(_internalString); | ||
_result.OrderDate.ShouldBe(_orderDate); | ||
_result.Status.ShouldBe(_status); | ||
} | ||
|
||
[Test] | ||
public void Simple_does_not_populate_Items() | ||
{ | ||
var actual = OrderBuilder.Simple().Build(); | ||
actual.ShouldBeOfType<Order>(); | ||
actual.Items.ShouldBeNull(); | ||
} | ||
|
||
[Test] | ||
public void Simple_returns_an_OrderBuilder() => OrderBuilder.Simple().ShouldBeOfType<OrderBuilder>(); | ||
|
||
[Test] | ||
public void Typical_populates_Items() | ||
{ | ||
var actual = OrderBuilder.Typical().Build(); | ||
actual.ShouldBeOfType<Order>(); | ||
actual.Items.ShouldNotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void Typical_returns_an_OrderBuilder() => OrderBuilder.Typical().ShouldBeOfType<OrderBuilder>(); | ||
|
||
[OneTimeSetUp] | ||
public void SetUp() | ||
{ | ||
_id = Guid.NewGuid(); | ||
_orderDate = DateTime.Now; | ||
_status = OrderStatus.Processing; | ||
_internalString = Guid.NewGuid().ToString(); | ||
|
||
_result = OrderBuilder | ||
.Typical() | ||
.WithId(_id) | ||
.WithInternalString(_internalString) | ||
.WithOrderDate(_orderDate) | ||
.WithStatus(_status) | ||
.Build(); | ||
} | ||
} |
Oops, something went wrong.