Exemplo n.º 1
0
        public void GivenNoAuthenticatedUser_WhenILogin_ThenIGetTheLoginView()
        {
            MockHttpContext.Setup(h => h.User).Returns(new UserViewModel());
            ActionResult result = sessionController.New();

            result.Should().BeOfType <ViewResult>();
        }
Exemplo n.º 2
0
        public void GivenNoAuthenticatedUser_WhenILogin_ThenIGetTheLoginView()
        {
            MockHttpContext.Setup(h => h.User).Returns(new UserViewModel());
            ActionResult result = _sessionController.New();

            Assert.That(result, Is.TypeOf <ViewResult>());
        }
Exemplo n.º 3
0
        public void GivenALoggedInUser_WhenILoginOut_ThenILoginView()
        {
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            MockHttpContext.Setup(x => x.Session.Clear());

            var result = this.sessionController.Remove() as RedirectToRouteResult;

            result.RouteValues["action"].Should().Be("New");
        }
Exemplo n.º 4
0
        public void GivenThereIsNoCustomError_ThenTheErrorIsHandled()
        {
            var controller    = new TestableBaseController(_logger.Object);
            var filterContext = new ExceptionContext();

            MockHttpContext.Setup(h => h.IsCustomErrorEnabled).Returns(false);
            filterContext.HttpContext = MockHttpContext.Object;
            controller.OnException(filterContext);
            filterContext.ExceptionHandled.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            _syndicationFeedDomain = new Mock <ISyndicationFeedService>();
            MockRequest.Setup(r => r.Url).Returns(new Uri("http://foo.com/feed/rss"));
            var headers = new NameValueCollection();

            headers.Add("HOST", "localhost");
            MockRequest.Setup(r => r.Headers).Returns(headers);
            MockHttpContext.Setup(h => h.Request).Returns(MockRequest.Object);
        }
Exemplo n.º 6
0
        public void GivenNoAuthenticatedUser_WhenILogin_ThenIGetTheLoginView()
        {
            SetControllerContext(_sessionController);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(null);

            MockHttpContext.Setup(h => h.User).Returns(new UserViewModel());
            ActionResult result = _sessionController.New();

            result.Should().BeOfType <ViewResult>();
        }
Exemplo n.º 7
0
        public void GivenALoggedInUser_WhenMySessionExpires_ThenIGetTheExpiredView()
        {
            SetControllerContext(_sessionController);

            MockHttpContext.Setup(x => x.Session.Clear());

            var result = _sessionController.Expired() as ActionResult;

            result.Should().BeOfType <ViewResult>();
        }
Exemplo n.º 8
0
        public void GivenAUser_WhenIRegister_AndTheUserIsNotLoggdIn_ThenTheUserIsSentToTheRegistrationPage()
        {
            var userViewModel = new UserViewModel {
                IsLoggedIn = false
            };

            MockHttpContext.Setup(h => h.User).Returns(userViewModel);
            var result = _controller.New() as ViewResult;

            Assert.That(result, Is.Not.Null);
        }
Exemplo n.º 9
0
        public void GivenThereIsACustomError_AndItIsNotAnHttpRequestValidationException_ThenTheViewIsSetToError()
        {
            var controller    = new TestableBaseController(_logger.Object);
            var filterContext = new ExceptionContext();

            MockHttpContext.Setup(h => h.IsCustomErrorEnabled).Returns(true);
            filterContext.HttpContext = MockHttpContext.Object;
            filterContext.Exception   = new Exception();
            controller.OnException(filterContext);
            filterContext.Result.As <ViewResult>().ViewName.Should().Be("Error");
        }
Exemplo n.º 10
0
        public void GivenThereIsACustomError_AndItIsNotAnHttpRequestValidationException_ThenTheViewIsSetToTheErrorView()
        {
            var controller    = new TestableBaseController(this.logger.Object, this.userService.Object, this.appEnvironmentService.Object);
            var filterContext = new ExceptionContext();

            MockHttpContext.Setup(h => h.IsCustomErrorEnabled).Returns(true);
            filterContext.HttpContext = MockHttpContext.Object;
            filterContext.Exception   = new Exception();
            controller.OnException(filterContext);
            filterContext.Result.Should().BeOfType <ViewResult>();
        }
Exemplo n.º 11
0
        public void GivenAnAuthenticatedUser_WhenILogin_ThenIGetTheRedirectView()
        {
            var userViewModel = new UserViewModel {
                IsLoggedIn = true
            };

            MockHttpContext.Setup(h => h.User).Returns(userViewModel);
            var result = _sessionController.New() as RedirectToRouteResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index").IgnoreCase);
        }
Exemplo n.º 12
0
        public void GivenAnAuthenticatedUser_WhenILogin_ThenIGetTheRedirectView()
        {
            MockHttpContext.Setup(h => h.User).Returns(new UserViewModel()
            {
                IsLoggedIn = true
            });

            var result = this.sessionController.New() as RedirectToRouteResult;

            result.Should().NotBeNull();
            result.RouteValues["action"].Should().Be("Index");
            result.RouteValues["controller"].Should().Be("Home");
        }
Exemplo n.º 13
0
        public void GivenAUser_WhenIRegister_AndTheUserIsAlreadyAuthenticated_ThenIGetRedirectedToTheAdminPage()
        {
            var userViewModel = new UserViewModel {
                IsLoggedIn = true
            };

            MockHttpContext.Setup(h => h.User).Returns(userViewModel);
            var result = _controller.New() as RedirectToRouteResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.RouteValues["controller"], Is.EqualTo("Dashboard").IgnoreCase);
            Assert.That(result.RouteValues["action"], Is.EqualTo("index").IgnoreCase);
        }
Exemplo n.º 14
0
        public void GivenALoggedInUser_WhenILoginOut_ThenIGetTheEndView()
        {
            SetControllerContext(_sessionController);

            MockHttpContext.SetupGet(x => x.Session["SessionGuid"]).Returns("guid");

            _sessionService.Setup(s => s.Update("guid", It.IsAny <DateTime>()));

            MockHttpContext.Setup(x => x.Session.Clear());

            var result = _sessionController.Remove() as ActionResult;

            result.Should().BeOfType <ViewResult>();
        }
Exemplo n.º 15
0
        public void GivenAnAuthenticatedUser_WhenILogin_ThenIGetTheRedirectView()
        {
            SetControllerContext(_sessionController);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(null);

            MockHttpContext.Setup(h => h.User).Returns(new UserViewModel()
            {
                IsLoggedIn = true
            });
            var result = _sessionController.New() as RedirectToRouteResult;

            result.Should().NotBeNull();
            result.RouteValues["action"].Should().Be("Index");
            result.RouteValues["controller"].Should().Be("Dashboard");
        }
Exemplo n.º 16
0
        public void GivenAValidDocumentId_WhenIAskForShow_ThenIGetAFileStreamResult()
        {
            var controller = new DocumentController(
                _documentService.Object,
                _userService.Object,
                _manCoService.Object,
                _logger.Object);

            _documentService.Setup(d => d.GetDocumentStream("documentId")).Returns(new byte[] { 1, 2, 3 });
            SetControllerContext(controller);
            MockHttpContext.Setup(h => h.Response).Returns(new FakeResponse());

            var result = controller.Show("documentId") as FileStreamResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <FileStreamResult>();
        }
        public override void Arrange()
        {
            base.Arrange();

            MockHttpContext.Setup(ctx => ctx.Request[ValueName]).Returns("value");
        }
Exemplo n.º 18
0
        public void GiveAJobController_WhenIWantTheJobReportListAndEnvironmentValueIsEmpty_ThenAnExceptionIsThrown()
        {
            MockHttpContext.Setup(m => m.Session["Environment"]).Returns(String.Empty);

            this.jobsController.GetJobReportList(It.IsAny <String>(), It.IsAny <String>());
        }