Esempio n. 1
0
        public void GetModelBindingContext_ModelBindingContextIsNotSet_ForTypes(
            string actionMethodName, bool expectedFallToEmptyPrefix, string expectedModelName)
        {
            // Arrange
            var type       = typeof(ControllerActionArgumentBinderTests);
            var methodInfo = type.GetMethod(actionMethodName);

            var actionContext = new ActionContext(
                new RouteContext(Mock.Of <HttpContext>()),
                Mock.Of <ActionDescriptor>());

            var metadataProvider = new DataAnnotationsModelMetadataProvider();
            var modelMetadata    = metadataProvider.GetMetadataForParameter(modelAccessor: null,
                                                                            methodInfo: methodInfo,
                                                                            parameterName: "parameter1");

            // Act
            var context = DefaultControllerActionArgumentBinder.GetModelBindingContext(
                modelMetadata,
                actionContext,
                Mock.Of <OperationBindingContext>());

            // Assert
            Assert.Equal(expectedFallToEmptyPrefix, context.FallbackToEmptyPrefix);
            Assert.Equal(expectedModelName, context.ModelName);
        }
Esempio n. 2
0
        public void GetModelBindingContext_UsesBindAttributeOnType_IfNoBindAttributeOnParameter_ForPrefix()
        {
            // Arrange
            var type          = typeof(ControllerActionArgumentBinderTests);
            var methodInfo    = type.GetMethod("ParameterWithNoBindAttribute");
            var actionContext = new ActionContext(new RouteContext(Mock.Of <HttpContext>()),
                                                  Mock.Of <ActionDescriptor>());

            var metadataProvider = new DataAnnotationsModelMetadataProvider();
            var modelMetadata    = metadataProvider.GetMetadataForParameter(modelAccessor: null,
                                                                            methodInfo: methodInfo,
                                                                            parameterName: "parameter");

            var actionBindingContext = new ActionBindingContext(actionContext,
                                                                Mock.Of <IModelMetadataProvider>(),
                                                                Mock.Of <IModelBinder>(),
                                                                Mock.Of <IValueProvider>(),
                                                                Mock.Of <IInputFormatterSelector>(),
                                                                Mock.Of <IModelValidatorProvider>());
            // Act
            var context = DefaultControllerActionArgumentBinder.GetModelBindingContext(
                modelMetadata, actionBindingContext, Mock.Of <OperationBindingContext>());

            // Assert
            Assert.Equal("TypePrefix", context.ModelName);
        }