public void FlowTemplateStep_Post_should_return_bad_request_if_service_throws_validation_error()
        {
            // Assemble
            var unitOfWork = A.Fake <IUnitOfWork>();

            A.CallTo(() => unitOfWork.FlowTemplateSteps.Add(A <IFlowTemplateStep> ._))
            .Throws(new ValidationException("Example Validation Message"));

            var sut = new FlowTemplateStepsController(unitOfWork);

            SetupController(sut, "http://example.com/api/FlowTemplates/1/Steps", HttpMethod.Post);

            // Act
            var instance = new FlowTemplateStepDto {
                StepTypeName = "StartStep"
            };
            var response = sut.Post(3, instance);

            var task = response.Content.ReadAsAsync <ExpandoObject>();

            task.Wait();
            dynamic result = task.Result;

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.Equal("Example Validation Message", result.BrokenRules[0]);
            Assert.Equal(1, result.BrokenRules.Count);
        }
        public void FlowTemplateService_Post_should_add_StartStep_values()
        {
            var unitOfWork = A.Fake <IUnitOfWork>();

            A.CallTo(() => unitOfWork.FlowTemplateSteps.Get()).Returns(new List <IFlowTemplateStep>
            {
                new FlowTemplateStep {
                    Id = 10
                }
            });
            var sut = new FlowTemplateStepsController(unitOfWork);
            IFlowTemplateStep captured = null;

            A.CallTo(() => unitOfWork.FlowTemplateSteps.Add(A <IFlowTemplateStep> ._))
            .Invokes((IFlowTemplateStep item) => captured = item);
            SetupController(sut, "http://example.com/api/FlowTemplates/1/Steps", HttpMethod.Post);

            // Act
            var instance = new FlowTemplateStepDto {
                Name = "New StartStep", StepTypeName = "StartStep"
            };
            var response = sut.Post(3, instance);

            var task = response.Content.ReadAsAsync <ExpandoObject>();

            task.Wait();
            dynamic result = task.Result;

            A.CallTo(() => unitOfWork.FlowTemplateSteps.Get()).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => unitOfWork.FlowTemplateSteps.Add(A <IFlowTemplateStep> ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => unitOfWork.Commit()).MustHaveHappened(Repeated.Exactly.Once);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(11, result.Id);
            Assert.Equal(captured.Id, result.Id);
            Assert.Equal(3, captured.FlowTemplateId);
            Assert.Equal(1, captured.StepTypeId);
            Assert.Equal("New StartStep", captured.Name);
        }