예제 #1
0
        public void PUT_Bruker_Bad_request()
        {

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

        }
예제 #2
0
 public void PUT_Bruker_Not_Found()
 {
     Profil nyBruker = new Profil();
     var commandBus = new Mock<IBrukerLogikk>();
     commandBus.Setup(c => c.EndreBrukerInfo(nyBruker, It.IsAny<string>())).Returns(false);
     // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "Profil" } });
     var controller = new ProfilController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/Profil/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Put(nyBruker);
     // Assert
     Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
     // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result);
 }