Esempio n. 1
0
        public void LoggInn_Feil_Validering()
        {
            //Arrange
            var controller = new AuthenticateController();
            var innBruker = new LogInn();
            controller.ModelState.AddModelError("Brukernavn", "Brukernavn må oppgis");
            //Act
            var result = controller.Post(innBruker);
            //Assert

            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
Esempio n. 2
0
        public void Post_Logginn_NOT_Found_I_DB()
        {
            LogInn bruker = new LogInn();
            bruker.Brukernavn = "*****@*****.**";
            bruker.Passord = "passord123";

            var commandBus = new Mock<IBrukerLogikk>();
            commandBus.Setup(c => c.BrukerIdb(bruker)).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "Authenticate" } });
            var controller = new AuthenticateController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Authenticate/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            LogInn nyBruker = new LogInn();
            nyBruker.Brukernavn = "*****@*****.**";
            nyBruker.Passord = "yolo1231";
            var response = controller.Post(nyBruker);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            // Act

        }
Esempio n. 3
0
        public void Post_Logginn_Not_Found()
        {

            var commandBus = new Mock<IBrukerLogikk>();
            commandBus.Setup(c => c.BrukerIdb(It.IsAny<LogInn>())).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "Authenticate" } });
            var controller = new AuthenticateController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Authenticate/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            LogInn nyBruker = new LogInn();
            nyBruker.Brukernavn = "";
            // The ASP.NET pipeline doesn't run, so validation don't run. 
            controller.ModelState.AddModelError("Email", "mock error message");
            var response = controller.Post(nyBruker);
            // Assert
            commandBus.Verify(e => e.BrukerIdb(nyBruker), Times.Never);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            // Act

        }
Esempio n. 4
0
 public void Post_Logginn_Ok()
 {
     LogInn nyBruker = new LogInn()
     { 
         Brukernavn = "*****@*****.**",
         Passord = "password"
     };
     var commandBus = new Mock<IBrukerLogikk>();
     commandBus.Setup(c => c.BrukerIdb(It.IsAny<LogInn>())).Returns(true);
     
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "Authenticate" } });
     var controller = new AuthenticateController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Authenticate/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Post(nyBruker);
     // Assert
     Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
   
    // Assert.AreEqual(string.Format("http://localhost/api/Authenticate/", nyBruker.Brukernavn), response.Headers.Location.ToString());
 }