Exemplo n.º 1
0
        private static void Assert_RegistrationFailsWithExpectedParamName(string paramName, Action action)
        {
            try
            {
                // Act
                action();

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (ArgumentException ex)
            {
                AssertThat.ExceptionContainsParamName(ex, "TService");
            }
        }
        public void Register_RegisteringANonConcreteType_ThrowsAnArgumentExceptionWithExpectedParamName()
        {
            // Arrange
            string expectedParameterName = "TConcrete";

            var container = ContainerFactory.New();

            try
            {
                // Act
                container.Register <IUserRepository>();

                Assert.Fail("The abstract type was not expected to be registered successfully.");
            }
            catch (ArgumentException ex)
            {
                AssertThat.ExceptionContainsParamName(expectedParameterName, ex);
            }
        }
Exemplo n.º 3
0
        public void RegisterByGenericArgument_GenericArgumentOfInvalidType_ThrowsExceptionWithExpectedParamName()
        {
            // Arrange
            string expectedParamName = "TImplementation";

            var container = ContainerFactory.New();

            try
            {
                // Act
                container.Register <object, ConcreteTypeWithValueTypeConstructorArgument>();

                // Assert
                Assert.Fail("Registration of ConcreteTypeWithValueTypeConstructorArgument should fail.");
            }
            catch (ArgumentException ex)
            {
                AssertThat.ExceptionContainsParamName(expectedParamName, ex);
            }
        }