示例#1
0
            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>();
            }
示例#2
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action getOverwrittenValue = () => DynamicBuilderExtensions.GetOverwrittenValue(builder, e => e.StringProperty);

                // assert
                getOverwrittenValue.Should().Throw <ArgumentNullException>();
            }
示例#3
0
            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);
            }
示例#4
0
            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);
            }
示例#5
0
            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);
            }