public void TestGetInstance()
 {
     var factory = new SingletonInstanceFactory();
     var component = factory.GetInstance(typeof(Hoge));
     Assert.IsNotNull(component);
     Assert.AreEqual(typeof(Hoge), component.GetType());
 }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="preparedComponents">生成済コンポーネントのコレクション</param>
        /// <param name="valueFactory">インスタンス生成ファクトリ</param>
        public PreparedSingletonInstanceFactory(IDictionary<Type, object> preparedComponents, Func<Type, object> valueFactory = null)
        {
            if (preparedComponents == null) { throw new ArgumentNullException("preparedComponents"); }

            _preparedComponents = preparedComponents;
            _factory = new SingletonInstanceFactory(valueFactory);
        }
        public void TestSingleton()
        {
            var factory = new SingletonInstanceFactory();
            var component1 = factory.GetInstance(typeof(Hoge));
            var component2 = factory.GetInstance(typeof(Hoge));

            Assert.AreSame(component1, component2);
        }
        public void TestGetInstance_WithCallback()
        {
            var testObj = new CallBackClass();
            var factory = new SingletonInstanceFactory(testObj.GetHoge);
            var component = factory.GetInstance(typeof(Hoge));

            Assert.IsNotNull(component);
            Assert.AreEqual(typeof(Hoge), component.GetType());
        }
        public void TestSetValueFactory()
        {
            const char EXPECTED = 'a';
            var factory = new SingletonInstanceFactory(t => new string(new char[] { EXPECTED }));

            var component = factory.GetInstance(typeof(string));

            Assert.IsNotNull(component);
            Assert.AreEqual(EXPECTED.ToString(), component);
        }
        public void TestDispose()
        {
            var testType = typeof(Hoge);
            var factory = new SingletonInstanceFactory();
            var component1 = factory.GetInstance(testType);

            factory.Dispose();
            var component2 = factory.GetInstance(testType);

            Assert.AreNotSame(component1, component2);
        }
 public void TestGetInstance_ArgNull()
 {
     var factory = new SingletonInstanceFactory();
     factory.GetInstance(null);
 }