Exemplo n.º 1
0
        public void Post_Bruker_Bad_request()
        {

            var commandBus = new Mock<IBrukerLogikk>();
            commandBus.Setup(c => c.RegistrerBruker(It.IsAny<Registrer>())).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
            var controller = new BrukerApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/BrukerApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            Registrer nyBruker = new Registrer();
            nyBruker.Email = "";
            // 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.RegistrerBruker(nyBruker), Times.Never);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            // Act

        }
Exemplo n.º 2
0
 public void Post_Bruker_Ok()
 {
     Registrer nyBruker = new Registrer()
     {
         Fornavn = "Mats",
         Etternavn = "Lokken",
         Email = "*****@*****.**",
         Telefonnummer = "93686771",
         BekreftPassord = "password"
     };
     var commandBus = new Mock<IBrukerLogikk>();
     commandBus.Setup(c => c.RegistrerBruker(It.IsAny<Registrer>())).Returns(true);
     // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
     var controller = new BrukerApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/BrukerApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Post(nyBruker);
     // Assert
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
     // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result);
     Assert.AreEqual(string.Format("http://localhost/api/BrukerApi/{0}", nyBruker.id), response.Headers.Location.ToString());
 }
Exemplo n.º 3
0
        public void Post_Bruker_NOT_FOUND()
        {
            Registrer nyBruker = new Registrer()
            {
                Fornavn = "Mats",
                Etternavn = "Lokken",
                Email = "*****@*****.**",
                Telefonnummer = "93686771",
                BekreftPassord = "password"
            };

            var commandBus = new Mock<IBrukerLogikk>();
            commandBus.Setup(c => c.RegistrerBruker(nyBruker)).Returns(false);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
            var controller = new BrukerApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/BrukerApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
          
           
            var response = controller.Post(nyBruker);
            // Assert
          
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            
            // Act

        }