public void Post_Registrer_ProsjektDeltakelse_Bad_Request()
 {
     var commandBus = new Mock<IProsjektLogikk>();
     commandBus.Setup(c => c.RegistrerProsjektdeltakelse(It.IsAny<ProsjektrequestMelding>(), 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", "ProsjektDeltakelseApi" } });
     var controller = new ProsjektDeltakelseApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektDeltakelseApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var pros = new ProsjektrequestMelding();
     pros.MeldingId = 0;
     // The ASP.NET pipeline doesn't run, so validation don't run. 
     controller.ModelState.AddModelError("MeldingId", "mock error message");
     var response = controller.Post(pros);
     // Assert
     Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
 }
        public void Post_Registrer_ProsjektDeltakelse_NOT_FOUND()
        {
            var pros = new ProsjektrequestMelding();
            pros.MeldingId = 0;
            var commandBus = new Mock<IProsjektLogikk>();
            commandBus.Setup(c => c.RegistrerProsjektdeltakelse(pros, "test")).Returns(false);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "ProsjektDeltakelseApi" } });
            var controller = new ProsjektDeltakelseApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektDeltakelseApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            // Act


            var response = controller.Post(pros);
            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
 public void Post_Registrer_ProsjektDeltakelse_Ok()
 {
     ProsjektrequestMelding nyttProsjekt = new ProsjektrequestMelding()
     {
         MeldingId = 1
     };
     var commandBus = new Mock<IProsjektLogikk>();
     commandBus.Setup(c => c.RegistrerProsjektdeltakelse(It.IsAny<ProsjektrequestMelding>(), 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", "ProsjektDeltakelseApi" } });
     var controller = new ProsjektDeltakelseApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektDeltakelseApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Post(nyttProsjekt);
     // Assert
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
     // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result);
     Assert.AreEqual(string.Format("http://localhost/api/ProsjektDeltakelseApi"), response.Headers.Location.ToString());
 }