Esempio n. 1
0
        public async Task EndreBestillingLoggetInnOk()
        {
            var bestilling = new Bestilling
            {
                Id   = 3,
                pris = 50.00,
                Fra  = "Horten",
                Til  = "Drammen",
                Dato = "2020-09-12",
                Tid  = "10:00"
            };

            mockRepo.Setup(k => k.Endre(bestilling)).ReturnsAsync(true);

            var bestillingController = new BestillingController(mockRepo.Object, mockLog.Object);

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

            var resultat = await bestillingController.Endre(bestilling) as OkObjectResult;

            Assert.Equal((int)HttpStatusCode.OK, resultat.StatusCode);
            Assert.Equal("Bestillingen ble endret", resultat.Value);
        }
Esempio n. 2
0
        public async Task EndreBestillingIkkeLoggetInn()
        {
            mockRepo.Setup(k => k.Endre(It.IsAny <Bestilling>())).ReturnsAsync(false);

            var bestillingController = new BestillingController(mockRepo.Object, mockLog.Object);

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

            var resultat = await bestillingController.Endre(It.IsAny <Bestilling>()) as UnauthorizedObjectResult;

            Assert.Equal((int)HttpStatusCode.Unauthorized, resultat.StatusCode);
            Assert.Equal("Ikke logget inn", resultat.Value);
        }
Esempio n. 3
0
        public async Task EndreBestillingFeilModel()
        {
            mockRepo.Setup(k => k.Endre(It.IsAny <Bestilling>())).ReturnsAsync(false);

            var bestillingController = new BestillingController(mockRepo.Object, mockLog.Object);

            bestillingController.ModelState.AddModelError("Fra", "Bestillingen mangler felt");

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

            var resultat = await bestillingController.Endre(It.IsAny <Bestilling>()) as BadRequestObjectResult;

            Assert.Equal((int)HttpStatusCode.BadRequest, resultat.StatusCode);
            Assert.Equal("Bestillingen mangler felt", resultat.Value);
        }