public void Post_Should_save_supported_child_steps() { // Assemble var instance = new FlowTemplateDto { Name = "Example Step", Steps = new List <FlowTemplateStepDto> { new FlowTemplateStepDto { StepTypeName = "StartStep" }, new FlowTemplateStepDto { StepTypeName = "StopStep" } } }; var controller = new FlowTemplatesController(_flowTemplateService); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/FlowTemplates"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "FlowTemplates" } }); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); // Assert controller.Post(instance); A.CallTo(() => _flowTemplateService.Add(A <FlowTemplate> ._)).MustHaveHappened(Repeated.Exactly.Once); }
public void Put_should_return_validation_messages_if_validation_exception_thrown() { // Assemble A.CallTo(() => _flowTemplateService.Update(A <FlowTemplate> ._)).Throws(new ValidationException("Validation Message")); // Act var controller = new FlowTemplatesController(_flowTemplateService); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/FlowTemplates"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "FlowTemplates" } }); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); // act var response = controller.Put(new FlowTemplateDto { Id = 1, Name = "NonExistant" }); // Assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); var content = (ObjectContent)response.Content; var value = content.Value; Assert.Equal("Message", ((HttpError)value).First().Key); Assert.Contains("Validation", ((HttpError)value).First().Value.ToString()); }
public void Post_success_should_return_new_id() { // Assemble A.CallTo(() => _flowTemplateService.Add(A <FlowTemplate> ._)).Returns(3); var controller = new FlowTemplatesController(_flowTemplateService); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/FlowTemplates"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "FlowTemplates" } }); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); // Act var postResult = controller.Post(new FlowTemplateDto { Id = 1, Name = "Test 1" }); var readAsAsyncTask = postResult.Content.ReadAsAsync <ExpandoObject>(); Task.WaitAll(readAsAsyncTask); dynamic result = readAsAsyncTask.Result; // Assert Assert.Equal(HttpStatusCode.Created, postResult.StatusCode); Assert.Equal(3, result.Id); }
public void Delete_should_request_item_to_be_deleted_from_repository() { A.CallTo(() => _flowTemplateService.GetFlowTemplate(A <int> ._)).Returns(new FlowTemplate { Id = 1, Name = "Example" }); A.CallTo(() => _flowTemplateService.GetFlowTemplateSteps(A <int> ._)).Returns(new List <FlowTemplateStep> { new FlowTemplateStep { Id = 10, FlowTemplateId = 1 }, new FlowTemplateStep { Id = 20, FlowTemplateId = 1 }, new FlowTemplateStep { Id = 30, FlowTemplateId = 1 } }); // Act var controller = new FlowTemplatesController(_flowTemplateService); controller.Delete(1); // Assert A.CallTo(() => _flowTemplateService.Delete(A <FlowTemplate> ._)).MustHaveHappened(Repeated.Exactly.Once); }
public void Put_existing_template_step_should_update_template_step() { var controller = new FlowTemplatesController(_flowTemplateService); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/FlowTemplates"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "FlowTemplates" } }); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); controller.Put(new FlowTemplateDto { Id = 1, Name = "Example Template Step", Steps = new List <FlowTemplateStepDto> { new FlowTemplateStepDto { Id = 10, Name = "Updated Step", StepTypeName = "StartStep" } } }); A.CallTo(() => _flowTemplateService.Update(A <FlowTemplate> ._)).MustHaveHappened(); }
public FlowTemplateControllerTests() { Library.Configuration.AutoMapperConfig.Configure(); AutoMapperConfig.Configure(); _flowTemplateService = A.Fake <IFlowTemplateService>(); _sut = new FlowTemplatesController(_flowTemplateService); }
public void Delete_should_return_not_found_if_not_exists() { // Assemble A.CallTo(() => _flowTemplateService.GetFlowTemplate(A <int> ._)).Returns(null); // Act var controller = new FlowTemplatesController(_flowTemplateService); // Assert Assert.Throws <HttpResponseException>(() => controller.Delete(100)); }
public void Successful_delete_should_return_200() { A.CallTo(() => _flowTemplateService.GetFlowTemplate(A <int> ._)).Returns(new FlowTemplate { Id = 1, Name = "Example" }); // Act var controller = new FlowTemplatesController(_flowTemplateService); var result = controller.Delete(1); // Assert Assert.Equal(200, result.StatusCode); }
public void Post_should_add_template() { var controller = new FlowTemplatesController(_flowTemplateService); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/FlowTemplates"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "FlowTemplates" } }); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); controller.Post(new FlowTemplateDto { Id = 1, Name = "Test 1" }); A.CallTo(() => _flowTemplateService.Add(A <FlowTemplate> ._)).MustHaveHappened(Repeated.Exactly.Once); }
public void Post_should_store_StoreDataStep_type() { // assemble FlowTemplate captured = null; A.CallTo(() => _flowTemplateService.Add(A <FlowTemplate> ._)) .Invokes((FlowTemplate item) => captured = item); var instance = new FlowTemplateDto { Name = "Example Step", Steps = new List <FlowTemplateStepDto> { new FlowTemplateStepDto { StepTypeName = "StoreDataStep" }, } }; var controller = new FlowTemplatesController(_flowTemplateService); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/FlowTemplates"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "FlowTemplates" } }); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); // act controller.Post(instance); // assert A.CallTo(() => _flowTemplateService.Add(A <FlowTemplate> ._)).MustHaveHappened(Repeated.Exactly.Once); Assert.IsType <StoreDataStep>(captured.Steps[0]); }