Пример #1
0
        public void GetActionMethodErrorMessageReturnsNullIfStaticMethodIsValid()
        {
            // Arrange
            MethodInfo methodInfo = typeof(object).GetMethod("ReferenceEquals");

            // Act
            string errorMessage = AsyncActionDescriptor.GetActionMethodErrorMessage(methodInfo);

            // Assert
            Assert.IsNull(errorMessage, "Error message should be null since method is valid.");
        }
Пример #2
0
        public void GetActionMethodErrorMessageReturnsNullIfInstanceMethodIsValid()
        {
            // Arrange
            MethodInfo methodInfo = typeof(MyController).GetMethod("ValidAction");

            // Act
            string errorMessage = AsyncActionDescriptor.GetActionMethodErrorMessage(methodInfo);

            // Assert
            Assert.IsNull(errorMessage, "Error message should be null since method is valid.");
        }
Пример #3
0
        public void GetActionMethodErrorMessageForMethodWithRefParameter()
        {
            // Arrange
            MethodInfo methodInfo = typeof(MyController).GetMethod("ActionWithRefParameter");

            // Act
            string errorMessage = AsyncActionDescriptor.GetActionMethodErrorMessage(methodInfo);

            // Assert
            Assert.AreEqual(@"Cannot call action method 'Void ActionWithRefParameter(Int32 ByRef)' on controller 'Microsoft.Web.Mvc.Test.AsyncActionDescriptorTest+MyController' since the parameter 'Int32& id' is passed by reference.", errorMessage);
        }
Пример #4
0
        public void GetActionMethodErrorMessageForInstanceMethodWithOpenGenericParameter()
        {
            // Arrange
            MethodInfo methodInfo = typeof(MyController).GetMethod("ActionWithOpenGenericParameter");

            // Act
            string errorMessage = AsyncActionDescriptor.GetActionMethodErrorMessage(methodInfo);

            // Assert
            Assert.AreEqual(@"Cannot call action method 'Void ActionWithOpenGenericParameter[T]()' on controller 'Microsoft.Web.Mvc.Test.AsyncActionDescriptorTest+MyController' since it is a generic method.", errorMessage);
        }
Пример #5
0
        public void GetActionMethodErrorMessageForInstanceMethodOnWrongTargetType()
        {
            // Arrange
            MethodInfo methodInfo = typeof(object).GetMethod("ToString");

            // Act
            string errorMessage = AsyncActionDescriptor.GetActionMethodErrorMessage(methodInfo);

            // Assert
            Assert.AreEqual(@"Cannot create a descriptor for instance method 'System.String ToString()' on type 'System.Object' since the type does not subclass ControllerBase.", errorMessage);
        }
Пример #6
0
        public void ExtractParameterFromDictionaryThrowsIfParameterIsMissing()
        {
            // Arrange
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            // Act & assert
            ExceptionHelper.ExpectArgumentException(
                delegate {
                AsyncActionDescriptor.ExtractParameterFromDictionary(_integerParameter, parameters, _convertIntToStringMethod);
            }, @"The parameters dictionary does not contain an entry for parameter 'value' of type 'System.Int32' for method 'System.String ToString(Int32)' in 'System.Convert'. The dictionary must contain an entry for each parameter, even parameters with null values.
Parameter name: parameters");
        }
Пример #7
0
        public void GetAsyncManagerThrowsIfControllerIsNotAsyncManagerContainer()
        {
            // Arrange
            ControllerBase controller = new MyController();

            // Act & assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                AsyncActionDescriptor.GetAsyncManager(controller);
            },
                @"The controller of type 'Microsoft.Web.Mvc.Test.AsyncActionDescriptorTest+MyController' must subclass AsyncController or implement the IAsyncManagerContainer interface.");
        }
Пример #8
0
        public void ExtractParameterFromDictionaryReturnsParameterIfValid()
        {
            // Arrange
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "value", 42 }
            };

            // Act
            object returned = AsyncActionDescriptor.ExtractParameterFromDictionary(_integerParameter, parameters, _convertIntToStringMethod);

            // Assert
            Assert.AreEqual(42, returned);
        }
Пример #9
0
        public void ExtractParameterFromDictionaryReturnsNullIfParameterIsNullAndNullableType()
        {
            // Arrange
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "value", null }
            };

            // Act
            object returned = AsyncActionDescriptor.ExtractParameterFromDictionary(_stringParameter, parameters, _convertStringToIntMethod);

            // Assert
            Assert.IsNull(returned);
        }
Пример #10
0
        public void ExtractParameterFromDictionaryThrowsIfParameterIsWrongType()
        {
            // Arrange
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "value", 42 }
            };

            // Act & assert
            ExceptionHelper.ExpectArgumentException(
                delegate {
                AsyncActionDescriptor.ExtractParameterFromDictionary(_stringParameter, parameters, _convertStringToIntMethod);
            }, @"The parameters dictionary contains an invalid entry for parameter 'value' for method 'Int32 ToInt32(System.String)' in 'System.Convert'. The dictionary contains a value of type 'System.Int32', but the parameter requires a value of type 'System.String'.
Parameter name: parameters");
        }
Пример #11
0
        public void ExtractParameterFromDictionaryThrowsIfRequiredParameterIsNull()
        {
            // Arrange
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "value", null }
            };

            // Act & assert
            ExceptionHelper.ExpectArgumentException(
                delegate {
                AsyncActionDescriptor.ExtractParameterFromDictionary(_integerParameter, parameters, _convertIntToStringMethod);
            }, @"The parameters dictionary contains a null entry for parameter 'value' of non-nullable type 'System.Int32' for method 'System.String ToString(Int32)' in 'System.Convert'. To make a parameter optional its type should be either a reference type or a Nullable type.
Parameter name: parameters");
        }
Пример #12
0
        public void GetAsyncManager()
        {
            // Arrange
            AsyncManager asyncHelper = new AsyncManager();

            Mock <Controller> mockController = new Mock <Controller>();

            mockController.As <IAsyncManagerContainer>().Expect(c => c.AsyncManager).Returns(asyncHelper);
            Controller controller = mockController.Object;

            // Act
            AsyncManager returned = AsyncActionDescriptor.GetAsyncManager(controller);

            // Assert
            Assert.AreEqual(asyncHelper, returned);
        }