-
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.
Features/72 update build configuration item (#92)
* Added extension methods to configure items registered in IBuildConfiguration. * Updated EmailValueGenerator to remove special characters when generating the address * Fixed bug in CultureValueGenerator which would return an empty culture name. Closes #72
- Loading branch information
1 parent
f2e13e7
commit 340a9f5
Showing
32 changed files
with
3,034 additions
and
2,078 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
194 changes: 194 additions & 0 deletions
194
ModelBuilder.UnitTests/BuildConfigurationExtensionsTests.CreationRule.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,194 @@ | ||
namespace ModelBuilder.UnitTests | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using FluentAssertions; | ||
using ModelBuilder.CreationRules; | ||
using ModelBuilder.UnitTests.Models; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
public partial class BuildConfigurationExtensionsTests | ||
{ | ||
[Fact] | ||
public void AddCreationRuleAddsRuleToCompiler() | ||
{ | ||
var sut = new BuildConfiguration(); | ||
|
||
sut.AddCreationRule<DummyCreationRule>(); | ||
|
||
var actual = sut.CreationRules.Single(); | ||
|
||
actual.Should().BeOfType<DummyCreationRule>(); | ||
} | ||
|
||
[Fact] | ||
public void AddCreationRuleThrowsExceptionWithNullCompiler() | ||
{ | ||
Action action = () => BuildConfigurationExtensions.AddCreationRule<DummyCreationRule>(null); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AddCreationRuleWithExpressionAddsRuleToCompiler() | ||
{ | ||
var priority = Environment.TickCount; | ||
var value = Guid.NewGuid().ToString(); | ||
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)); | ||
|
||
var sut = new BuildConfiguration(); | ||
|
||
sut.AddCreationRule<Person>(x => x.FirstName, priority, value); | ||
|
||
var rule = sut.CreationRules.Single(); | ||
|
||
rule.Priority.Should().Be(priority); | ||
|
||
var actual = rule.Create(null, propertyInfo); | ||
|
||
actual.Should().Be(value); | ||
} | ||
|
||
[Fact] | ||
public void AddCreationRuleWithExpressionThrowsExceptionWithNullCompiler() | ||
{ | ||
var priority = Environment.TickCount; | ||
var value = Guid.NewGuid().ToString(); | ||
|
||
Action action = () => | ||
BuildConfigurationExtensions.AddCreationRule<Person>(null, x => x.FirstName, priority, value); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AddCreationRuleWithExpressionThrowsExceptionWithNullExpression() | ||
{ | ||
var priority = Environment.TickCount; | ||
var value = Guid.NewGuid().ToString(); | ||
|
||
var sut = new BuildConfiguration(); | ||
|
||
Action action = () => sut.AddCreationRule((Expression<Func<Person, object>>) null, priority, value); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AddWithCreationRuleAddsRuleToCompiler() | ||
{ | ||
var rule = new ExpressionCreationRule<Person>(x => x.FirstName, (object) null, Environment.TickCount); | ||
|
||
var sut = new BuildConfiguration(); | ||
|
||
sut.Add(rule); | ||
|
||
sut.CreationRules.Should().Contain(rule); | ||
} | ||
|
||
[Fact] | ||
public void AddWithCreationRuleThrowsExceptionWithNullCompiler() | ||
{ | ||
var rule = new ExpressionCreationRule<Person>(x => x.FirstName, (object) null, Environment.TickCount); | ||
|
||
Action action = () => BuildConfigurationExtensions.Add(null, rule); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AddWithCreationRuleThrowsExceptionWithNullRule() | ||
{ | ||
var sut = Substitute.For<IBuildConfiguration>(); | ||
|
||
Action action = () => sut.Add((ICreationRule) null); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void RemoveCreationRuleRemovesMultipleMatchingRulesFromCompiler() | ||
{ | ||
var sut = new BuildConfiguration(); | ||
|
||
sut.AddCreationRule<DummyCreationRule>(); | ||
sut.AddCreationRule<DummyCreationRule>(); | ||
sut.AddCreationRule<DummyCreationRule>(); | ||
sut.RemoveCreationRule<DummyCreationRule>(); | ||
|
||
sut.CreationRules.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void RemoveCreationRuleRemovesRulesFromCompiler() | ||
{ | ||
var sut = new BuildConfiguration(); | ||
|
||
sut.AddCreationRule<DummyCreationRule>(); | ||
sut.RemoveCreationRule<DummyCreationRule>(); | ||
|
||
sut.CreationRules.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void RemoveCreationRuleThrowsExceptionWithNullCompiler() | ||
{ | ||
Action action = () => BuildConfigurationExtensions.RemoveCreationRule<DummyCreationRule>(null); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void UpdateCreationRuleThrowsExceptionWhenRuleNotFound() | ||
{ | ||
var sut = new BuildConfiguration(); | ||
|
||
Action action = () => sut.UpdateCreationRule<RegexCreationRule>(x => | ||
{ | ||
// Do nothing | ||
}); | ||
|
||
action.Should().Throw<InvalidOperationException>(); | ||
} | ||
|
||
[Fact] | ||
public void UpdateCreationRuleThrowsExceptionWithNullAction() | ||
{ | ||
var sut = Substitute.For<IBuildConfiguration>(); | ||
|
||
Action action = () => sut.UpdateCreationRule<RegexCreationRule>(null); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void UpdateCreationRuleThrowsExceptionWithNullConfiguration() | ||
{ | ||
Action action = () => BuildConfigurationExtensions.UpdateCreationRule<RegexCreationRule>(null, x => | ||
{ | ||
// Do nothing | ||
}); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void UpdateCreationRuleUpdateMatchingRule() | ||
{ | ||
var expected = Guid.NewGuid(); | ||
var sut = new BuildConfiguration(); | ||
var rule = new DummyCreationRule | ||
{ | ||
Value = expected | ||
}; | ||
|
||
sut.CreationRules.Add(rule); | ||
|
||
sut.UpdateCreationRule<DummyCreationRule>(x => { x.Value = expected; }); | ||
|
||
rule.Value.Should().Be(expected); | ||
} | ||
} | ||
} |
Oops, something went wrong.