Exemplo n.º 1
0
        public void TryGetBuilder2()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <Type>();
            var factory    = new Factory <string>();

            factory.Add("empty", new GameObjectBuilderEmpty());
            factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab")));
            collection.Add(typeof(IGameObjectBuilder), factory);
            provider.Add(collection);

            bool result1 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "empty", out IGameObjectBuilder builder1);
            bool result2 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "prefab", out IGameObjectBuilder builder2);
            bool result3 = provider.TryGetBuilder(typeof(int), "empty", out IBuilder builder3);
            bool result4 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "prefab2", out IGameObjectBuilder builder4);

            Assert.True(result1);
            Assert.True(result2);
            Assert.False(result3);
            Assert.False(result4);
            Assert.NotNull(builder1);
            Assert.NotNull(builder2);
            Assert.Null(builder3);
            Assert.Null(builder4);
        }
Exemplo n.º 2
0
 public void Can_clear()
 {
     var collection = new FactoryCollection();
     collection.Add(new SimpleFactory<Rabbit>());
     collection.Clear();
     Assert.Empty(collection);
 }
Exemplo n.º 3
0
        public void Count()
        {
            var collection = new FactoryCollection <int>();

            collection.Add(0, new Factory <int>());

            Assert.AreEqual(1, collection.Factories.Count);
        }
Exemplo n.º 4
0
        public void ContainsKey()
        {
            var collection = new FactoryCollection <int>();

            collection.Add(0, new Factory <int>());

            bool result = collection.Factories.ContainsKey(0);

            Assert.True(result);
        }
Exemplo n.º 5
0
        public void GetGeneric()
        {
            var collection = new FactoryCollection <int>();

            collection.Add(0, new Factory <int>());

            var factory = collection.Get <Factory <int> >(0);

            Assert.NotNull(factory);
        }
        public void Remove()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <int>();

            provider.Add(collection);
            provider.Remove(collection);

            Assert.AreEqual(0, provider.Collections.Count);
        }
Exemplo n.º 7
0
        public void CountTest()
        {
            IFactoryCollection collection = new FactoryCollection();

            collection.Add(new ServiceDescriptor(typeof(ClassA), ServiceLifetime.Transient));
            collection.Add(new ServiceDescriptor(typeof(ClassB), ServiceLifetime.Singleton));

            Assert.Equal(2, collection.Count);
            Assert.Equal(2, collection.Count());
            Assert.Equal(1, collection.Count(o => o.Lifetime == ServiceLifetime.Singleton));
        }
Exemplo n.º 8
0
        public void BuildTest()
        {
            IFactoryCollection collection = new FactoryCollection();

            collection.Add(new ServiceDescriptor(typeof(ClassA), ServiceLifetime.Transient));
            collection.Build();
            collection.Add(new ServiceDescriptor(typeof(ClassB), ServiceLifetime.Singleton));

            Assert.True(collection.IsBuild);
            Assert.Equal(1, collection.Count);
        }
Exemplo n.º 9
0
        public void AddTest()
        {
            IFactoryCollection collection = new FactoryCollection();

            collection.Add(new ServiceDescriptor(typeof(ClassA), ServiceLifetime.Transient));
            collection.Add(new ServiceDescriptor(typeof(ClassB), ServiceLifetime.Singleton));

            var a = collection.FirstOrDefault(o => o.ImplementationType.Equals(typeof(ClassA)));
            var b = collection.FirstOrDefault(o => o.ImplementationType.Equals(typeof(ClassB)));

            Assert.NotNull(a);
            Assert.NotNull(b);
        }
Exemplo n.º 10
0
        public void AddSingletonTest3()
        {
            IFactoryCollection collection = new FactoryCollection();

            collection.AddSingleton <InterfaceA, ClassA>();

            var a = collection.FirstOrDefault(o => o.ImplementationType.Equals(typeof(ClassA)));

            Assert.NotNull(a);
            Assert.Equal(ServiceLifetime.Singleton, a.Lifetime);
            Assert.Equal(typeof(InterfaceA), a.ServiceType);
            Assert.Equal(typeof(ClassA), a.ImplementationType);
        }
Exemplo n.º 11
0
        public void AddTransientTest1()
        {
            IFactoryCollection collection = new FactoryCollection();

            collection.AddTransient <ClassA>();

            var a = collection.FirstOrDefault(o => o.ImplementationType.Equals(typeof(ClassA)));

            Assert.NotNull(a);
            Assert.Equal(ServiceLifetime.Transient, a.Lifetime);
            Assert.Equal(typeof(ClassA), a.ServiceType);
            Assert.Equal(typeof(ClassA), a.ImplementationType);
        }
Exemplo n.º 12
0
        public void AddFirstLoader2()
        {
            IFactoryCollection collection = new FactoryCollection();

            collection.AddFirstLoader <ClassD>(false);

            var a = collection.FirstOrDefault(o => o.ImplementationType.Equals(typeof(ClassD)));

            Assert.NotNull(a);
            Assert.Equal(ServiceLifetime.TransientFirstLoader, a.Lifetime);
            Assert.Equal(typeof(ClassD), a.ServiceType);
            Assert.Equal(typeof(ClassD), a.ImplementationType);
        }
Exemplo n.º 13
0
        public void TryGet()
        {
            var collection = new FactoryCollection <int>();

            collection.Add(0, new Factory <int>());

            bool result1 = collection.TryGet(0, out IFactory factory1);
            bool result2 = collection.TryGet(1, out IFactory factory2);

            Assert.True(result1);
            Assert.False(result2);
            Assert.NotNull(factory1);
            Assert.Null(factory2);
        }
Exemplo n.º 14
0
        static Arithmetics()
        {
            QuickSupport  = new FactoryCollection();
            QuickChecked  = new FactoryCollection();
            InterpSupport = new FactoryCollection();
            InterpChecked = new FactoryCollection();

            Register <Int32, Int32Arithmetic>(false);
            Register <Int64, Int64Arithmetic>(false);
            Register <Single, SingleArithmetic>(false);
            Register <Double, DoubleArithmetic>(false);
            Register <Decimal, DecimalArithmetic>(false);

            Register <Int32, Int32CheckedArithmetic>(true);
            Register <Int64, Int64CheckedArithmetic>(true);
        }
Exemplo n.º 15
0
        public void GetBuilder2()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <Type>();
            var factory    = new Factory <string>();

            factory.Add("empty", new GameObjectBuilderEmpty());
            factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab")));
            collection.Add(typeof(IGameObjectBuilder), factory);
            provider.Add(collection);

            IGameObjectBuilder builder1 = provider.GetBuilder <IGameObjectBuilder, Type, string>(typeof(IGameObjectBuilder), "empty");
            IGameObjectBuilder builder2 = provider.GetBuilder <IGameObjectBuilder, Type, string>(typeof(IGameObjectBuilder), "prefab");

            Assert.NotNull(builder1);
            Assert.NotNull(builder2);
        }
Exemplo n.º 16
0
        public void BuildGameObject()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <Type>();
            var factory    = new Factory <string>();

            provider.Add(collection);
            collection.Add(typeof(IGameObjectBuilder), factory);
            factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab")));
            factory.Add("empty", new GameObjectBuilderEmpty());

            GameObject gameObject1 = provider.GetBuilder <IGameObjectBuilder, string>("prefab").Build();
            GameObject gameObject2 = provider.GetBuilder <IGameObjectBuilder, string>("empty").Build();

            Assert.NotNull(gameObject1);
            Assert.NotNull(gameObject2);
            Assert.AreEqual("prefab(Clone)", gameObject1.name);
            Assert.AreEqual("New Game Object", gameObject2.name);
        }
Exemplo n.º 17
0
 public void Cannot_get_missing_factory()
 {
     var collection = new FactoryCollection();
     Assert.Throws<MissingSequenceException>(() => collection.Get<Rabbit>());
 }
Exemplo n.º 18
0
 public void Cannot_get_missing_named_factory()
 {
     var collection = new FactoryCollection();
     collection.Add<Rabbit>(new SimpleFactory<Rabbit>());
     Assert.Throws<MissingSequenceException>(() => collection.Get<Rabbit>("rabbit"));
 }
Exemplo n.º 19
0
 public void Can_add_default_factory()
 {
     var collection = new FactoryCollection();
     collection.Add(new SimpleFactory<Rabbit>());
     Assert.NotEmpty(collection);
 }
Exemplo n.º 20
0
        public void IdentifierType()
        {
            var collection = new FactoryCollection <int>();

            Assert.AreEqual(typeof(int), collection.IdentifierType);
        }
Exemplo n.º 21
0
 public void Can_add_named_factory()
 {
     var collection = new FactoryCollection();
     collection.Add(new SimpleFactory<Rabbit>(), "bunny");
     Assert.NotEmpty(collection);
 }
Exemplo n.º 22
0
 public void Can_get_default_factory()
 {
     var collection = new FactoryCollection();
     collection.Add(new SimpleFactory<Rabbit>());
     Assert.NotNull(collection.Get<Rabbit>());
 }
Exemplo n.º 23
0
 public void Can_get_named_factory()
 {
     var collection = new FactoryCollection();
     collection.Add(new SimpleFactory<Rabbit>(), "bunny");
     Assert.NotNull(collection.Get<Rabbit>("bunny"));
 }
Exemplo n.º 24
0
 public void Cannot_add_duplicate_factory()
 {
     var collection = new FactoryCollection();
     collection.Add<Rabbit>(new SimpleFactory<Rabbit>());
     Assert.Throws<DuplicateSequenceException>(() => collection.Add<Rabbit>(new SimpleFactory<Rabbit>()));
 }