public async Task <IHttpActionResult> SaveDraft(ConfirmationReportViewModel report)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool isNew = report.Id == 0;

            var returnedReport = await worker.SaveDraft(report);

            if (isNew)
            {
                return(Created(new Uri(Url.Link("FindById", new { id = returnedReport.Id })), report));
            }
            else
            {
                return(Ok(report));
            }
        }
示例#2
0
        public async Task SaveDraft__If_Model_is_invalid__Return_BadRequest()
        {
            // Arrange
            var model = new ConfirmationReportViewModel {
                Id = 5
            };

            IConfirmationReportWorker worker = Substitute.For <IConfirmationReportWorker>();

            worker.SaveDraft(model).Returns(new ConfirmationReportViewModel {
                Id = 5
            });

            var controller = new ConfirmationReportController(worker);

            controller.ModelState.AddModelError("fakeError", "fakeError");

            // Act
            var actual = await controller.SaveDraft(model);

            // Assert
            Assert.IsAssignableFrom <InvalidModelStateResult>(actual);
        }
示例#3
0
        public async Task SaveDraft__Report_With_Id_Not_0__Return_Ok_Status()
        {
            // Arrange
            var model = new ConfirmationReportViewModel {
                Id = 5
            };

            IConfirmationReportWorker worker = Substitute.For <IConfirmationReportWorker>();

            worker.SaveDraft(model).Returns(new ConfirmationReportViewModel {
                Id = 5
            });

            var controller = new ConfirmationReportController(worker);

            SubstituteUrlHelper(controller, "http://localhost/api/Reports/id/5");

            // Act
            var actual = await controller.SaveDraft(model);

            // Assert
            Assert.IsAssignableFrom <OkNegotiatedContentResult <ConfirmationReportViewModel> >(actual);
        }