Example #1
0
        public void TestInnerObjectFill()
        {
            TestParentClass testClass = FillClass <TestParentClass>();

            Assert.AreNotEqual(testClass.TestInt, 0);

            Assert.AreNotEqual(testClass.testOpenClass.TestInt, 0);
            Assert.AreNotEqual(testClass.testOpenClass.TestDouble, 0);
            Assert.AreNotEqual(testClass.testOpenClass.TestFloat, 0);
            Assert.AreNotEqual(testClass.testOpenClass.TestLong, 0);

            Assert.IsNotNull(testClass.testOpenClass.TestString);
            Assert.IsNotNull(testClass.testOpenClass.TestDateTime);
            Assert.IsNotNull(testClass.testOpenClass.TestSpan);
            Assert.IsNotNull(testClass.testOpenClass.TestUri);
        }
Example #2
0
            public void ShouldChangeOnlyOverwrittenPropertyInChildObject()
            {
                // arrange
                var    parentObject        = new TestParentClass(new TestChildClass(1, Guid.NewGuid().ToString()));
                var    parentBuilder       = Build.Dynamically(parentObject);
                string expectedStringValue = Guid.NewGuid().ToString();

                // act
                var resultParentObject = DynamicBuilderExtensions
                                         .WithChild(parentBuilder, p => p.Child, childBuilder => childBuilder.WithValue(c => c.StringProperty, expectedStringValue))
                                         .Build();

                // assert
                resultParentObject.Child.Should().BeEquivalentTo(parentObject.Child, opt => opt.Excluding(e => e.StringProperty));
                resultParentObject.Child.StringProperty.Should().Be(expectedStringValue);
            }
Example #3
0
            public void NullChild_ShouldCreateNewChildWithOverwrittenProperties()
            {
                // arrange
                var    parentObject        = new TestParentClass(null);
                var    parentBuilder       = Build.Dynamically(parentObject);
                string expectedStringValue = Guid.NewGuid().ToString();

                // act
                var resultParentObject = DynamicBuilderExtensions
                                         .WithChild(parentBuilder, p => p.Child, childBuilder => childBuilder.WithValue(c => c.StringProperty, expectedStringValue))
                                         .Build();

                // assert
                resultParentObject.Child.Should().NotBeNull();
                resultParentObject.Child.Int32Property.Should().Be(default(int));
                resultParentObject.Child.StringProperty.Should().Be(expectedStringValue);
            }
Example #4
0
        public void GuardExpressions_AgainstInvalidType_ShouldSucceed_WhenTypeIsDerivedFromRequiredType()
        {
            TestClass testClassInstance = new TestClass();

            TestParentClass result = Guard.AgainstInvalidType <TestParentClass>(testClassInstance, "testClassInstance is is derived from TestParentClass, the check should succeed.");
        }