-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The Builder<T> delegate is now public, enabling generated extensions to be called from outside the scope of the current assembly.
- Loading branch information
Showing
10 changed files
with
165 additions
and
20 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
41 changes: 41 additions & 0 deletions
41
src/Fluentify.Console.Tests/Record/Example/Simple/MovieTests/WhenMovieIsBuilt.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,41 @@ | ||
namespace Fluentify.Console.Record.Example.Simple.MovieTests; | ||
|
||
public sealed class WhenMovieIsBuilt | ||
{ | ||
[Fact] | ||
public void GivenAMovieThenTheInstanceIsCreated() | ||
{ | ||
// Arrange | ||
var original = new Movie(); | ||
|
||
var expected = new Movie | ||
{ | ||
Actors = | ||
[ | ||
new Actor | ||
{ | ||
Birthday = 1940, | ||
FirstName = "Patrick", | ||
Surname = "Stewart", | ||
}, | ||
], | ||
Genre = Genre.SciFi, | ||
ReleasedOn = new DateOnly(1996, 12, 13), | ||
Title = "Star Trek: First Contact", | ||
}; | ||
|
||
// Act | ||
Movie actual = original | ||
.OfGenre(Genre.SciFi) | ||
.WithTitle("Star Trek: First Contact") | ||
.ReleasedOn(new DateOnly(1996, 12, 13)) | ||
.WithActors(actor => actor | ||
.WithFirstName("Patrick") | ||
.WithSurname("Stewart") | ||
.BornIn(1940)); | ||
|
||
// Assert | ||
_ = actual.Should().NotBe(original); | ||
_ = actual.Should().BeEquivalentTo(expected); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...uentify.Console.Tests/Record/Example/Simple/MyServiceBuilderTests/WhenMyServiceIsBuilt.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 @@ | ||
namespace Fluentify.Console.Record.Example.Simple.MyServiceBuilderTests; | ||
|
||
public sealed class WhenMyServiceIsBuilt | ||
{ | ||
[Fact] | ||
public void GivenRequiredValuesThenTheInstanceIsBuilt() | ||
{ | ||
// Arrange | ||
const string connectionString = "The String"; | ||
const int timeout = 30; | ||
|
||
// Act | ||
MyService service = MyServiceBuilder | ||
.Empty | ||
.ConnectsTo(connectionString) | ||
.Waits(timeout) | ||
.Build(); | ||
|
||
// Assert | ||
_ = service.Should().NotBeNull(); | ||
_ = service.ConnectionString.Should().Be(connectionString); | ||
_ = service.Timeout.TotalSeconds.Should().Be(timeout); | ||
} | ||
} |
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 Fluentify.Console.Record.Example; | ||
|
||
[Fluentify] | ||
public partial record Actor( | ||
[Descriptor("BornIn")] int Birthday, | ||
string FirstName, | ||
string Surname); |
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 Fluentify.Console.Record.Example.Simple; | ||
|
||
public enum Genre | ||
{ | ||
Horror, | ||
SciFi, | ||
} |
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,10 @@ | ||
namespace Fluentify.Console.Record.Example; | ||
|
||
using Fluentify.Console.Record.Example.Simple; | ||
|
||
[Fluentify] | ||
public partial record Movie( | ||
Actor[] Actors, | ||
[Descriptor("OfGenre")] Genre Genre, | ||
[Descriptor("ReleasedOn")] DateOnly ReleasedOn, | ||
string Title); |
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,17 @@ | ||
namespace Fluentify.Console.Record.Example.Simple; | ||
|
||
public class MyService | ||
{ | ||
public MyService(string connectionString, TimeSpan timeout) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(connectionString); | ||
ArgumentOutOfRangeException.ThrowIfLessThan(timeout.TotalSeconds, 1); | ||
|
||
ConnectionString = connectionString; | ||
Timeout = timeout; | ||
} | ||
|
||
public string ConnectionString { get; } | ||
|
||
public TimeSpan Timeout { get; } | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Fluentify.Console/Record/Example/Simple/MyServiceBuilder.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,14 @@ | ||
namespace Fluentify.Console.Record.Example.Simple; | ||
|
||
[Fluentify] | ||
public partial record MyServiceBuilder( | ||
[Descriptor("ConnectsTo")] string ConnectionString, | ||
[Descriptor("Waits")] int Timeout) | ||
{ | ||
public static MyServiceBuilder Empty => new(); | ||
|
||
public MyService Build() | ||
{ | ||
return new MyService(ConnectionString, TimeSpan.FromSeconds(Timeout)); | ||
} | ||
} |
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