コード例 #1
0
            public void NonNullEnumerable_ShouldOverwriteWithEnumerableCombinedWithNewElement()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                builderMock.Setup(e => e.IsOverwritten(nameof(TestClass.EnumerableProperty))).Returns(true);
                builderMock
                .Setup(e => e.GetOverwrittenValue(nameof(TestClass.EnumerableProperty)))
                .Returns(new List <int> {
                    1, 2
                });
                int minValue = 1;

                builderMock.Setup(e => e.IsOverwritten(nameof(TestClass.MinValueProperty))).Returns(true);
                builderMock.Setup(e => e.GetOverwrittenValue(nameof(TestClass.MinValueProperty))).Returns(minValue);
                int expectedValue = minValue + 1;

                // act
                var builder = DynamicBuilderExtensions.WithBuilderDependentElement(builderMock.Object, e => e.EnumerableProperty, obj => obj.GetOverwrittenValue(e => e.MinValueProperty) + 1);

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.EnumerableProperty), It.Is <IEnumerable <int> >(en => en.SequenceEqual(new List <int> {
                    1, 2, expectedValue
                }))), Times.Once);
            }
コード例 #2
0
            public void NullEnumerable_ShouldOverwriteWithNewEnumerableWithGivenElement()
            {
                // arrange
                int additionalElement  = 3;
                var additionalElements = new List <int> {
                    4, 5
                };
                var expectedElements = new List <int> {
                    additionalElement
                }.Concat(additionalElements);
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                builderMock.Setup(e => e.Build()).Returns(new TestClass {
                    SomeValueProperty = additionalElement
                });
                builderMock.Setup(e => e.IsOverwritten(nameof(TestClass.EnumerableProperty))).Returns(true);
                builderMock
                .Setup(e => e.GetOverwrittenValue(nameof(TestClass.EnumerableProperty)))
                .Returns((IEnumerable <int>)null);

                // act
                var builder = DynamicBuilderExtensions.WithDependentElements(builderMock.Object, e => e.EnumerableProperty, obj => new List <int> {
                    obj.SomeValueProperty
                }.Concat(additionalElements));

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.EnumerableProperty), It.Is <IEnumerable <int> >(en => en.SequenceEqual(expectedElements))), Times.Once);
            }
コード例 #3
0
            public void NonNullEnumerable_ShouldOverwriteWithEnumerableCombinedWithNewElement()
            {
                // arrange
                var originalElements = new List <int> {
                    1, 2
                };
                int additionalElement  = 3;
                var additionalElements = new List <int> {
                    4, 5
                };
                var expectedElements = originalElements.Concat(new List <int> {
                    additionalElement
                }).Concat(additionalElements);
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                builderMock.Setup(e => e.IsOverwritten(nameof(TestClass.SomeValueProperty))).Returns(true);
                builderMock.Setup(e => e.GetOverwrittenValue(nameof(TestClass.SomeValueProperty))).Returns(additionalElement);
                builderMock.Setup(e => e.IsOverwritten(nameof(TestClass.EnumerableProperty))).Returns(true);
                builderMock
                .Setup(e => e.GetOverwrittenValue(nameof(TestClass.EnumerableProperty)))
                .Returns(originalElements);

                // act
                var builder = DynamicBuilderExtensions.WithBuilderDependentElements(builderMock.Object, e => e.EnumerableProperty, obj => new List <int> {
                    obj.GetOverwrittenValue(e => e.SomeValueProperty)
                }.Concat(additionalElements));

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.EnumerableProperty), It.Is <IEnumerable <int> >(en => en.SequenceEqual(expectedElements))), Times.Once);
            }
コード例 #4
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withBuilderDependentElement = () => DynamicBuilderExtensions.WithBuilderDependentElement(builder, e => e.EnumerableProperty, p => 1);

                // assert
                withBuilderDependentElement.Should().Throw <ArgumentNullException>();
            }
コード例 #5
0
            public void ClassProperty_ShouldOverwriteWithNull()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                var builder = DynamicBuilderExtensions.WithNull(builderMock.Object, e => e.StringProperty);

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.StringProperty), (string)null), Times.Once);
            }
            public void ShouldOverwritePropertyByExpression()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                var builder = DynamicBuilderExtensions.WithEmpty(builderMock.Object, e => e.EnumerableProperty);

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.EnumerableProperty), Enumerable.Empty <string>()), Times.Once);
            }
コード例 #7
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>();
            }
コード例 #8
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>();
            }
コード例 #9
0
            public void ShouldOverwritePropertyByExpression()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                var builder = DynamicBuilderExtensions.WithMany(builderMock.Object, e => e.EnumerableProperty, 2, idx => idx.ToString());

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.EnumerableProperty), It.Is <IEnumerable <string> >(en => en.SequenceEqual(new[] { "0", "1" }))), Times.Once);
            }
コード例 #10
0
            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 NullTransformation_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withValue = () => DynamicBuilderExtensions.WithTransformedValue(builderMock.Object, e => e.Int32Property, null);

                // assert
                withValue.Should().Throw <ArgumentNullException>();
            }
            public void NullExpression_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withValue = () => DynamicBuilderExtensions.WithTransformedValue <TestClass, int>(builderMock.Object, null, val => val);

                // assert
                withValue.Should().Throw <ArgumentNullException>();
            }
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withValue = () => DynamicBuilderExtensions.WithTransformedValue(builder, e => e.Int32Property, val => val);

                // assert
                withValue.Should().Throw <ArgumentNullException>();
            }
コード例 #14
0
            public void NullBuildChildAction_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestParentClass> builder = new DynamicBuilder <TestParentClass>();

                // act
                Action withChild = () => DynamicBuilderExtensions.WithChild(builder, p => p.Child, null);

                // assert
                withChild.Should().Throw <ArgumentNullException>();
            }
コード例 #15
0
            public void NullPropertyExpression_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withBuilderDependentElement = () => DynamicBuilderExtensions.WithBuilderDependentElement(builderMock.Object, null, p => 1);

                // assert
                withBuilderDependentElement.Should().Throw <ArgumentNullException>();
            }
コード例 #16
0
            public void NullPropertyFunc_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestParentClass> builder = new DynamicBuilder <TestParentClass>();

                // act
                Action withChild = () => DynamicBuilderExtensions.WithChild <TestParentClass, TestChildClass>(builder, null, childBuilder => childBuilder.WithValue(c => c.Int32Property, 1));

                // assert
                withChild.Should().Throw <ArgumentNullException>();
            }
コード例 #17
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withOne = () => DynamicBuilderExtensions.WithSingle(builder, e => e.EnumerableProperty, 1);

                // assert
                withOne.Should().Throw <ArgumentNullException>();
            }
コード例 #18
0
            public void NullExpression_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withOne = () => DynamicBuilderExtensions.WithSingle(builderMock.Object, null, 1);

                // assert
                withOne.Should().Throw <ArgumentNullException>();
            }
コード例 #19
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withDependentValue = () => DynamicBuilderExtensions.WithDependentValue(builder, e => e.MinValueProperty, db => 1);

                // assert
                withDependentValue.Should().Throw <ArgumentNullException>();
            }
コード例 #20
0
            public void NullGetBuilder_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withDependentValue = () => DynamicBuilderExtensions.WithDependentValue(builderMock.Object, e => e.MinValueProperty, null);

                // assert
                withDependentValue.Should().Throw <ArgumentNullException>();
            }
コード例 #21
0
            public void NullableProperty_ShouldOverwriteWithNull()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                var builder = DynamicBuilderExtensions.WithDefault(builderMock.Object, e => e.NullableInt32Property);

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.NullableInt32Property), (int?)null), Times.Once);
            }
コード例 #22
0
            public void StructProperty_ShouldOverwriteWithDefaultValue()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                var builder = DynamicBuilderExtensions.WithDefault(builderMock.Object, e => e.GuidProperty);

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.GuidProperty), Guid.Empty), Times.Once);
            }
コード例 #23
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withDefault = () => DynamicBuilderExtensions.WithDefault(builder, e => e.StringProperty);

                // assert
                withDefault.Should().Throw <ArgumentNullException>();
            }
コード例 #24
0
            public void NullExpression_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withDefault = () => DynamicBuilderExtensions.WithDefault <TestClass, string>(builderMock.Object, null);

                // assert
                withDefault.Should().Throw <ArgumentNullException>();
            }
コード例 #25
0
            public void NullExpression_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withValue = () => DynamicBuilderExtensions.WithBuilderDependentValue(builderMock.Object, null, db => db.GetOverwrittenValue(e => e.MinValueProperty) + 1);

                // assert
                withValue.Should().Throw <ArgumentNullException>();
            }
コード例 #26
0
            public void NullElementFactory_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withBuilderDependentMany = () => DynamicBuilderExtensions.WithBuilderDependentMany(builderMock.Object, e => e.EnumerableProperty, 2, null);

                // assert
                withBuilderDependentMany.Should().Throw <ArgumentNullException>();
            }
コード例 #27
0
            public void NullPropertyExpression_ShouldThrow()
            {
                // arrange
                var builderMock = new Mock <IDynamicBuilder <TestClass> >();

                // act
                Action withBuilderDependentMany = () => DynamicBuilderExtensions.WithBuilderDependentMany(builderMock.Object, null, 2, (objBuilder, idx) => idx.ToString());

                // assert
                withBuilderDependentMany.Should().Throw <ArgumentNullException>();
            }
コード例 #28
0
            public void NullBuilder_ShouldThrow()
            {
                // arrange
                IDynamicBuilder <TestClass> builder = null;

                // act
                Action withBuilderDependentMany = () => DynamicBuilderExtensions.WithBuilderDependentMany(builder, e => e.EnumerableProperty, 2, (objBuilder, idx) => idx.ToString());

                // assert
                withBuilderDependentMany.Should().Throw <ArgumentNullException>();
            }
コード例 #29
0
            public void ShouldOverwritePropertyByExpression()
            {
                // arrange
                var builderMock   = new Mock <IDynamicBuilder <TestClass> >();
                int expectedValue = 1;

                // act
                var builder = DynamicBuilderExtensions.WithSingle(builderMock.Object, e => e.EnumerableProperty, expectedValue);

                // assert
                builderMock.Verify(e => e.Overwrite(nameof(TestClass.EnumerableProperty), It.Is <IEnumerable <int> >(en => en.SequenceEqual(new[] { expectedValue }))), Times.Once);
            }
コード例 #30
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>();
            }