Esempio n. 1
0
        public async Task FindNewReportNumber__Return_OkNegotiatedContentResult_of_Int()
        {
            // Arrange
            IConfirmationReportWorker worker = Substitute.For <IConfirmationReportWorker>();

            worker.FindNewReportNumber().Returns(1);

            var controller = new ConfirmationReportController(worker);

            // Act
            var actual = await controller.FindNewReportNumber();

            // Assert
            Assert.IsAssignableFrom <OkNegotiatedContentResult <int> >(actual);
        }
Esempio n. 2
0
        public async Task FindById__if_report_not_found__Return_NotFound_Status()
        {
            // Arrange
            int model = 1;

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

            worker.FindById(model).Returns(null as ConfirmationReportViewModel);
            var controller = new ConfirmationReportController(worker);

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

            // Assert
            Assert.IsAssignableFrom <NotFoundResult>(actual);
        }
Esempio n. 3
0
        public async Task FindAllByOwner__If_Model_is_invalid__Return_BadRequest()
        {
            // Arrange
            IConfirmationReportWorker worker = Substitute.For <IConfirmationReportWorker>();

            worker.FindAllByOwner(null, null).Returns(new List <ConfirmationReportViewModel>());

            var controller = new ConfirmationReportController(worker);

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

            // Act
            var actual = await controller.FindAllByOwner(null, null);

            // Assert
            Assert.IsAssignableFrom <InvalidModelStateResult>(actual);
        }
Esempio n. 4
0
        public async Task FindById__if_report_found__Return_Ok_Status()
        {
            // Arrange
            int model = 1;

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

            worker.FindById(model).Returns(new ConfirmationReportViewModel {
                Id = 1
            });

            var controller = new ConfirmationReportController(worker);

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

            // Assert
            Assert.IsAssignableFrom <OkNegotiatedContentResult <ConfirmationReportViewModel> >(actual);
        }
Esempio n. 5
0
        public async Task FindById__if_report_found__Return_report_with_same_reportNumber()
        {
            // Arrange
            int model = 1;

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

            worker.FindById(model).Returns(new ConfirmationReportViewModel {
                Id = 1
            });

            var controller = new ConfirmationReportController(worker);

            // Act
            var actual = await controller.FindById(model) as OkNegotiatedContentResult <ConfirmationReportViewModel>;

            // Assert
            Assert.IsNotNull(actual.Content);
            Assert.AreEqual(model, actual.Content.Id);
        }
Esempio n. 6
0
        public async Task FindAllByOwner__If_Owner_has_report__Return_Ok_Status()
        {
            var fakeList = new List <ConfirmationReportViewModel>()
            {
                new ConfirmationReportViewModel {
                    OwnerName = "wilver"
                }
            };
            // Arrange
            IConfirmationReportWorker worker = Substitute.For <IConfirmationReportWorker>();

            worker.FindAllByOwner("wilver", null).Returns(fakeList);

            var controller = new ConfirmationReportController(worker);

            // Act
            var actual = await controller.FindAllByOwner("wilver", null);

            // Assert
            Assert.IsAssignableFrom <OkNegotiatedContentResult <List <ConfirmationReportViewModel> > >(actual);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }