public void GivenNoAuthenticatedUser_WhenILogin_ThenIGetTheLoginView() { MockHttpContext.Setup(h => h.User).Returns(new UserViewModel()); ActionResult result = sessionController.New(); result.Should().BeOfType <ViewResult>(); }
public void GivenNoAuthenticatedUser_WhenILogin_ThenIGetTheLoginView() { MockHttpContext.Setup(h => h.User).Returns(new UserViewModel()); ActionResult result = _sessionController.New(); Assert.That(result, Is.TypeOf <ViewResult>()); }
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"); }
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(); }
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); }
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>(); }
public void GivenALoggedInUser_WhenMySessionExpires_ThenIGetTheExpiredView() { SetControllerContext(_sessionController); MockHttpContext.Setup(x => x.Session.Clear()); var result = _sessionController.Expired() as ActionResult; result.Should().BeOfType <ViewResult>(); }
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); }
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"); }
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>(); }
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); }
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"); }
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); }
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>(); }
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"); }
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"); }
public void GiveAJobController_WhenIWantTheJobReportListAndEnvironmentValueIsEmpty_ThenAnExceptionIsThrown() { MockHttpContext.Setup(m => m.Session["Environment"]).Returns(String.Empty); this.jobsController.GetJobReportList(It.IsAny <String>(), It.IsAny <String>()); }