예제 #1
0
            public void NullBuildChildAction_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClassParent> >();

                // act
                Action withBuilderDependentChild = () => DynamicBuilderExtensions.WithBuilderDependentChild(builderMock.Object, p => p.Child, null);

                // assert
                withBuilderDependentChild.Should().Throw <ArgumentNullException>();
            }
예제 #2
0
            public void NullPropertyFunc_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClassParent> >();

                // act
                Action withBuilderDependentChild = () => DynamicBuilderExtensions.WithBuilderDependentChild <TestClassParent, TestClassChild>(builderMock.Object, null, (parentBuilder, childBuilder) => childBuilder
                                                                                                                                              .WithValue(c => c.ChildValueProperty, parentBuilder.GetOverwrittenValue(e => e.ParentValueProperty) + 1));

                // assert
                withBuilderDependentChild.Should().Throw <ArgumentNullException>();
            }
예제 #3
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClassParent> builder = null;

                // act
                Action withBuilderDependentChild = () => DynamicBuilderExtensions.WithBuilderDependentChild(builder, e => e.Child, (parentBuilder, childBuilder) => childBuilder
                                                                                                            .WithValue(c => c.ChildValueProperty, parentBuilder.GetOverwrittenValue(e => e.ParentValueProperty) + 1));

                // assert
                withBuilderDependentChild.Should().Throw <ArgumentNullException>();
            }
예제 #4
0
            public void ExpressionIsMethodCall_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClassParent> >();

                // act
                Action withBuilderDependentChild = () => DynamicBuilderExtensions.WithBuilderDependentChild(builderMock.Object, e => e.ChildFunction(), (parentBuilder, childBuilder) => childBuilder
                                                                                                            .WithValue(c => c.ChildValueProperty, parentBuilder.GetOverwrittenValue(e => e.ParentValueProperty) + 1));

                // assert
                var exception = withBuilderDependentChild.Should().Throw <ArgumentException>().And;

                exception.Data[Errors.ErrorCodeExceptionDataKey].Should().Be(Errors.OnlyMemberAccessExpressionAreAllowed.Code);
            }
예제 #5
0
            public void ShouldOverwritePropertyByExpression()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClassParent> >();
                var child       = new TestClassChild();
                int parentValue = 1;

                builderMock.Setup(e => e.IsOverwritten(nameof(TestClassParent.ParentValueProperty))).Returns(true);
                builderMock.Setup(e => e.GetOverwrittenValue(nameof(TestClassParent.ParentValueProperty))).Returns(parentValue);
                builderMock.Setup(e => e.IsOverwritten(nameof(TestClassParent.Child))).Returns(true);
                builderMock.Setup(e => e.GetOverwrittenValue(nameof(TestClassParent.Child))).Returns(child);
                int expectedChildValue = parentValue + 1;

                // act
                var builder = DynamicBuilderExtensions.WithBuilderDependentChild(builderMock.Object, e => e.Child, (parentBuilder, childBuilder) => childBuilder
                                                                                 .WithValue(c => c.ChildValueProperty, parentBuilder.GetOverwrittenValue(e => e.ParentValueProperty) + 1));

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClassParent.Child), It.Is <TestClassChild>(c => c.ChildValueProperty == expectedChildValue)), Times.Once);
            }