コード例 #1
0
        public void Endre_funnet_Session_ikke_OK()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var controller  = new BestillingController(new BestillingBLL(new BestillingStub()));

            SessionMock.InitializeController(controller);
            controller.Session["LoggetInn"] = false;

            // Bestilling Objekter
            var reiseFra = new Flyplass()
            {
                FlyplassKode = "OSL", By = "Oslo"
            };
            var reiseTil = new Flyplass()
            {
                FlyplassKode = "KRS", By = "Kristiansand"
            };
            var flymaskin = new Flymaskin()
            {
                FlyId = "AA00", Type = "Boeing", Kapasitet = 100
            };
            var rute = new Rute()
            {
                RuteId = "OSLKRS000", ReiseFra = reiseFra, ReiseTil = reiseTil, Dato = "10.10.2017", Tid = "10:00", ReiseTid = "10min", Flymaskin = flymaskin, Pris = 999
            };
            var poststed = new Poststed()
            {
                Postnr = "1000", Sted = "Oslo"
            };
            var kunde = new Kunde()
            {
                Fornavn = "Per", Etternavn = "Olsen", Adresse = "Osloveien 82", Poststed = poststed, Telefon = "12345678", Epost = "*****@*****.**", Aktiv = true
            };

            ;
            var innBestilling = new Bestilling()
            {
                Id    = 1,
                Rute  = rute,
                Kunde = kunde
            };

            // Act
            var actionResultat = (RedirectToRouteResult)controller.EndreBestilling(1, innBestilling);

            // Assert
            Assert.AreEqual(actionResultat.RouteName, "");
            Assert.AreEqual(actionResultat.RouteValues.Values.First(), "IngenTilgang");
        }
コード例 #2
0
        public void Endre()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var controller  = new BestillingController(new BestillingBLL(new BestillingStub()));

            SessionMock.InitializeController(controller);
            controller.Session["LoggetInn"] = true;

            // Act
            var actionResult = (ViewResult)controller.EndreBestilling(1);

            // Assert
            Assert.AreEqual(actionResult.ViewName, "");
        }
コード例 #3
0
        public void Endre_session_ikke_OK()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var controller  = new BestillingController(new BestillingBLL(new BestillingStub()));

            SessionMock.InitializeController(controller);
            controller.Session["LoggetInn"] = false;

            // Act
            var result = (RedirectToRouteResult)controller.EndreBestilling(1);

            // Assert
            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.First(), "IngenTilgang");
        }
コード例 #4
0
        public void Endre_Ikke_Funnet_Ved_View()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var controller  = new BestillingController(new BestillingBLL(new BestillingStub()));

            SessionMock.InitializeController(controller);
            controller.Session["LoggetInn"] = true;

            // Act
            var actionResult       = (ViewResult)controller.EndreBestilling(0);
            var bestillingResultat = (Bestilling)actionResult.Model;

            // Assert
            Assert.AreEqual(actionResult.ViewName, "");
            Assert.AreEqual(bestillingResultat.Id, 0);
        }
コード例 #5
0
        public async Task EndreBestillingInnloggetOK()
        {
            mockRep.Setup(s => s.EndreBestilling(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(true);

            var BestillingController = new BestillingController(mockRep.Object, mockLog.Object);

            mockSession[_loggetInn] = _loggetInn;
            mockHttpContext.Setup(s => s.Session).Returns(mockSession);
            BestillingController.ControllerContext.HttpContext = mockHttpContext.Object;

            //Act
            var resultat = await BestillingController.EndreBestilling(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()) as OkObjectResult;

            //Assert
            Assert.Equal((int)HttpStatusCode.OK, resultat.StatusCode);
            Assert.Equal("Bestilling endret", resultat.Value);
        }
コード例 #6
0
        public async Task EndreBestillingIkkeInnlogget()
        {
            mockRep.Setup(s => s.EndreBestilling(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(false);

            var BestillingController = new BestillingController(mockRep.Object, mockLog.Object);

            mockSession[_loggetInn] = _ikkeLoggetInn;
            mockHttpContext.Setup(s => s.Session).Returns(mockSession);
            BestillingController.ControllerContext.HttpContext = mockHttpContext.Object;

            //Act
            var resultat = await BestillingController.EndreBestilling(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()) as UnauthorizedObjectResult;

            //Assert
            Assert.Equal((int)HttpStatusCode.Unauthorized, resultat.StatusCode);
            Assert.Equal("Ikke innlogget", resultat.Value);
        }
コード例 #7
0
        public void Endre_feil_validering_Post()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var controller  = new BestillingController(new BestillingBLL(new BestillingStub()));

            SessionMock.InitializeController(controller);
            controller.Session["LoggetInn"] = true;

            var innBestilling = new Bestilling();

            controller.ViewData.ModelState.AddModelError("feil", "Id = 0");

            // Act
            var actionResult = (ViewResult)controller.EndreBestilling(0, innBestilling);

            // Assert
            Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1);
            Assert.AreEqual(actionResult.ViewData.ModelState["feil"].Errors[0].ErrorMessage, "Id = 0");
            Assert.AreEqual(actionResult.ViewName, "~/Views/Error/Error.cshtml");
        }