public void Post_Vakt_Bad_request() { var commandBus = new Mock<IVaktLogikk>(); commandBus.Setup(c => c.RegistrerVakt(It.IsAny<Vaktskjema>(), 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", "VaktApi" } }); var controller = new Jobbplan.Controllers.VaktApiController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; Vaktskjema vakter = new Vaktskjema(); vakter.start = ""; vakter.end = ""; // The ASP.NET pipeline doesn't run, so validation don't run. controller.ModelState.AddModelError("start", "mock error message"); var response = controller.Post(vakter); // Assert commandBus.Verify(e => e.RegistrerVakt(vakter, "mats"), Times.Never); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); // Act }
public void Post_Vakt_NOT_FOUND() { Vaktskjema vakter = new Vaktskjema() { start = "22.12.2012", startTid = "16.43", endTid = "18.43", title = "Dagvakt", Beskrivelse = "Opplæring", BrukerId = 1, ProsjektId = 1 }; Vaktskjema vakter1 = new Vaktskjema() { start = "22.12.2012", startTid = "19.43", endTid = "18.43", title = "Dagvakt", Beskrivelse = "Opplæring", BrukerId = 1, ProsjektId = 1 }; var commandBus = new Mock <IVaktLogikk>(); commandBus.Setup(c => c.RegistrerVakt(vakter, 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", "VaktApi" } }); var controller = new Jobbplan.Controllers.VaktApiController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; var response = controller.Post(vakter1); // Assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); // Act }
public void Post_Vakt_Ok() { Vaktskjema vakter = new Vaktskjema() { start = "22.12.2012", startTid = "16.43", endTid = "18.43", title = "Dagvakt", Beskrivelse = "Opplæring", BrukerId = 1, ProsjektId = 1 }; var commandBus = new Mock <IVaktLogikk>(); commandBus.Setup(c => c.RegistrerVakt(It.IsAny <Vaktskjema>(), 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", "VaktApi" } }); var controller = new Jobbplan.Controllers.VaktApiController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.Post(vakter); // Assert Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result); Assert.AreEqual(string.Format("http://localhost/api/VaktApi/{0}", vakter.Vaktid), response.Headers.Location.ToString()); }
public void Post_Vakt_Bad_request() { var commandBus = new Mock <IVaktLogikk>(); commandBus.Setup(c => c.RegistrerVakt(It.IsAny <Vaktskjema>(), 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", "VaktApi" } }); var controller = new Jobbplan.Controllers.VaktApiController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; Vaktskjema vakter = new Vaktskjema(); vakter.start = ""; vakter.end = ""; // The ASP.NET pipeline doesn't run, so validation don't run. controller.ModelState.AddModelError("start", "mock error message"); var response = controller.Post(vakter); // Assert commandBus.Verify(e => e.RegistrerVakt(vakter, "mats"), Times.Never); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); // Act }
public void Post_Vakt_Ok() { Vaktskjema vakter = new Vaktskjema() { start = "22.12.2012", startTid = "16.43", endTid = "18.43", title = "Dagvakt", Beskrivelse = "Opplæring", BrukerId = 1, ProsjektId = 1 }; var commandBus = new Mock<IVaktLogikk>(); commandBus.Setup(c => c.RegistrerVakt(It.IsAny<Vaktskjema>(), 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", "VaktApi" } }); var controller = new Jobbplan.Controllers.VaktApiController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.Post(vakter); // Assert Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result); Assert.AreEqual(string.Format("http://localhost/api/VaktApi/{0}", vakter.Vaktid), response.Headers.Location.ToString()); }
public void Post_Vakt_NOT_FOUND() { Vaktskjema vakter = new Vaktskjema() { start = "22.12.2012", startTid = "16.43", endTid = "18.43", title = "Dagvakt", Beskrivelse = "Opplæring", BrukerId = 1, ProsjektId = 1 }; Vaktskjema vakter1 = new Vaktskjema() { start = "22.12.2012", startTid = "19.43", endTid = "18.43", title = "Dagvakt", Beskrivelse = "Opplæring", BrukerId = 1, ProsjektId = 1 }; var commandBus = new Mock<IVaktLogikk>(); commandBus.Setup(c => c.RegistrerVakt(vakter, 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", "VaktApi" } }); var controller = new Jobbplan.Controllers.VaktApiController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; var response = controller.Post(vakter1); // Assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); // Act }