-
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.
* Updated TypeCreatorBase to include logging of type mapping * Added WriteLog extension methods
- Loading branch information
1 parent
7826b6f
commit e4c8fc2
Showing
17 changed files
with
731 additions
and
122 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
ModelBuilder.UnitTests/BuildConfigurationExtensionsTests.WriteLog.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,69 @@ | ||
namespace ModelBuilder.UnitTests | ||
{ | ||
using System; | ||
using FluentAssertions; | ||
using ModelBuilder.UnitTests.Models; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
public partial class BuildConfigurationExtensionsTests | ||
{ | ||
[Fact] | ||
public void WriteLogForExecuteStrategyReturnsExecuteStrategyWithLogging() | ||
{ | ||
var configuration = Substitute.For<IBuildConfiguration>(); | ||
|
||
var actual = configuration.WriteLog(_output.WriteLine); | ||
|
||
actual.Should().BeAssignableTo<IExecuteStrategy>(); | ||
actual.Should().NotBeOfType<DefaultExecuteStrategy>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyThrowsExceptionWithNullAction() | ||
{ | ||
var configuration = Substitute.For<IBuildConfiguration>(); | ||
|
||
Action action = () => configuration.WriteLog(null!); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyThrowsExceptionWithNullConfiguration() | ||
{ | ||
Action action = () => BuildConfigurationExtensions.WriteLog(null!, _output.WriteLine); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTReturnsExecuteStrategyWithLogging() | ||
{ | ||
var configuration = Substitute.For<IBuildConfiguration>(); | ||
|
||
var actual = configuration.WriteLog<Person>(_output.WriteLine); | ||
|
||
actual.Should().BeAssignableTo<IExecuteStrategy<Person>>(); | ||
actual.Should().NotBeOfType<DefaultExecuteStrategy<Person>>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTThrowsExceptionWithNullAction() | ||
{ | ||
var configuration = Substitute.For<IBuildConfiguration>(); | ||
|
||
Action action = () => configuration.WriteLog<Person>(null!); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTThrowsExceptionWithNullConfiguration() | ||
{ | ||
Action action = () => BuildConfigurationExtensions.WriteLog<Person>(null!, _output.WriteLine); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
} | ||
} |
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
185 changes: 185 additions & 0 deletions
185
ModelBuilder.UnitTests/ExecuteStrategyExtensionsTests.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,185 @@ | ||
namespace ModelBuilder.UnitTests | ||
{ | ||
using System; | ||
using FluentAssertions; | ||
using ModelBuilder.UnitTests.Models; | ||
using NSubstitute; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public class ExecuteStrategyExtensionsTests | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public ExecuteStrategyExtensionsTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public void BuildChainReturnsValueFromExecuteStrategy() | ||
{ | ||
var expected = Substitute.For<IBuildChain>(); | ||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
executeStrategy.BuildChain.Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(_output.WriteLine).BuildChain; | ||
|
||
actual.Should().BeSameAs(expected); | ||
} | ||
|
||
[Fact] | ||
public void ConfigurationReturnsValueFromExecuteStrategy() | ||
{ | ||
var expected = Substitute.For<IBuildConfiguration>(); | ||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
executeStrategy.Configuration.Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(_output.WriteLine).Configuration; | ||
|
||
actual.Should().BeSameAs(expected); | ||
} | ||
|
||
[Fact] | ||
public void LogReturnsValueFromExecuteStrategy() | ||
{ | ||
var expected = Substitute.For<IBuildLog>(); | ||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
executeStrategy.Log.Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(_output.WriteLine).Log; | ||
|
||
actual.Should().BeSameAs(expected); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogCallsInitializeOnExecuteStrategy() | ||
{ | ||
var configuration = Substitute.For<IBuildConfiguration>(); | ||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
executeStrategy.WriteLog(_output.WriteLine).Initialize(configuration); | ||
|
||
executeStrategy.Received().Initialize(configuration); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyThrowsExceptionWithNullAction() | ||
{ | ||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
Action action = () => executeStrategy.WriteLog(null!); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyThrowsExceptionWithNullExecuteStrategy() | ||
{ | ||
Action action = () => ExecuteStrategyExtensions.WriteLog(null!, _output.WriteLine); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTThrowsExceptionWithNullAction() | ||
{ | ||
var executeStrategy = Substitute.For<IExecuteStrategy<Person>>(); | ||
|
||
Action action = () => executeStrategy.WriteLog(null!); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTThrowsExceptionWithNullExecuteStrategy() | ||
{ | ||
Action action = () => ExecuteStrategyExtensions.WriteLog<Person>(null!, _output.WriteLine); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTWritesLogOnCreate() | ||
{ | ||
var count = 0; | ||
var expected = new Person(); | ||
|
||
var executeStrategy = Substitute.For<IExecuteStrategy<Person>>(); | ||
|
||
executeStrategy.Create().Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(x => | ||
{ | ||
count++; | ||
_output.WriteLine(x); | ||
}).Create(); | ||
|
||
actual.Should().Be(expected); | ||
count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyTWritesLogOnPopulate() | ||
{ | ||
var count = 0; | ||
var expected = new Person(); | ||
|
||
var executeStrategy = Substitute.For<IExecuteStrategy<Person>>(); | ||
|
||
executeStrategy.Populate(expected).Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(x => | ||
{ | ||
count++; | ||
_output.WriteLine(x); | ||
}).Populate(expected); | ||
|
||
actual.Should().Be(expected); | ||
count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyWritesLogOnCreate() | ||
{ | ||
var count = 0; | ||
var expected = new Person(); | ||
|
||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
executeStrategy.Create(typeof(Person)).Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(x => | ||
{ | ||
count++; | ||
_output.WriteLine(x); | ||
}).Create(typeof(Person)); | ||
|
||
actual.Should().Be(expected); | ||
count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void WriteLogForExecuteStrategyWritesLogOnPopulate() | ||
{ | ||
var count = 0; | ||
var expected = new Person(); | ||
|
||
var executeStrategy = Substitute.For<IExecuteStrategy>(); | ||
|
||
executeStrategy.Populate(expected).Returns(expected); | ||
|
||
var actual = executeStrategy.WriteLog(x => | ||
{ | ||
count++; | ||
_output.WriteLine(x); | ||
}).Populate(expected); | ||
|
||
actual.Should().Be(expected); | ||
count.Should().Be(1); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.