Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
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());
        }