예제 #1
0
        public void InstantiateWithNullObjectName()
        {
            SimpleInstantiationStrategy strategy = new SimpleInstantiationStrategy();
            object obj = strategy.Instantiate(SingletonDefinition, null, Factory);

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is ITestObject);
            ITestObject actual = (ITestObject)obj;

            Assert.IsNull(actual.Name);
            Assert.AreEqual(0, actual.Age);
        }
예제 #2
0
        public void InstantiateWithDefinitionThatDoesNotHaveAResolvedObjectClass()
        {
            RootObjectDefinition def = new RootObjectDefinition();

            def.ObjectTypeName = typeof(TestObject).FullName;

            SimpleInstantiationStrategy strategy = new SimpleInstantiationStrategy();
            object foo = strategy.Instantiate(def, "foo", Factory);

            Assert.IsNotNull(foo);
            Assert.AreEqual(typeof(TestObject), foo.GetType());
        }
예제 #3
0
        public void InstantiateWithFactoryMethod()
        {
            SimpleInstantiationStrategy strategy = new SimpleInstantiationStrategy();
            object obj = strategy.Instantiate(SingletonDefinitionWithFactory,
                                              string.Empty, Factory, typeof(TestObjectFactory).GetMethod("GetObject"), null);

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is ITestObject);
            ITestObject actual = (ITestObject)obj;

            Assert.AreEqual(TestObjectFactory.TheName, actual.Name);
            Assert.AreEqual(TestObjectFactory.TheAge, actual.Age);
        }
예제 #4
0
        public void InstantiateWithExplicitCtor()
        {
            SimpleInstantiationStrategy strategy = new SimpleInstantiationStrategy();
            object obj = strategy.Instantiate(
                SingletonDefinition, null, Factory,
                SingletonDefinition.ObjectType.GetConstructor(
                    new Type[] { typeof(string), typeof(int) }),
                new object[] { "Rick", 19 });

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is ITestObject);
            ITestObject actual = (ITestObject)obj;

            Assert.AreEqual("Rick", actual.Name);
            Assert.AreEqual(19, actual.Age);
        }
예제 #5
0
        public void InstantiateWithNulls()
        {
            SimpleInstantiationStrategy strategy = new SimpleInstantiationStrategy();

            Assert.Throws <ArgumentNullException>(() => strategy.Instantiate(null, null, null));
        }