Example #1
0
        public void OnProvidersExecuting_ValidatesTempDataProperties()
        {
            // Arrange
            var type     = typeof(TestController_PrivateSet);
            var options  = Options.Create(new MvcViewOptions());
            var provider = new TempDataApplicationModelProvider(options);
            var expected = $"The '{type.FullName}.Test' property with TempDataAttribute is invalid. A property using TempDataAttribute must have a public getter and setter.";

            var context = GetContext(type);

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => provider.OnProvidersExecuting(context));

            Assert.Equal(expected, ex.Message);
        }
Example #2
0
        public void AddsTempDataPropertyFilter_ForTempDataAttributeProperties()
        {
            // Arrange
            var type     = typeof(TestController_NullableNonPrimitiveTempDataProperty);
            var options  = Options.Create(new MvcViewOptions());
            var provider = new TempDataApplicationModelProvider(options);

            var context = GetContext(type);

            // Act
            provider.OnProvidersExecuting(context);

            // Assert
            var controller = Assert.Single(context.Result.Controllers);

            Assert.IsType <ControllerSaveTempDataPropertyFilterFactory>(Assert.Single(controller.Filters));
        }
Example #3
0
        public void OnProvidersExecuting_DoesNotAddFilter_IfTypeHasNoTempDataProperties()
        {
            // Arrange
            var type     = typeof(TestController_NoTempDataProperties);
            var options  = Options.Create(new MvcViewOptions());
            var provider = new TempDataApplicationModelProvider(options);

            var context = GetContext(type);

            // Act
            provider.OnProvidersExecuting(context);

            // Assert
            var controller = Assert.Single(context.Result.Controllers);

            Assert.Empty(controller.Filters);
        }
Example #4
0
        public void OnProvidersExecuting_SetsKeyPrefixToEmptyString()
        {
            // Arrange
            var expected = typeof(TestController_OneTempDataProperty).GetProperty(nameof(TestController_OneTempDataProperty.Test2));
            var options  = Options.Create(new MvcViewOptions());
            var type     = typeof(TestController_OneTempDataProperty);
            var provider = new TempDataApplicationModelProvider(options);
            var context  = GetContext(type);

            // Act
            provider.OnProvidersExecuting(context);
            var controller = context.Result.Controllers.SingleOrDefault();
            var filter     = Assert.IsType <ControllerSaveTempDataPropertyFilterFactory>(Assert.Single(controller.Filters));

            // Assert
            Assert.NotNull(filter);
            var property = Assert.Single(filter.TempDataProperties);

            Assert.Same(expected, property.PropertyInfo);
            Assert.Equal("Test2", property.Key);
        }