Beispiel #1
0
        public void Registrer_Post_OK_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 result = (RedirectToRouteResult)controller.RegistrerBestilling(innBestilling);

            // Assert
            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.First(), "IngenTilgang");
        }
Beispiel #2
0
        public void Registrer()
        {
            // 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.RegistrerBestilling();

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

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

            var innBestilling = new Bestilling();

            innBestilling.Id = 0;

            // Act
            var actionResult = (ViewResult)controller.RegistrerBestilling(innBestilling);

            // Assert
            Assert.AreEqual(actionResult.ViewName, "~/Views/Error/Error.cshtml");
        }
Beispiel #4
0
        public void Session_false()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var controller  = new BestillingController(new BestillingBLL(new BestillingStub()));;

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

            var innBestilling = new Bestilling()
            {
                Id = 1
            };
            // Act
            var result = (RedirectToRouteResult)controller.RegistrerBestilling();

            // Assert
            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.First(), "IngenTilgang");
        }
Beispiel #5
0
        public void Registrer_Post_Model_feil()
        {
            // 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("id", "Ikke oppgitt id");

            // Act
            var actionResult = (ViewResult)controller.RegistrerBestilling(innBestilling);

            // Assert
            Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1);
            Assert.AreEqual(actionResult.ViewName, "~/Views/Error/Error.cshtml");
        }