public void Overwritten_ShouldReturnTrue()
                {
                    // arrange
                    var sut = new DynamicBuilder <SomeStruct>();

                    sut.Overwrite(nameof(SomeStruct.Int32Property), 1);

                    // act
                    bool result = sut.IsOverwritten(nameof(SomeStruct.Int32Property));

                    // assert
                    result.Should().BeTrue();
                }
Esempio n. 2
0
                public void Overwritten_ShouldReturnOverwrittenValue()
                {
                    // arrange
                    var sut      = new DynamicBuilder <SomeClass>();
                    int expected = 1;

                    sut.Overwrite(nameof(SomeClass.Int32Property), expected);

                    // act
                    object result = sut.GetOverwrittenValue(nameof(SomeClass.Int32Property));

                    // assert
                    result.Should().Be(expected);
                }
Esempio n. 3
0
                public void ShouldBuildObjectWithOverwrittenProperties()
                {
                    // arrange
                    var template = new SomeStruct(
                        intProperty: 1,
                        stringProperty: "some text");
                    int    expectedIntProperty    = template.IntProperty;
                    string expectedStringProperty = "other text";

                    var sut = new DynamicBuilder <SomeStruct>();

                    sut.OverwriteWithTemplate(template);
                    sut.Overwrite(nameof(SomeStruct.StringProperty), expectedStringProperty);

                    // act
                    var result = sut.Build();

                    // assert
                    result.IntProperty.Should().Be(expectedIntProperty);
                    result.StringProperty.Should().Be(expectedStringProperty);
                }
                public void ShouldCallPropertySetterForGivenProperty(string propertyName, object expectedValue)
                {
                    // arrange
                    var expectedInstance    = new TestClass();
                    var instanceFactoryMock = new Mock <IInstanceFactory <TestClass> >();

                    instanceFactoryMock
                    .Setup(e => e.Create(It.IsAny <IEnumerable <INamedPropertyOverwriter> >()))
                    .Returns(expectedInstance);
                    var propertySetterMock = new Mock <IPropertySetter>();

                    var sut = new DynamicBuilder <TestClass>(
                        instanceFactory: instanceFactoryMock.Object,
                        propertySetter: propertySetterMock.Object);
                    var expectedProperty = expectedInstance.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                    // act
                    sut.Overwrite(propertyName, expectedValue);
                    sut.Build();

                    // assert
                    propertySetterMock
                    .Verify(e => e.SetProperty(expectedInstance, expectedProperty, expectedValue), Times.Once());
                }