public void Endre_funnet_session_ikke_OK() { // Arrange var SessionMock = new TestControllerBuilder(); var controller = new RuteController(new RuteBLL(new RuteStub())); SessionMock.InitializeController(controller); controller.Session["LoggetInn"] = false; var innRute = new Rute() { RuteId = "OSLKRS000", ReiseFra = reiseFra, ReiseTil = reiseTil, Dato = "10.10.2017", Tid = "10:00", ReiseTid = "10min", Flymaskin = flymaskin, Pris = 999 }; // Act var actionResultat = (RedirectToRouteResult)controller.EndreRute("OSLKRS000", innRute); // Assert Assert.AreEqual(actionResultat.RouteName, ""); Assert.AreEqual(actionResultat.RouteValues.Values.First(), "IngenTilgang"); }
public void Endre_ikke_funnet_Post() { // Arrange var SessionMock = new TestControllerBuilder(); var controller = new RuteController(new RuteBLL(new RuteStub())); SessionMock.InitializeController(controller); controller.Session["LoggetInn"] = true; var innRute = new Rute() { RuteId = "OSLKRS000", ReiseFra = reiseFra, ReiseTil = reiseTil, Dato = "10.10.2017", Tid = "10:00", ReiseTid = "10min", Flymaskin = flymaskin, Pris = 999 }; // Act var actionResult = (ViewResult)controller.EndreRute("", innRute); // Assert Assert.AreEqual(actionResult.ViewName, "~/Views/Error/Error.cshtml"); }
public void Endre() { // Arrange var SessionMock = new TestControllerBuilder(); var controller = new RuteController(new RuteBLL(new RuteStub())); SessionMock.InitializeController(controller); controller.Session["LoggetInn"] = true; // Act var actionResult = (ViewResult)controller.EndreRute(""); // Assert Assert.AreEqual(actionResult.ViewName, ""); }
public async Task RuteEndreIkkeFunnet() { mockRepo.Setup(k => k.EndreRute(It.IsAny <Rute>())).ReturnsAsync(false); var ruteController = new RuteController(mockRepo.Object, mockLog.Object); mockSession[_loggetInn] = _loggetInn; mockHttpContext.Setup(s => s.Session).Returns(mockSession); ruteController.ControllerContext.HttpContext = mockHttpContext.Object; var resultat = await ruteController.EndreRute(It.IsAny <Rute>()) as NotFoundObjectResult; Assert.Equal((int)HttpStatusCode.NotFound, resultat.StatusCode); Assert.Equal("Kunne ikke endre ruten", resultat.Value); }
public async Task RuteEndreUnauthorized() { mockRepo.Setup(k => k.EndreRute(It.IsAny <Rute>())).ReturnsAsync(false); var ruteController = new RuteController(mockRepo.Object, mockLog.Object); mockSession[_loggetInn] = _ikkeLoggetInn; mockHttpContext.Setup(s => s.Session).Returns(mockSession); ruteController.ControllerContext.HttpContext = mockHttpContext.Object; var resultat = await ruteController.EndreRute(It.IsAny <Rute>()) as UnauthorizedObjectResult; Assert.Equal((int)HttpStatusCode.Unauthorized, resultat.StatusCode); Assert.Equal("Ikke logget inn", resultat.Value); }
public void Endre_session_ikke_OK() { // Arrange var SessionMock = new TestControllerBuilder(); var controller = new RuteController(new RuteBLL(new RuteStub())); SessionMock.InitializeController(controller); controller.Session["LoggetInn"] = false; // Act var result = (RedirectToRouteResult)controller.EndreRute(""); // Assert Assert.AreEqual(result.RouteName, ""); Assert.AreEqual(result.RouteValues.Values.First(), "IngenTilgang"); }
public void Endre_Ikke_Funnet_Ved_View() { // Arrange var SessionMock = new TestControllerBuilder(); var controller = new RuteController(new RuteBLL(new RuteStub())); SessionMock.InitializeController(controller); controller.Session["LoggetInn"] = true; // Act var actionResult = (ViewResult)controller.EndreRute(""); var flyplassResultat = (Rute)actionResult.Model; // Assert Assert.AreEqual(actionResult.ViewName, ""); Assert.AreEqual(flyplassResultat.RuteId, "TSTTST000"); }
public async Task RuteEndreFeilModel() { mockRepo.Setup(k => k.EndreRute(It.IsAny <Rute>())).ReturnsAsync(false); var ruteController = new RuteController(mockRepo.Object, mockLog.Object); ruteController.ModelState.AddModelError("Navn", "Ruteobjektet er ikke validert"); mockSession[_loggetInn] = _loggetInn; mockHttpContext.Setup(s => s.Session).Returns(mockSession); ruteController.ControllerContext.HttpContext = mockHttpContext.Object; var resultat = await ruteController.EndreRute(It.IsAny <Rute>()) as BadRequestObjectResult; Assert.Equal((int)HttpStatusCode.BadRequest, resultat.StatusCode); Assert.Equal("Ruteobjektet er ikke validert", resultat.Value); }
public void Endre_feil_validering_Post() { // Arrange var SessionMock = new TestControllerBuilder(); var controller = new RuteController(new RuteBLL(new RuteStub())); SessionMock.InitializeController(controller); controller.Session["LoggetInn"] = true; var innRute = new Rute(); controller.ViewData.ModelState.AddModelError("feil", "RuteId = ''"); // Act var actionResult = (ViewResult)controller.EndreRute("", innRute); // Assert Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1); Assert.AreEqual(actionResult.ViewData.ModelState["feil"].Errors[0].ErrorMessage, "RuteId = ''"); Assert.AreEqual(actionResult.ViewName, "~/Views/Error/Error.cshtml"); }
public async Task RuteEndreOk() { var mockListe = new List <Stasjon>(); var ruten = new Rute() { Navn = "Drammen-Oslo", Id = 2, StasjonerPaaRute = mockListe, }; mockRepo.Setup(k => k.EndreRute(ruten)).ReturnsAsync(true); var ruteController = new RuteController(mockRepo.Object, mockLog.Object); mockSession[_loggetInn] = _loggetInn; mockHttpContext.Setup(s => s.Session).Returns(mockSession); ruteController.ControllerContext.HttpContext = mockHttpContext.Object; var resultat = await ruteController.EndreRute(ruten) as OkObjectResult; Assert.Equal((int)HttpStatusCode.OK, resultat.StatusCode); Assert.Equal("Ruten ble endret", resultat.Value); }