示例#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);
        }
        public void Count()
        {
            var provider = new FactoryProvider();

            provider.Add(new FactoryCollection <int>());

            Assert.AreEqual(1, provider.Collections.Count);
        }
        public void GetGeneric()
        {
            var provider = new FactoryProvider();

            provider.Add(new FactoryCollection <int>());

            IFactoryCollection <int> collection = provider.Get <int>();

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

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

            Assert.AreEqual(0, provider.Collections.Count);
        }
        public void ContainsKey()
        {
            var provider = new FactoryProvider();

            provider.Add(new FactoryCollection <int>());

            bool result = provider.Collections.ContainsKey(typeof(int));

            Assert.True(result);
        }
        public void TryGet()
        {
            var provider = new FactoryProvider();

            provider.Add(new FactoryCollection <int>());

            bool result1 = provider.TryGet(typeof(int), out IFactoryCollection collection1);
            bool result2 = provider.TryGet(typeof(long), out IFactoryCollection collection2);

            Assert.True(result1);
            Assert.False(result2);
            Assert.NotNull(collection1);
            Assert.Null(collection2);
        }
        public void TryGetGeneric()
        {
            var provider = new FactoryProvider();

            provider.Add(new FactoryCollection <int>());

            bool result1 = provider.TryGet(out IFactoryCollection <int> collection1);
            bool result2 = provider.TryGet(out IFactoryCollection <long> collection2);

            Assert.True(result1);
            Assert.False(result2);
            Assert.NotNull(collection1);
            Assert.Null(collection2);
        }
示例#8
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);
        }
        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);
        }