-
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.
#13 fixed netstandard2.0 compatibility
- Loading branch information
Showing
20 changed files
with
319 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Mel Grubb | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
8 changes: 8 additions & 0 deletions
8
src/BuilderGenerator.Test.Core/BuilderGenerator.Test.Core.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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
{ | ||
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; } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
{ | ||
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[] ReadWriteArray { get; set; } = Array.Empty<string>(); | ||
|
||
public ICollection<string> ReadWriteCollection { get; set; } = new List<string>(); | ||
|
||
public IEnumerable<string> ReadWriteEnumerable { get; set; } = new List<string>(); | ||
|
||
public HashSet<string> ReadWriteHashSet { get; set; } = new HashSet<string>(); | ||
|
||
public List<string> ReadWriteList { get; set; } = new List<string>(); | ||
} | ||
} |
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,9 @@ | ||
using System; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
{ | ||
public abstract class Entity | ||
{ | ||
public Guid Id { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BuilderGenerator.Test.Core.Models.Enums; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
{ | ||
public class Order : AuditableEntity | ||
{ | ||
public DateTime OrderDate { get; set; } | ||
public ICollection<OrderItem> Orders { get; set; } = new List<OrderItem>(); | ||
public OrderStatus Status { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
{ | ||
public class OrderItem : AuditableEntity | ||
{ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Entities # | ||
|
||
This folder contains sample entities for which builders will be created. It's your standard, generic Foo/Bar/Baz hierarchy, with edge cases exercised as described blow. | ||
|
||
## Hierarchy ## | ||
|
||
Foo contains a read-only collection or Bars. | ||
Bars contains a read-only collection of Bazs. | ||
Baz has no children of its own. | ||
|
||
Each layer also contains writable collections of strings in various formats to test the Builder's ability to adapt and choose appropriate properties to handle. |
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,14 @@ | ||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace BuilderGenerator.Test.Core.Models.Entities | ||
{ | ||
public class User : AuditableEntity | ||
{ | ||
public string? FirstName { get; set; } | ||
public string? LastName { get; set; } | ||
public string? MiddleName { get; set; } | ||
public ICollection<Order> Orders { get; set; } = new List<Order>(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/BuilderGenerator.Test.Core/Models/Enums/OrderStatus.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,11 @@ | ||
namespace BuilderGenerator.Test.Core.Models.Enums | ||
{ | ||
public enum OrderStatus | ||
{ | ||
Received = 1, | ||
Processing = 2, | ||
Shipping = 3, | ||
Shipped = 4, | ||
Completed = 5, | ||
} | ||
} |
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,3 @@ | ||
# BuilderGenerator.Core # | ||
|
||
This project defines the object model used in the other framework-specific tests. It is defined as a netstandard2.0 library so that it can be used with the widest variety of consuming projects. |
18 changes: 18 additions & 0 deletions
18
src/BuilderGenerator.Test.Net60/BuilderGenerator.Test.Net60.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>net6.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.Net60/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.Net60.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,16 @@ | ||
using System; | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
|
||
namespace BuilderGenerator.Test.Net60.Builders; | ||
|
||
[BuilderFor(typeof(Order))] | ||
public partial class OrderBuilder | ||
{ | ||
public static OrderBuilder Simple() | ||
{ | ||
var builder = new OrderBuilder() | ||
.WithId(Guid.NewGuid); | ||
|
||
return builder; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/BuilderGenerator.Test.Net60/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.Net60.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.Net60.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. |
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,65 @@ | ||
using System; | ||
using BuilderGenerator.Test.Core.Models.Entities; | ||
using BuilderGenerator.Test.Net60.Builders; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
namespace BuilderGenerator.Test.Net60.Tests; | ||
|
||
[TestFixture] | ||
public class BuilderTests | ||
{ | ||
private string _firstName; | ||
private Guid _id; | ||
private string _lastName; | ||
private string _middleName; | ||
private User _result; | ||
|
||
[Test] | ||
public void Simple_does_not_populate_Orders() | ||
{ | ||
var actual = UserBuilder.Simple().Build(); | ||
actual.ShouldBeOfType<User>(); | ||
actual.Orders.ShouldBeNull(); | ||
} | ||
|
||
[Test] | ||
public void Simple_returns_a_UserBuilder() => UserBuilder.Simple().ShouldBeOfType<UserBuilder>(); | ||
|
||
[Test] | ||
public void Typical_populates_Orders() | ||
{ | ||
var actual = UserBuilder.Typical().Build(); | ||
actual.ShouldBeOfType<User>(); | ||
actual.Orders.ShouldNotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void Typical_returns_a_UserBuilder() => UserBuilder.Typical().ShouldBeOfType<UserBuilder>(); | ||
|
||
[Test] | ||
public void UserBuilder_can_set_properties() | ||
{ | ||
_result.Id.ShouldBe(_id); | ||
_result.FirstName.ShouldBe(_firstName); | ||
_result.MiddleName.ShouldBe(_middleName); | ||
_result.LastName.ShouldBe(_lastName); | ||
} | ||
|
||
[OneTimeSetUp] | ||
public void SetUp() | ||
{ | ||
_id = Guid.NewGuid(); | ||
_firstName = Guid.NewGuid().ToString(); | ||
_middleName = Guid.NewGuid().ToString(); | ||
_lastName = Guid.NewGuid().ToString(); | ||
|
||
_result = UserBuilder | ||
.Typical() | ||
.WithId(_id) | ||
.WithFirstName(_firstName) | ||
.WithMiddleName(_middleName) | ||
.WithLastName(_lastName) | ||
.Build(); | ||
} | ||
} |
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