示例#1
0
        public void CreateTest_NoRegisteredFactory()
        {
            Assert.Throws <InvalidOperationException>(

                // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                () => FactoryRegistry <int> .Create(), "No factory registered for type: System.Int32"
                );
        }
示例#2
0
        public void TryCreateTest()
        {
            var factory = new IntFactory();

            FactoryRegistry <int> .RegisterFactory(factory);

            Assert.IsTrue(FactoryRegistry <int> .TryCreate(out var created, 1234));
            Assert.AreEqual(1234, created);
        }
示例#3
0
        public void CreateTest()
        {
            var factory = new IntFactory();

            FactoryRegistry <int> .RegisterFactory(factory);

            Assert.AreEqual(0, factory.Create());
            Assert.AreEqual(1234, factory.Create(1234));
        }
示例#4
0
        public void RegisterFactoryTest()
        {
            Assert.IsNull(FactoryRegistry <int> .Factory);

            var factory = new IntFactory();

            Assert.IsTrue(FactoryRegistry <int> .RegisterFactory(factory));
            Assert.AreEqual(factory, FactoryRegistry <int> .Factory);
            Assert.IsNotNull(FactoryRegistry <int> .Factory);

            var factory2 = new IntFactory();

            Assert.AreNotEqual(factory, factory2);
            Assert.IsFalse(FactoryRegistry <int> .RegisterFactory(factory2));
            Assert.AreEqual(factory, FactoryRegistry <int> .Factory);

            Assert.IsTrue(FactoryRegistry <int> .RegisterFactory(factory2, true));
            Assert.AreEqual(factory2, FactoryRegistry <int> .Factory);
        }