public void NullExpression_ShouldThrow() { // arrange var builderMock = new Mock <IDynamicBuilder <TestClass> >(); // act Action getOverwrittenValue = () => DynamicBuilderExtensions.GetOverwrittenValue <TestClass, string>(builderMock.Object, null); // assert getOverwrittenValue.Should().Throw <ArgumentNullException>(); }
public void NullBuilder_ShouldThrow() { // arrange IDynamicBuilder <TestClass> builder = null; // act Action getOverwrittenValue = () => DynamicBuilderExtensions.GetOverwrittenValue(builder, e => e.StringProperty); // assert getOverwrittenValue.Should().Throw <ArgumentNullException>(); }
public void ExpressionIsMethodCall_ShouldThrow() { // arrange var builderMock = new Mock <IDynamicBuilder <TestClass> >(); // act Action getOverwrittenValue = () => DynamicBuilderExtensions.GetOverwrittenValue(builderMock.Object, e => e.StringFunction()); // assert var exception = getOverwrittenValue.Should().Throw <ArgumentException>().And; exception.Data[Errors.ErrorCodeExceptionDataKey].Should().Be(Errors.OnlyMemberAccessExpressionAreAllowed.Code); }
public void StructProperty_ShouldGetOverwrittenValue() { // arrange Guid expectedResult = Guid.NewGuid(); var builderMock = new Mock <IDynamicBuilder <TestClass> >(); builderMock .Setup(e => e.IsOverwritten(nameof(TestClass.GuidProperty))) .Returns(true); builderMock .Setup(e => e.GetOverwrittenValue(nameof(TestClass.GuidProperty))) .Returns(expectedResult); // act var result = DynamicBuilderExtensions.GetOverwrittenValue(builderMock.Object, e => e.GuidProperty); // assert result.Should().Be(expectedResult); }
public void NullableProperty_ShouldGetOverwrittenValue() { // arrange int?expectedResult = 1; var builderMock = new Mock <IDynamicBuilder <TestClass> >(); builderMock .Setup(e => e.IsOverwritten(nameof(TestClass.NullableInt32Property))) .Returns(true); builderMock .Setup(e => e.GetOverwrittenValue(nameof(TestClass.NullableInt32Property))) .Returns((int?)1); // act int?result = DynamicBuilderExtensions.GetOverwrittenValue(builderMock.Object, e => e.NullableInt32Property); // assert result.Should().Be(expectedResult); }