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 Can_clear() { var collection = new FactoryCollection(); collection.Add(new SimpleFactory<Rabbit>()); collection.Clear(); Assert.Empty(collection); }
public void Count() { var collection = new FactoryCollection <int>(); collection.Add(0, new Factory <int>()); Assert.AreEqual(1, collection.Factories.Count); }
public void ContainsKey() { var collection = new FactoryCollection <int>(); collection.Add(0, new Factory <int>()); bool result = collection.Factories.ContainsKey(0); Assert.True(result); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void Cannot_get_missing_factory() { var collection = new FactoryCollection(); Assert.Throws<MissingSequenceException>(() => collection.Get<Rabbit>()); }
public void Cannot_get_missing_named_factory() { var collection = new FactoryCollection(); collection.Add<Rabbit>(new SimpleFactory<Rabbit>()); Assert.Throws<MissingSequenceException>(() => collection.Get<Rabbit>("rabbit")); }
public void Can_add_default_factory() { var collection = new FactoryCollection(); collection.Add(new SimpleFactory<Rabbit>()); Assert.NotEmpty(collection); }
public void IdentifierType() { var collection = new FactoryCollection <int>(); Assert.AreEqual(typeof(int), collection.IdentifierType); }
public void Can_add_named_factory() { var collection = new FactoryCollection(); collection.Add(new SimpleFactory<Rabbit>(), "bunny"); Assert.NotEmpty(collection); }
public void Can_get_default_factory() { var collection = new FactoryCollection(); collection.Add(new SimpleFactory<Rabbit>()); Assert.NotNull(collection.Get<Rabbit>()); }
public void Can_get_named_factory() { var collection = new FactoryCollection(); collection.Add(new SimpleFactory<Rabbit>(), "bunny"); Assert.NotNull(collection.Get<Rabbit>("bunny")); }
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>())); }