Пример #1
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");
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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");
        }
Пример #5
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");
        }