Beispiel #1
0
        public void Controller_PartialView_WithParameterViewNameAndViewModel_SetsResultViewNameAndViewDataModelAndSameTempData()
        {
            // Arrange
            var controller = new TestableController()
            {
                ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
                TempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>()),
            };
            var model = new object();

            // Act
            var actualViewResult = controller.PartialView("CustomViewName", model);

            // Assert
            Assert.IsType <PartialViewResult>(actualViewResult);
            Assert.Equal("CustomViewName", actualViewResult.ViewName);
            Assert.Same(controller.ViewData, actualViewResult.ViewData);
            Assert.Same(controller.TempData, actualViewResult.TempData);
            Assert.Same(model, actualViewResult.ViewData.Model);
        }
Beispiel #2
0
        public void Controller_PartialView_WithNullModelParameter_OverwritesViewDataModel()
        {
            // Arrange
            var controller = new TestableController()
            {
                ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
                TempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>()),
            };

            controller.ViewData.Model = new object();

            // Act
            var actualViewResult = controller.PartialView(model: null);

            // Assert
            Assert.IsType <PartialViewResult>(actualViewResult);
            Assert.Null(actualViewResult.ViewName);
            Assert.Same(controller.ViewData, actualViewResult.ViewData);
            Assert.Same(controller.TempData, actualViewResult.TempData);
            Assert.Null(actualViewResult.ViewData.Model);
        }