public void CreateInstanceWithBind_OverwriteBind_GivesProperInstance()
        {
            // Arrange
            ServiceLocator.Bind <IMultipleImplementations, ImplementationOne>();
            try
            {
                // Act
                var instance = ServiceLocator.CreateInstance <IMultipleImplementations>();

                // Assert
                Assert.IsType <ImplementationOne>(instance);

                // Rearrange
                ServiceLocator.Bind <IMultipleImplementations, ImplementationTwo>();

                // Act
                instance = ServiceLocator.CreateInstance <IMultipleImplementations>();

                // Assert
                Assert.IsType <ImplementationTwo>(instance);
            }
            finally
            {
                ServiceLocator.Unbind <IMultipleImplementations>();
            }
        }
        public void CreateInstance_UsingUnimplementedKey_Throws()
        {
            // Arrange
            var locator = new ServiceLocator <LocatorKey, IPartlyImplemented>();

            // Act && Assert
            Assert.Throws <ArgumentException>(() => locator.CreateInstance(LocatorKey.Unimplemented));
        }
        public void CreateInstanceWithPredicate_PredicateResultsInSingleImplementation_GivesInstance()
        {
            // Act
            var algorithm = ServiceLocator.CreateInstance <IHashingAlgorithm>(algo => algo.IsThisAlgorithm("md5"));

            // Assert
            Assert.NotNull(algorithm);
            Assert.IsType <MD5>(algorithm);
        }
        public void CreateInstance_InterfaceHasOneImplementation_GivesInstance()
        {
            // Act
            var instance = ServiceLocator.CreateInstance <IImplementation>();

            // Assert
            Assert.NotNull(instance);
            Assert.IsType <Implementation>(instance);
        }
        public void CreateInstanceWithoutGenerics_InterfaceHasOneImplementation_GivesInstance()
        {
            // Act
            var instance = ServiceLocator.CreateInstance(typeof(IObjectImplementation));

            // Assert
            Assert.NotNull(instance);
            Assert.IsType <ObjectImplementation>(instance);
        }
Exemplo n.º 6
0
        public void Correctly_Constructs_Instance_With_Key()
        {
            InfrastructureDependencyRegistrar.RegisterInfrastructure();
            IServiceLocator serviceLocator = new ServiceLocator();

            var instance = serviceLocator.CreateInstance <IDatabaseActionExecutor>("Create");

            Assert.That(instance, Is.Not.Null);
        }
Exemplo n.º 7
0
        public void Correctly_Constructs_Instance()
        {
            InfrastructureDependencyRegistrar.RegisterInfrastructure();
            IServiceLocator serviceLocator = new ServiceLocator();

            var instance = serviceLocator.CreateInstance <IResourceFileLocator>();

            Assert.That(instance, Is.Not.Null);
        }
Exemplo n.º 8
0
		public void Correctly_Constructs_Instance_With_Key()
		{
            InfrastructureDependencyRegistrar.RegisterInfrastructure();
			IServiceLocator serviceLocator = new ServiceLocator();

			var instance = serviceLocator.CreateInstance<IDatabaseActionExecutor>("Create");

			Assert.That(instance, Is.Not.Null);
		}
Exemplo n.º 9
0
		public void Correctly_Constructs_Instance()
		{
            InfrastructureDependencyRegistrar.RegisterInfrastructure();
			IServiceLocator serviceLocator = new ServiceLocator();

			var instance = serviceLocator.CreateInstance<IResourceFileLocator>();

			Assert.That(instance, Is.Not.Null);
		}
        public void CreateInstance_UsingClassType_GivesInstance()
        {
            // Act
            var instance = ServiceLocator.CreateInstance <Implementation>();

            // Assert
            Assert.NotNull(instance);
            Assert.IsType <Implementation>(instance);
        }
        public void CreateInstance_UsingValidKey_GivesInstance()
        {
            // Arrange
            var locator = new ServiceLocator <LocatorKey, IPartlyImplemented>();

            // Act
            var instance = locator.CreateInstance(LocatorKey.Implemented);

            // Assert
            Assert.NotNull(instance);
            Assert.IsType <Implemented>(instance);
        }
        public void CreateInstanceWithBind_InterfaceHasMultipleImplementations_GivesInstance()
        {
            // Arrange
            ServiceLocator.Bind <IMultipleImplementations, ImplementationOne>();
            try
            {
                // Act
                var instance = ServiceLocator.CreateInstance <IMultipleImplementations>();

                // Assert
                Assert.IsType <ImplementationOne>(instance);
            }
            finally
            {
                ServiceLocator.Unbind <IMultipleImplementations>();
            }
        }
        public void CreateInstanceWithBindAndUnbind_InterfaceHasMultipleImplementations_Throws()
        {
            // Arrange
            ServiceLocator.Bind <IMultipleImplementations, ImplementationOne>();

            // Act
            var instance = ServiceLocator.CreateInstance <IMultipleImplementations>();

            // Assert
            Assert.IsType <ImplementationOne>(instance);


            // Rearrange
            ServiceLocator.Unbind <IMultipleImplementations>();

            // Act && Assert
            Assert.Throws <ArgumentException>(() => ServiceLocator.CreateInstance <IMultipleImplementations>());
        }
 public void CreateInstance_ImplementationHasNoEmptyConstructor_Throws()
 {
     // Act && Assert
     Assert.Throws <ArgumentException>(() => ServiceLocator.CreateInstance <ImplementationWithoutEmptyConstructor>());
 }
 public void CreateInstanceWithPredicate_PredicateResultsInNoImplementations_Throws()
 {
     // Act && Assert
     Assert.Throws <ArgumentException>(() => ServiceLocator.CreateInstance <IHashingAlgorithm>(algo => algo.IsThisAlgorithm("sha256")));
 }
 public void CreateInstance_InterfaceHasMultipleImplementations_Throws()
 {
     // Act && Assert
     Assert.Throws <ArgumentException>(() => ServiceLocator.CreateInstance <IMultipleImplementations>());
 }
 public void CreateInstanceWithPredicate_PredicateResultsInMultipleImplementations_Throws()
 {
     // Act && Assert
     Assert.Throws <ArgumentException>(() => ServiceLocator.CreateInstance <IHashingAlgorithm>(algo => true));
 }