Skip to content

Commit

Permalink
Turned on nullable types (#105)
Browse files Browse the repository at this point in the history
* Turned on nullable types
* Removed incorrect usage of IComparable in DefaultPropertyResolver

Closes #95
  • Loading branch information
roryprimrose authored May 25, 2020
1 parent 56809a6 commit f05d987
Show file tree
Hide file tree
Showing 199 changed files with 2,395 additions and 1,578 deletions.
30 changes: 30 additions & 0 deletions ModelBuilder.UnitTests/BuildActions/BuildCapabilityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace ModelBuilder.UnitTests.BuildActions
{
using System;
using FluentAssertions;
using ModelBuilder.BuildActions;
using ModelBuilder.ValueGenerators;
using Xunit;

public class BuildCapabilityTests
{
[Fact]
public void ImplementedByTypeReturnsConstructorParameter()
{
var type = typeof(EmailValueGenerator);

var sut = new BuildCapability(type);

sut.ImplementedByType.Should().Be(type);
}

[Fact]
public void ThrowsExceptionWithNullImplementedByType()
{
// ReSharper disable once ObjectCreationAsStatement
Action action = () => new BuildCapability(null!);

action.Should().Throw<ArgumentNullException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void BuildForParameterThrowsExceptionWithNullExecuteStrategy()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.Build(null, parameterInfo);
Action action = () => sut.Build(null!, parameterInfo);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -75,7 +75,7 @@ public void BuildForParameterThrowsExceptionWithNullType()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.Build(executeStrategy, (ParameterInfo) null);
Action action = () => sut.Build(executeStrategy, (ParameterInfo) null!);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -84,7 +84,7 @@ public void BuildForParameterThrowsExceptionWithNullType()
public void BuildForPropertyReturnsNullWhenNoMatchingTypeFound()
{
var buildChain = new BuildHistory();
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;

buildChain.Push(Guid.NewGuid());
buildChain.Push(DateTimeOffset.UtcNow);
Expand All @@ -104,7 +104,7 @@ public void BuildForPropertyReturnsNullWhenNoMatchingTypeFound()
public void BuildForPropertyReturnsValueMatchingType()
{
var buildChain = new BuildHistory();
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;
var expected = Guid.NewGuid().ToString();

buildChain.Push(Guid.NewGuid());
Expand All @@ -125,11 +125,11 @@ public void BuildForPropertyReturnsValueMatchingType()
[Fact]
public void BuildForPropertyThrowsExceptionWithNullExecuteStrategy()
{
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;

var sut = new CircularReferenceBuildAction();

Action action = () => sut.Build(null, propertyInfo);
Action action = () => sut.Build(null!, propertyInfo);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -141,7 +141,7 @@ public void BuildForPropertyThrowsExceptionWithNullType()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.Build(executeStrategy, (PropertyInfo) null);
Action action = () => sut.Build(executeStrategy, (PropertyInfo) null!);

action.Should().Throw<ArgumentNullException>();
}
Expand Down Expand Up @@ -195,7 +195,7 @@ public void BuildForTypeThrowsExceptionWithNullExecuteStrategy()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.Build(null, type);
Action action = () => sut.Build(null!, type);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -207,7 +207,7 @@ public void BuildForTypeThrowsExceptionWithNullType()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.Build(executeStrategy, (Type) null);
Action action = () => sut.Build(executeStrategy, (Type) null!);

action.Should().Throw<ArgumentNullException>();
}
Expand Down Expand Up @@ -258,8 +258,9 @@ public void GetBuildCapabilityForParameterReturnsCapabilityWhenBuildChainContain

var sut = new CircularReferenceBuildAction();

var actual = sut.GetBuildCapability(buildConfiguration, buildChain, parameterInfo);
var actual = sut.GetBuildCapability(buildConfiguration, buildChain, parameterInfo)!;

actual.Should().NotBeNull();
actual.SupportsCreate.Should().BeTrue();
actual.SupportsPopulate.Should().BeFalse();
actual.AutoDetectConstructor.Should().BeFalse();
Expand All @@ -276,7 +277,7 @@ public void GetBuildCapabilityForParameterThrowsExceptionWithNullBuildChain()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.GetBuildCapability(buildConfiguration, null, parameterInfo);
Action action = () => sut.GetBuildCapability(buildConfiguration, null!, parameterInfo);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -289,7 +290,7 @@ public void GetBuildCapabilityForParameterThrowsExceptionWithNullType()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.GetBuildCapability(buildConfiguration, buildChain, (ParameterInfo) null);
Action action = () => sut.GetBuildCapability(buildConfiguration, buildChain, (ParameterInfo) null!);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -299,7 +300,7 @@ public void GetBuildCapabilityForPropertyReturnsNullWhenBuildChainDoesNotContain
{
var buildConfiguration = new BuildConfiguration();
var buildChain = new BuildHistory();
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;

buildChain.Push(Guid.NewGuid());

Expand All @@ -315,7 +316,7 @@ public void GetBuildCapabilityForPropertyReturnsNullWhenBuildChainIsEmpty()
{
var buildConfiguration = new BuildConfiguration();
var buildChain = new BuildHistory();
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;

var sut = new CircularReferenceBuildAction();

Expand All @@ -329,7 +330,7 @@ public void GetBuildCapabilityForPropertyReturnsCapabilityWhenBuildChainContains
{
var buildConfiguration = new BuildConfiguration();
var buildChain = new BuildHistory();
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;

buildChain.Push(Guid.NewGuid());
buildChain.Push(Guid.NewGuid().ToString());
Expand All @@ -339,7 +340,8 @@ public void GetBuildCapabilityForPropertyReturnsCapabilityWhenBuildChainContains

var actual = sut.GetBuildCapability(buildConfiguration, buildChain, propertyInfo);

actual.SupportsCreate.Should().BeTrue();
actual.Should().NotBeNull();
actual!.SupportsCreate.Should().BeTrue();
actual.SupportsPopulate.Should().BeFalse();
actual.AutoDetectConstructor.Should().BeFalse();
actual.AutoPopulate.Should().BeFalse();
Expand All @@ -349,12 +351,12 @@ public void GetBuildCapabilityForPropertyReturnsCapabilityWhenBuildChainContains
[Fact]
public void GetBuildCapabilityForPropertyThrowsExceptionWithNullBuildChain()
{
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName));
var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName))!;
var buildConfiguration = new BuildConfiguration();

var sut = new CircularReferenceBuildAction();

Action action = () => sut.GetBuildCapability(buildConfiguration, null, propertyInfo);
Action action = () => sut.GetBuildCapability(buildConfiguration, null!, propertyInfo);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -367,7 +369,7 @@ public void GetBuildCapabilityForPropertyThrowsExceptionWithNullType()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.GetBuildCapability(buildConfiguration, buildChain, (PropertyInfo) null);
Action action = () => sut.GetBuildCapability(buildConfiguration, buildChain, (PropertyInfo) null!);

action.Should().Throw<ArgumentNullException>();
}
Expand Down Expand Up @@ -417,7 +419,8 @@ public void GetBuildCapabilityForTypeReturnsCapabilityWhenBuildChainContainsMatc

var actual = sut.GetBuildCapability(buildConfiguration, buildChain, type);

actual.SupportsCreate.Should().BeTrue();
actual.Should().NotBeNull();
actual!.SupportsCreate.Should().BeTrue();
actual.SupportsPopulate.Should().BeFalse();
actual.AutoDetectConstructor.Should().BeFalse();
actual.AutoPopulate.Should().BeFalse();
Expand All @@ -432,7 +435,7 @@ public void GetBuildCapabilityForTypeThrowsExceptionWithNullBuildChain()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.GetBuildCapability(buildConfiguration, null, type);
Action action = () => sut.GetBuildCapability(buildConfiguration, null!, type);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -445,7 +448,7 @@ public void GetBuildCapabilityForTypeThrowsExceptionWithNullType()

var sut = new CircularReferenceBuildAction();

Action action = () => sut.GetBuildCapability(buildConfiguration, buildChain, (Type) null);
Action action = () => sut.GetBuildCapability(buildConfiguration, buildChain, (Type) null!);

action.Should().Throw<ArgumentNullException>();
}
Expand All @@ -455,7 +458,7 @@ public void PopulateThrowsException()
{
var sut = new CircularReferenceBuildAction();

Action action = () => sut.Populate(null, null);
Action action = () => sut.Populate(null!, null!);

action.Should().Throw<NotSupportedException>();
}
Expand Down
Loading

0 comments on commit f05d987

Please sign in to comment.