예제 #1
0
        public void CreateViewDataDictionary_UsesDeclaredTypeOverModelType_WhenCreatingTheViewDataDictionary()
        {
            // Arrange
            var modelMetadataProvider = new EmptyModelMetadataProvider();
            var activator             = new RazorPagePropertyActivator(
                typeof(TestPage),
                declaredModelType: typeof(TestModel),
                metadataProvider: modelMetadataProvider,
                propertyValueAccessors: null);
            var original = new ViewDataDictionary(modelMetadataProvider, new ModelStateDictionary())
            {
                { "test-key", "test-value" },
            };
            var viewContext = new ViewContext
            {
                ViewData = original,
            };

            // Act
            var viewDataDictionary = activator.CreateViewDataDictionary(viewContext);

            // Assert
            Assert.NotNull(viewDataDictionary);
            Assert.NotSame(original, viewDataDictionary);
            Assert.IsType <ViewDataDictionary <TestModel> >(viewDataDictionary);
            Assert.Equal("test-value", viewDataDictionary["test-key"]);
        }
예제 #2
0
        public void CreateViewDataDictionary_ReturnsInstanceOnContext_IfModelTypeMatches()
        {
            // Arrange
            var modelMetadataProvider = new EmptyModelMetadataProvider();
            var activator             = new RazorPagePropertyActivator(
                typeof(TestPage),
                declaredModelType: typeof(TestModel),
                metadataProvider: modelMetadataProvider,
                propertyValueAccessors: null);
            var original = new ViewDataDictionary <TestModel>(modelMetadataProvider, new ModelStateDictionary())
            {
                { "test-key", "test-value" },
            };
            var viewContext = new ViewContext
            {
                ViewData = original,
            };

            // Act
            var viewDataDictionary = activator.CreateViewDataDictionary(viewContext);

            // Assert
            Assert.NotNull(viewDataDictionary);
            Assert.Same(original, viewDataDictionary);
        }
예제 #3
0
        public void CreateViewDataDictionary_MakesNewInstanceWithObjectModelType_WhenValueOnContextAndModelTypeAreNull()
        {
            // Arrange
            var activator = new RazorPagePropertyActivator(
                typeof(TestPage),
                declaredModelType: null,
                metadataProvider: new EmptyModelMetadataProvider(),
                propertyValueAccessors: null);
            var viewContext = new ViewContext();

            // Act
            var viewDataDictionary = activator.CreateViewDataDictionary(viewContext);

            // Assert
            Assert.NotNull(viewDataDictionary);
            Assert.IsType <ViewDataDictionary <object> >(viewDataDictionary);
        }
예제 #4
0
        public void CreateViewDataDictionary_MakesNewInstance_WhenValueOnContextIsNull()
        {
            // Arrange
            var activator = new RazorPagePropertyActivator(
                typeof(TestPage),
                typeof(TestModel),
                new EmptyModelMetadataProvider(),
                propertyValueAccessors: null);
            var viewContext = new ViewContext();

            // Act
            var viewDataDictionary = activator.CreateViewDataDictionary(viewContext);

            // Assert
            Assert.NotNull(viewDataDictionary);
            Assert.IsType <ViewDataDictionary <TestModel> >(viewDataDictionary);
        }