public void CanGetInstanceWithExportableCtor() { //Arrange Compose <IAnimal> .Exports.Clear(); Compose <IManager> .Exports.Clear(); Compose <IZoo> .Exports.Clear(); Compose <ICar> .Exports.Clear(); Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); Compose <ICar> .Add(typeof(Car)); Compose <IZoo> .Add(typeof(DallasZoo)); Compose <IManager> .Add(typeof(MrJones)); //Act var obj = ReflectionHelpers.GetInstance <Cat>(); // Assert Assert.True(obj != null && obj.Manager != null && obj.Manager.Car != null && obj.Zoo != null); }
public void CanPopulateExportableCtor() { //Arrange Compose <IAnimal> .Exports.Clear(); Compose <IManager> .Exports.Clear(); Compose <IZoo> .Exports.Clear(); Compose <ICar> .Exports.Clear(); Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); Compose <IZoo> .Add(typeof(DallasZoo)); Compose <IManager> .Add(typeof(MrJones)); Compose <ICar> .Add(typeof(Car)); //Act var ctorInfo = typeof(Cat).GetExportableConstructor(); var parameters = ctorInfo.GetCtorParameters(); var obj = (Cat)ctorInfo.Invoke(parameters); // Assert Assert.True(obj != null && obj.Manager != null && obj.Zoo != null); }
public void CanFindExportableCtor() { //Arrange Compose <IAnimal> .Exports.Clear(); Compose <IManager> .Exports.Clear(); Compose <IZoo> .Exports.Clear(); Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); Compose <IZoo> .Add(typeof(DallasZoo)); Compose <IManager> .Add(typeof(MrJones)); //Act var ctorInfo = typeof(Cat).GetExportableConstructor(); // Assert Assert.True(ctorInfo != null); }
public void CanGetPropertySingleton() { Compose <IZoo> .Exports.Clear(); //Register/Act Compose <IZoo> .Add(typeof(BostonZoo)); // Act var zoo = Compose <IZoo> .Singleton; //Assert Assert.True(zoo != null && zoo.Name == "Babaam"); }
public void WillFailIfTypeIsMissing() { Compose <IAnimal> .Exports.Clear(); //Register/Act Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); // Act var ex = Assert.Throws <InvalidOperationException>(() => { Compose <IAnimal> .Get <Cat>(); }); //Assert Assert.True(ex.Message == "Sequence contains no matching element"); }
public void CanGetRewrittenSingleton() { Compose <IZoo> .Exports.Clear(); //Register/Act Compose <IZoo> .Add(typeof(BostonZoo)); Compose <IZoo> .Add(typeof(DallasZoo)); // Act var zoo = Compose <IZoo> .Get(); //Assert Assert.True(zoo != null && zoo.GetType() == typeof(DallasZoo)); }
public void WillNotAddMultipleTypes() { Compose <IAnimal> .Exports.Clear(); //Register Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Lion)); //Act var animals = Compose <IAnimal> .GetAll(); // Assert Assert.True(animals.Count == 1 && animals.First().GetType() == typeof(Lion)); }
public void CanGetAllExports() { Compose <IAnimal> .Exports.Clear(); //Register Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); //Act var animals = Compose <IAnimal> .GetAll(); // Assert Assert.True(animals.Count == 3); }
public void SingletonIsSameInstance() { Compose <IZoo> .Exports.Clear(); //Register/Act Compose <IZoo> .Add(typeof(BostonZoo)); Compose <IZoo> .Add(typeof(DallasZoo)); // Act var zoo1 = Compose <IZoo> .Get(); var zoo2 = Compose <IZoo> .Get(); //Assert Assert.True(zoo1.Equals(zoo2)); }
public void CanGetSpecificType() { Compose <IAnimal> .Exports.Clear(); //Register Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); //Act var animal = Compose <IAnimal> .Get <Lion>(); // Assert Assert.True(animal.Says() == "Grrr"); }
public void CanMakeGenericExport() { Compose <IAnimal> .Exports.Clear(); //Register Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); //Act var genericExport = typeof(IAnimal).MakeGenericExport(); Assert.True(genericExport != null); var getMethod = genericExport.GetMethod("Get", new Type[] { typeof(Type) }); // Assert Assert.True(getMethod.Invoke(genericExport, new object[] { typeof(Dog) }) != null); }