Ejemplo n.º 1
0
 public void Post_Legg_til_prosjekt_Bad_Request()
 {
     var commandBus = new Mock<IProsjektLogikk>();
     commandBus.Setup(c => c.RegistrerProsjekt(It.IsAny<Prosjekt>(), 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", "ProsjektApi" } });
     var controller = new ProsjektApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var pros = new Prosjekt();
     pros.Arbeidsplass = "";
     // The ASP.NET pipeline doesn't run, so validation don't run. 
     controller.ModelState.AddModelError("Arbeidsplass", "mock error message");
     var response = controller.Post(pros);
     // Assert
     Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
 }
Ejemplo n.º 2
0
 public void Post_Registrer_Prosjekt_Ok()
 {
     Prosjekt nyttProsjekt = new Prosjekt()
     {
         Arbeidsplass = "TestShop"   
     };
     var commandBus = new Mock<IProsjektLogikk>();
     commandBus.Setup(c => c.RegistrerProsjekt(It.IsAny<Prosjekt>(), 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", "ProsjektApi" } });
     var controller = new ProsjektApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektApi/")
         {
             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/ProsjektApi/{0}", nyttProsjekt.ProsjektId), response.Headers.Location.ToString());
 }
Ejemplo n.º 3
0
 public void Post_Legg_til_prosjekt_NOT_FOUND()
 {
     var pros = new Prosjekt();
     pros.Arbeidsplass = "";
     var commandBus = new Mock<IProsjektLogikk>();
     commandBus.Setup(c => c.RegistrerProsjekt(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", "ProsjektApi" } });
     var controller = new ProsjektApiController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/ProsjektApi/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
   
     
     var response = controller.Post(pros);
     // Assert
     Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
 }
Ejemplo n.º 4
0
        public void Delete_Prosjekt_NOT_FOUND()
        {
            
            var commandBus = new Mock<IProsjektLogikk>();
            commandBus.Setup(c => c.SlettProsjekt(It.IsAny<string>(), 1)).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "ProsjektApi" } });
            var controller = new ProsjektApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Delete, "http://localhost/api/ProsjektApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };

            // Act
            var response = controller.Delete(0);
            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Ejemplo n.º 5
0
        public void PUT_Endre_Prosjekt_NOT_found()
        {

            var commandBus = new Mock<IProsjektLogikk>();
            Prosjekt test = null;
            commandBus.Setup(c => c.EndreProsjekt(test, 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", "ProsjektApi" } });
            var controller = new ProsjektApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/ProsjektApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            // The ASP.NET pipeline doesn't run, so validation don't run. 
            
            var response = controller.Put(test);
            // Assert
            commandBus.Verify(e => e.EndreProsjekt(test, "brukernavn"), Times.Never);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            // Act

        }
Ejemplo n.º 6
0
        public void PUT_Endre_Prosjekt_Bad_request()
        {

            var commandBus = new Mock<IProsjektLogikk>();
            commandBus.Setup(c => c.EndreProsjekt(It.IsAny<Prosjekt>(), 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", "ProsjektApi" } });
            var controller = new ProsjektApiController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/ProsjektApi/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            Prosjekt eProsj = new Prosjekt();
            eProsj.Arbeidsplass = "";
            // The ASP.NET pipeline doesn't run, so validation don't run. 
            controller.ModelState.AddModelError("start", "mock error message");
            var response = controller.Put(eProsj);
            // Assert
            commandBus.Verify(e => e.EndreProsjekt(eProsj, "brukernavn"), Times.Never);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            // Act

        }