-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/113 factory type creator (#124)
* Added FactoryTypeCreator * Updated DefaultConstructorResolver to return null when no constructor found * Updated DefaultTypeCreator to not create types without a public constructors
- Loading branch information
1 parent
0c03975
commit a853e95
Showing
16 changed files
with
735 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace ModelBuilder.UnitTests.Models | ||
{ | ||
using System; | ||
|
||
public class FactoryItem | ||
{ | ||
private FactoryItem() | ||
{ | ||
Value = Guid.NewGuid(); | ||
} | ||
|
||
public static FactoryItem Create() | ||
{ | ||
return new FactoryItem(); | ||
} | ||
|
||
public Guid Value { get; } | ||
} | ||
} |
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,19 @@ | ||
namespace ModelBuilder.UnitTests.Models | ||
{ | ||
using System; | ||
|
||
public class FactoryWithValue | ||
{ | ||
private FactoryWithValue(Guid value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static FactoryWithValue Create(Guid value) | ||
{ | ||
return new FactoryWithValue(value); | ||
} | ||
|
||
public Guid Value { get; } | ||
} | ||
} |
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,19 @@ | ||
namespace ModelBuilder.UnitTests.Models | ||
{ | ||
using System; | ||
|
||
public class NotFactoryItem | ||
{ | ||
private NotFactoryItem() | ||
{ | ||
Value = Guid.NewGuid(); | ||
} | ||
|
||
public static NotFactoryItem Create(NotFactoryItem item) | ||
{ | ||
return item; | ||
} | ||
|
||
public Guid Value { get; } | ||
} | ||
} |
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,7 @@ | ||
namespace ModelBuilder.UnitTests.Models | ||
{ | ||
public class NullablePropertyModel<T> where T : class | ||
{ | ||
public T Value { get; set; } = default!; | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
ModelBuilder.UnitTests/Scenarios/NonConstructorCreationTests.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,36 @@ | ||
namespace ModelBuilder.UnitTests.Scenarios | ||
{ | ||
using System; | ||
using FluentAssertions; | ||
using ModelBuilder.UnitTests.Models; | ||
using Xunit; | ||
|
||
public class NonConstructorCreationTests | ||
{ | ||
[Fact] | ||
public void CanCreateViaStaticFactoryMethodWithCreatedParameters() | ||
{ | ||
var actual = Model.Create<FactoryWithValue>(); | ||
|
||
actual.Value.Should().NotBeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void CanCreateViaStaticFactoryMethodWithoutParameters() | ||
{ | ||
var actual = Model.Create<FactoryItem>(); | ||
|
||
actual.Value.Should().NotBeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void CanCreateViaStaticFactoryMethodWithProvidedParameters() | ||
{ | ||
var value = Guid.NewGuid(); | ||
|
||
var actual = Model.Create<FactoryWithValue>(value); | ||
|
||
actual.Value.Should().Be(value); | ||
} | ||
} | ||
} |
Oops, something went wrong.