示例#1
0
        public void TestBuilder_PropertiesArePopulated_ObjectIsCreatedUsingBuilderProperties()
        {
            var builder = new Implementation.BuilderWithOneInterfaceProperty();

            var testObject = builder.Build();

            //Assert the builder properties
            Assert.NotNull(builder.TestService);
            Assert.NotNull(builder.TestObjectB);
            Assert.Equal(2, builder.Id);

            //Assert the reference Property was instanitated using its constructor
            Assert.NotNull(builder.TestObjectB.TestServiceB);

            //Assert the object properties
            Assert.Equal(0, testObject.Number);
            Assert.Equal(DateTime.MinValue, testObject.Date);
            Assert.Same(builder.TestService, testObject.TestServiceA); //use the same object from container
            Assert.NotNull(testObject.TestObjectB);                    //create a new object
        }
示例#2
0
        public void TestBuilder_WithContainer_ObjectIsCreatedUsingBuilderProperties()
        {
            var container   = new SimpleContainer();
            var testService = new TestServiceA();

            container.Add <ITestServiceA>(testService);

            var builder = new Implementation.BuilderWithOneInterfaceProperty(container);

            var testObject = builder.Build();

            //Assert the builder properties
            Assert.Same(testService, builder.TestService); //use the object from container
            Assert.Equal(2, builder.Id);

            //Assert the object properties
            Assert.Equal(0, testObject.Number);
            Assert.Equal(DateTime.MinValue, testObject.Date);
            Assert.Same(builder.TestService, testObject.TestServiceA); //use the same object from container
            Assert.NotNull(testObject.TestObjectB);                    //create a new object
        }