Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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");
        }
Пример #5
0
        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");
        }
Пример #6
0
        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));
        }
Пример #7
0
        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));
        }
Пример #8
0
        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);
        }
Пример #9
0
        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));
        }
Пример #10
0
        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");
        }
Пример #11
0
        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);
        }