Esempio n. 1
0
 public void Post_Ta_Ledig_Vakt_Not_Found()
 {
     var commandBus = new Mock<IVaktLogikk>();
     commandBus.Setup(c => c.taLedigVakt(0, 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", "VaktApi3" } });
     var controller = new VaktApi3Controller(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi3/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     int id = 0;
     // The ASP.NET pipeline doesn't run, so validation don't run. 
     var response = controller.Post(id);
     // Assert
     Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
 }
Esempio n. 2
0
        public void Post_Ta_Ledig_Vakt_Ok()
        {

            var commandBus = new Mock<IVaktLogikk>();
            commandBus.Setup(c => c.taLedigVakt(It.IsAny<int>(), 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", "VaktApi3" } });
            var controller = new VaktApi3Controller(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/VaktApi3/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            // Act
            var response = controller.Post(1);
            // Assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            // var newCategory = JsonConvert.DeserializeObject<CategoryModel>(response.Content.ReadAsStringAsync().Result);
            Assert.AreEqual(string.Format("http://localhost/api/VaktApi3/{0}", 1), response.Headers.Location.ToString());
        }