コード例 #1
0
        public void RemoveInstance_Should_Throw_Exception_When_Type_Is_Not_Registered()
        {
            // Arrange
            var container = ContainerFactory.Create();

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                container.RemoveInstance <IContainerTestInterface>,
                "Container does not contain 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type as a key.");
        }
コード例 #2
0
        public void CreateInstance_Should_Throw_Exception_When_Type_Has_Ambiguous_Constructors()
        {
            // Arrange
            var container = ContainerFactory.Create();

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                () => container.CreateInstance <ContainerTestClassWithAmbiguousConstructors>(),
                "Ambiguous usage of 'Inject' attribute on constructors of type 'Agero.Core.DIContainer.Tests.Types.ContainerTestClassWithAmbiguousConstructors'." +
                " Only one constructor can be marked with 'Inject' attribute.");
        }
コード例 #3
0
        public void RemoveInstance_Should_Throw_Exception_When_FactoryMethod_Is_Registered_Per_Container_And_Instance_Is_Not_Created()
        {
            // Arrange
            var container = ContainerFactory.Create();

            container.RegisterFactoryMethod <IContainerTestInterface>(c => new ContainerTestClass(), Lifetime.PerContainer);

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                container.RemoveInstance <IContainerTestInterface>,
                "Container does not contain an instance of 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type.");
        }
コード例 #4
0
        public void RegisterInstance_Should_Throw_Exception_When_Instance_Is_Already_Registered()
        {
            // Arrange
            var container = ContainerFactory.Create();

            container.RegisterInstance <IContainerTestInterface>(new ContainerTestClass());

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                () => container.RegisterInstance <IContainerTestInterface>(new ContainerTestClass()),
                "Container already contains 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type as a key.");
        }
コード例 #5
0
        public void CreateInstance_Should_Throw_Exception_When_UnknownInstances_Has_More_Than_One_Entry_Of_The_Same_Type()
        {
            // Arrange
            var container        = ContainerFactory.Create();
            var unknownInstance1 = new ContainerUnknownInstanceTestClass();
            var unknownInstance2 = new ContainerUnknownInstanceTestClass();

            // Act
            // Assert
            ExceptionAssert.Thrown <ArgumentException>(
                () => container.CreateInstance <ContainerTestClassWithUnknownInstance>(unknownInstance1, unknownInstance2),
                $"unknownInstances has more than one entry of the same type.{Environment.NewLine}Parameter name: unknownInstances");
        }
コード例 #6
0
        public void RemoveInstance_Should_Throw_Exception_When_Implementation_Is_Registered_Per_Call()
        {
            // Arrange
            var container = ContainerFactory.Create();

            container.RegisterImplementation <IContainerTestInterface, ContainerTestClass>();
            container.Get <IContainerTestInterface>();

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                container.RemoveInstance <IContainerTestInterface>,
                "Container does not contain an instance of 'Agero.Core.DIContainer.Tests.Types.IContainerTestInterface' type.");
        }
コード例 #7
0
        public void CreateInstance_Should_Throw_Exception_When_Property_Injected_Instance_Is_Not_Registered()
        {
            // Arrange
            var container = ContainerFactory.Create();

            container.RegisterImplementation <IContainerTestInterface, ContainerTestClass>();

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                () => container.CreateInstance <ContainerTestClassWithInjectedInstances>(),
                "The property types (Agero.Core.DIContainer.Tests.Types.IContainerTestInterface2) of type" +
                " 'Agero.Core.DIContainer.Tests.Types.ContainerTestClassWithInjectedInstances' are not registered" +
                " in the container or not passed as unknown instances.");
        }
コード例 #8
0
        public void CreateInstance_Should_Throw_Exception_When_Constructor_Injected_Instance_Is_Not_Registered()
        {
            // Arrange
            var container = ContainerFactory.Create();

            container.RegisterImplementation <IContainerTestInterface2, ContainerTestClass2>();

            // Act
            // Assert
            ExceptionAssert.Thrown <ContainerException>(
                () => container.CreateInstance <ContainerTestClassWithInjectedInstances>(),
                "The types (Agero.Core.DIContainer.Tests.Types.IContainerTestInterface) which" +
                " are the parameters of constructor of type 'Agero.Core.DIContainer.Tests.Types.ContainerTestClassWithInjectedInstances'" +
                " are not registered in the container or not passed as unknown instances.");
        }