예제 #1
0
        public void EngineLookupFailureThrows() {
            // Arrange
            ControllerBase controller = new Mock<ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData routeData = new RouteData();
            routeData.Values["action"] = _viewName;
            ControllerContext context = new ControllerContext(httpContext, routeData, controller);
            Mock<IViewEngine> viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
            List<IViewEngine> viewEngines = new List<IViewEngine>();
            viewEngines.Add(viewEngine.Object);
            Mock<ViewEngineCollection> viewEngineCollection = new Mock<ViewEngineCollection>(MockBehavior.Strict, viewEngines);
            ViewResult result = new ViewResultHelper { ViewEngineCollection = viewEngineCollection.Object };
            viewEngineCollection
                .Setup(e => e.FindView(It.IsAny<ControllerContext>(), _viewName, _masterName))
                .Returns(new ViewEngineResult(new[] { "location1", "location2" }));
            viewEngine
                .Setup(e => e.FindView(It.IsAny<ControllerContext>(), _viewName, _masterName, It.IsAny<bool>()))
                .Callback<ControllerContext, string, string, bool>(
                    (controllerContext, viewName, masterName, useCache) => {
                        Assert.AreSame(httpContext, controllerContext.HttpContext);
                        Assert.AreSame(routeData, controllerContext.RouteData);
                    })
                .Returns(new ViewEngineResult(new[] { "location1", "location2" }));

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                () => result.ExecuteResult(context),
                @"The view '" + _viewName + @"' or its master was not found or no view engine supports the searched locations. The following locations were searched:
location1
location2");

            viewEngine.Verify();
            viewEngineCollection.Verify();
        }
예제 #2
0
        public void ExecuteResultWithExplicitViewObject()
        {
            // Arrange
            ControllerBase  controller  = new Mock <ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData       routeData   = new RouteData();

            routeData.Values["action"] = _viewName;
            ControllerContext context = new ControllerContext(httpContext, routeData, controller);
            Mock <IView>      view    = new Mock <IView>(MockBehavior.Strict);
            ViewResult        result  = new ViewResultHelper {
                View = view.Object
            };

            view
            .Setup(o => o.Render(It.IsAny <ViewContext>(), httpContext.Response.Output))
            .Callback <ViewContext, TextWriter>(
                (viewContext, writer) =>
            {
                Assert.Same(view.Object, viewContext.View);
                Assert.Same(result.ViewData, viewContext.ViewData);
                Assert.Same(result.TempData, viewContext.TempData);
                Assert.Same(controller, viewContext.Controller);
            });

            // Act
            result.ExecuteResult(context);

            // Assert
            view.Verify();
        }
예제 #3
0
        public void EngineLookupFailureThrows()
        {
            // Arrange
            ControllerBase  controller  = new Mock <ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData       routeData   = new RouteData();

            routeData.Values["action"] = _viewName;
            ControllerContext  context     = new ControllerContext(httpContext, routeData, controller);
            Mock <IViewEngine> viewEngine  = new Mock <IViewEngine>(MockBehavior.Strict);
            List <IViewEngine> viewEngines = new List <IViewEngine>();

            viewEngines.Add(viewEngine.Object);
            Mock <ViewEngineCollection> viewEngineCollection = new Mock <ViewEngineCollection>(
                MockBehavior.Strict,
                viewEngines
                );
            ViewResult result = new ViewResultHelper
            {
                ViewEngineCollection = viewEngineCollection.Object
            };

            viewEngineCollection
            .Setup(e => e.FindView(It.IsAny <ControllerContext>(), _viewName, _masterName))
            .Returns(new ViewEngineResult(new[] { "location1", "location2" }));
            viewEngine
            .Setup(
                e =>
                e.FindView(
                    It.IsAny <ControllerContext>(),
                    _viewName,
                    _masterName,
                    It.IsAny <bool>()
                    )
                )
            .Callback <ControllerContext, string, string, bool>(
                (controllerContext, viewName, masterName, useCache) =>
            {
                Assert.Same(httpContext, controllerContext.HttpContext);
                Assert.Same(routeData, controllerContext.RouteData);
            }
                )
            .Returns(new ViewEngineResult(new[] { "location1", "location2" }));

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => result.ExecuteResult(context),
                "The view '"
                + _viewName
                + "' or its master was not found or no view engine supports the searched locations. The following locations were searched:"
                + Environment.NewLine
                + "location1"
                + Environment.NewLine
                + "location2"
                );

            viewEngine.Verify();
            viewEngineCollection.Verify();
        }
예제 #4
0
        public void ExecuteResultWithNullControllerContextThrows()
        {
            // Arrange
            ViewResult result = new ViewResultHelper();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => result.ExecuteResult(null), "context");
        }
예제 #5
0
        public void ExecuteResultWithNullControllerContextThrows()
        {
            // Arrange
            ViewResult result = new ViewResultHelper();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => result.ExecuteResult(null),
                "context");
        }
예제 #6
0
        public void EmptyViewNameUsesActionNameAsViewName()
        {
            // Arrange
            ControllerBase  controller  = new Mock <ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData       routeData   = new RouteData();

            routeData.Values["action"] = _viewName;
            ControllerContext  context     = new ControllerContext(httpContext, routeData, controller);
            Mock <IViewEngine> viewEngine  = new Mock <IViewEngine>(MockBehavior.Strict);
            Mock <IView>       view        = new Mock <IView>(MockBehavior.Strict);
            List <IViewEngine> viewEngines = new List <IViewEngine>();

            viewEngines.Add(viewEngine.Object);
            Mock <ViewEngineCollection> viewEngineCollection = new Mock <ViewEngineCollection>(MockBehavior.Strict, viewEngines);
            ViewResult result = new ViewResultHelper {
                ViewEngineCollection = viewEngineCollection.Object
            };

            viewEngineCollection
            .Setup(e => e.FindView(It.IsAny <ControllerContext>(), _viewName, _masterName))
            .Returns(new ViewEngineResult(view.Object, viewEngine.Object));
            viewEngine
            .Setup(e => e.FindView(It.IsAny <ControllerContext>(), _viewName, _masterName, It.IsAny <bool>()))
            .Callback <ControllerContext, string, string, bool>(
                (controllerContext, viewName, masterName, useCache) =>
            {
                Assert.Same(httpContext, controllerContext.HttpContext);
                Assert.Same(routeData, controllerContext.RouteData);
            })
            .Returns(new ViewEngineResult(view.Object, viewEngine.Object));
            view
            .Setup(o => o.Render(It.IsAny <ViewContext>(), httpContext.Response.Output))
            .Callback <ViewContext, TextWriter>(
                (viewContext, writer) =>
            {
                Assert.Same(view.Object, viewContext.View);
                Assert.Same(result.ViewData, viewContext.ViewData);
                Assert.Same(result.TempData, viewContext.TempData);
                Assert.Same(controller, viewContext.Controller);
            });
            viewEngine
            .Setup(e => e.ReleaseView(context, It.IsAny <IView>()))
            .Callback <ControllerContext, IView>(
                (controllerContext, releasedView) => { Assert.Same(releasedView, view.Object); });

            // Act
            result.ExecuteResult(context);

            // Assert
            viewEngine.Verify();
            viewEngineCollection.Verify();
            view.Verify();
        }
예제 #7
0
        public void EmptyViewNameUsesActionNameAsViewName()
        {
            // Arrange
            ControllerBase controller = new Mock<ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData routeData = new RouteData();
            routeData.Values["action"] = _viewName;
            ControllerContext context = new ControllerContext(httpContext, routeData, controller);
            Mock<IViewEngine> viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
            Mock<IView> view = new Mock<IView>(MockBehavior.Strict);
            List<IViewEngine> viewEngines = new List<IViewEngine>();
            viewEngines.Add(viewEngine.Object);
            Mock<ViewEngineCollection> viewEngineCollection = new Mock<ViewEngineCollection>(MockBehavior.Strict, viewEngines);
            ViewResult result = new ViewResultHelper { ViewEngineCollection = viewEngineCollection.Object };
            viewEngineCollection
                .Setup(e => e.FindView(It.IsAny<ControllerContext>(), _viewName, _masterName))
                .Returns(new ViewEngineResult(view.Object, viewEngine.Object));
            viewEngine
                .Setup(e => e.FindView(It.IsAny<ControllerContext>(), _viewName, _masterName, It.IsAny<bool>()))
                .Callback<ControllerContext, string, string, bool>(
                    (controllerContext, viewName, masterName, useCache) =>
                    {
                        Assert.Same(httpContext, controllerContext.HttpContext);
                        Assert.Same(routeData, controllerContext.RouteData);
                    })
                .Returns(new ViewEngineResult(view.Object, viewEngine.Object));
            view
                .Setup(o => o.Render(It.IsAny<ViewContext>(), httpContext.Response.Output))
                .Callback<ViewContext, TextWriter>(
                    (viewContext, writer) =>
                    {
                        Assert.Same(view.Object, viewContext.View);
                        Assert.Same(result.ViewData, viewContext.ViewData);
                        Assert.Same(result.TempData, viewContext.TempData);
                        Assert.Same(controller, viewContext.Controller);
                    });
            viewEngine
                .Setup(e => e.ReleaseView(context, It.IsAny<IView>()))
                .Callback<ControllerContext, IView>(
                    (controllerContext, releasedView) => { Assert.Same(releasedView, view.Object); });

            // Act
            result.ExecuteResult(context);

            // Assert
            viewEngine.Verify();
            viewEngineCollection.Verify();
            view.Verify();
        }
예제 #8
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<EditViewModel>(controller.Edit(user.Id));
 }
예제 #9
0
파일: Create.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper<CreateDivisionViewModel>(controller.Create(viewModel));
 }
예제 #10
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<DetailsViewModel>(controller.Details(season.Id));
 }
예제 #11
0
파일: Home.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper(controller.Index());
 }
예제 #12
0
 public override void When()
 {
     resultHelper = new ViewResultHelper(controller.Standings());
 }
예제 #13
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<ScoresheetViewModel>(controller.Scoresheet(meet.Id));
 }
예제 #14
0
        public void ExecuteResultWithNullControllerContextThrows()
        {
            // Arrange
            ViewResult result = new ViewResultHelper();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => result.ExecuteResult(null),
                "context");
        }
예제 #15
0
파일: Create.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper<CreateTeamViewModel>(controller.Create(divisionId));
 }
예제 #16
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<SeasonScheduleViewModel>(controller.Schedule());
 }
예제 #17
0
 public override void When()
 {
     resultHelper = new ViewResultHelper(controller.Edit(viewModel));
 }
예제 #18
0
파일: SignUp.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper<CreateViewModel>(controller.SignUp(viewModel, true));
 }
예제 #19
0
파일: Login.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper<LoginViewModel>(controller.Login(viewModel));
 }
예제 #20
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<DashboardViewModel>(controller.Dashboard(null));
 }
예제 #21
0
        public void ExecuteResultWithExplicitViewObject()
        {
            // Arrange
            ControllerBase controller = new Mock<ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData routeData = new RouteData();
            routeData.Values["action"] = _viewName;
            ControllerContext context = new ControllerContext(httpContext, routeData, controller);
            Mock<IView> view = new Mock<IView>(MockBehavior.Strict);
            ViewResult result = new ViewResultHelper { View = view.Object };
            view
                .Setup(o => o.Render(It.IsAny<ViewContext>(), httpContext.Response.Output))
                .Callback<ViewContext, TextWriter>(
                    (viewContext, writer) =>
                    {
                        Assert.Same(view.Object, viewContext.View);
                        Assert.Same(result.ViewData, viewContext.ViewData);
                        Assert.Same(result.TempData, viewContext.TempData);
                        Assert.Same(controller, viewContext.Controller);
                    });

            // Act
            result.ExecuteResult(context);

            // Assert
            view.Verify();
        }
예제 #22
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<SeasonStandingsViewModel>(controller.Standings());
 }
예제 #23
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<UserHistoryViewModel>(controller.UserMatchHistory(user.Id, null));
 }
예제 #24
0
파일: Index.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper<IndexViewModel>(controller.Index(page));
 }
예제 #25
0
        public void ExecuteResultWithNullControllerContextThrows() {
            // Arrange
            ViewResult result = new ViewResultHelper();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => result.ExecuteResult(null),
                "context");
        }
예제 #26
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<ChangeActiveViewModel>(controller.ChangeActive());
 }
예제 #27
0
 public override void When()
 {
     resultHelper = new ViewResultHelper(controller.Schedule());
 }
예제 #28
0
파일: Create.cs 프로젝트: pwideman/ClubPool
 public override void When()
 {
     resultHelper = new ViewResultHelper<CreateSeasonViewModel>(controller.Create(new CreateSeasonViewModel()));
 }
예제 #29
0
 public override void When()
 {
     resultHelper = new ViewResultHelper<UnapprovedUsersViewModel>(controller.UnapprovedUsers());
 }