public void GetAllPatients_ThereIsPatients_ShouldReturnOkAndListOfPatients()
        {
            // Arrange
            _patientServiceMock.Setup(p => p.GetAllPatients()).Returns(_patients);
            _patientsController = new PatientController(_patientServiceMock.Object, _loggerMock.Object);

            // Act
            var response = _patientsController.GetAllPatients();

            var okResult = response as OkObjectResult;

            // Assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);

            var returnedPatientDTOs = okResult.Value as List <PatientDTO>;

            Assert.IsNotNull(returnedPatientDTOs);
            Assert.IsInstanceOf(typeof(List <PatientDTO>), returnedPatientDTOs);
            Assert.AreEqual(returnedPatientDTOs.Any(), true);

            var comparer = new PatientDTOComparer();

            CollectionAssert.AreEqual(returnedPatientDTOs.OrderBy(product => product, comparer),
                                      _patients.OrderBy(product => product, comparer), comparer);

            Assert.AreEqual(2, returnedPatientDTOs.Count);
        }
예제 #2
0
        public void TestFetchAllPatients()
        {
            var Response = _patientcontroller.GetAllPatients();

            Assert.IsNotNull(Response);
            Assert.IsInstanceOfType(Response, typeof(List <Patient>));
        }
        public void GetAllPatients_IfThrowException_ShouldLogAndReturnExceptionMessage()
        {
            // Arrange
            _patientServiceMock.Setup(p => p.GetAllPatients()).Throws <Exception>();
            _patientsController = new PatientController(_patientServiceMock.Object, _loggerMock.Object);

            // Act & Assert
            var ex = Assert.Throws <Exception>(() => _patientsController.GetAllPatients());

            Assert.That(ex.Message, Is.EqualTo("An exception occured."));
        }
예제 #4
0
        public async Task GetAll_WhenCalled_ReturnsAllItems()
        {
            // Arrange
            var patientRepo = new PatientRepositoryFake();
            var controller  = new PatientController(patientRepo, _mockMapper, _mockConverter, null, _logger);

            // Act
            var result = await controller.GetAllPatients();

            // Assert
            Assert.IsType <ActionResult <List <PatientModel> > >(result);
            Assert.Equal(2, result.Value.Count);
        }
        public void GetAllPatients_IfThereIsNoPatients_ShouldReturnNotFoundAndEmptyList()
        {
            // Arrange
            _patients.Clear();
            _patientServiceMock.Setup(p => p.GetAllPatients()).Returns(_patients);
            _patientsController = new PatientController(_patientServiceMock.Object, _loggerMock.Object);

            // Act
            var response = _patientsController.GetAllPatients();

            var notFoundResult = response as NotFoundResult;

            // Assert
            Assert.IsNotNull(notFoundResult);
            Assert.AreEqual(404, notFoundResult.StatusCode);
        }
        public async Task GetAllPatients_Should_Return_List_Of_Patients()
        {
            string testId = "";

            try
            {
                testId = Test.addTest(new testDefinition
                {
                    name        = "Get list of patients",
                    description = "This test should return a list of patients",
                    storyName   = "Patient Retrieve",
                    featureName = "Positive Tests",
                    epicName    = "Unit Tests"
                });

                // Arrange
                Test.addStep(new step {
                    description = "Arrange", name = "Step 1: Arrange"
                });
                this.mockUserRepo.Setup(repo => repo.GetAllPatients()).Returns(this.lpatient);
                PatientController sut = this.sutBuilder.WithRepository(this.mockUserRepo.Object);
                Test.stopStep(Status.passed);

                // Act
                Test.addStep(new step {
                    description = " Get all the patients", name = "Step 2: Act"
                });
                var result = sut.GetAllPatients();
                Test.stopStep(Status.passed);

                // Assert
                Test.addStep(new step {
                    description = "Check if the number the clients returned is correct", name = "Step 3: Assert"
                });
                var viewResult = Assert.IsType <OkObjectResult>(result);
                var model      = Assert.IsAssignableFrom <List <PatientViewModel> >(viewResult.Value);
                Assert.Equal(3, model.Count());
                Test.stopStep(Status.passed);
                Test.stopTest(testId, Status.passed, "Test success", "Passed");
            }
            catch (Exception ex)
            {
                Test.stopStep(Status.failed);
                Test.stopTest(testId, Status.passed, "Test failed", ex.ToString());
                Assert.True(false);
            }
        }
예제 #7
0
        private async Task GetPagedPatient(int page, int totalElements, int elementsPerPage)
        {
            IActionResult        result = null;
            PatientController    sut    = null;
            IQueryable <Patient> list   = GetPatientList(totalElements);

            AllureLifecycle.Instance.WrapInStep(() =>
            {
                // Arrange
                this.mockPatientRepository
                .Setup(repo => repo.GetAllWithPaginationPatients(It.IsAny <int>(), It.IsAny <int>()))
                .ReturnsAsync(
                    new PagedList <Patient>(list, page + 1, elementsPerPage));
                sut = this.sutBuilder.WithRepository(this.mockRepositories.Object);
            }, "Action: Step 1: Arrange");

            await AllureLifecycle.Instance.WrapInStep(async() =>
            {
                // Act
                result = await sut.GetAllPatients(page, 18);
            }, $"Action: Step 2: Act. Get all the patients of page {page}, just {elementsPerPage} items");

            AllureLifecycle.Instance.WrapInStep(() =>
            {
                // Assert
                ExtendedPagedList <PatientViewModel> model =
                    AssertAndGetModel <ExtendedPagedList <PatientViewModel> >(result);
                Assert.AreEqual(elementsPerPage, model.NumberOfElements);
                Assert.AreEqual(page, model.Number);
                Assert.AreEqual(totalElements, model.TotalElements);

                // compare the Ids of the patient and patientVM
                CollectionAssert.AreEqual(
                    list.Skip(page * elementsPerPage).Take(elementsPerPage).Select(p => p.Id).ToArray(),
                    model.Content.Select(p => p.Id).ToArray());
            }, "Step 3: Assert. Check if the number the patients returned is correct");
        }
예제 #8
0
        public async Task GetAllPatients_Paged_Should_Return_List_Of_Patients_After_Last_Page()
        {
            int           totalElements   = 90;
            int           page            = 5;
            int           elementsPerPage = 18;
            IActionResult result          = null;

            IQueryable <Patient> list = GetPatientList(totalElements);
            PatientController    sut  = null;

            AllureLifecycle.Instance.WrapInStep(() =>
            {
                // Arrange
                this.mockPatientRepository
                .Setup(repo => repo.GetAllWithPaginationPatients(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(
                    new PagedList <Patient>(list, page + 1, elementsPerPage));
                sut = this.sutBuilder.WithRepository(this.mockRepositories.Object);
            }, "Action: Create a Patient List");

            await AllureLifecycle.Instance.WrapInStep(async() =>
            {
                // Act
                result = await sut.GetAllPatients(page, 18);
            }, $"Action: Get all the patients of page {page}, just {elementsPerPage} items");

            AllureLifecycle.Instance.WrapInStep(() =>
            {
                ExtendedPagedList <PatientViewModel> model =
                    AssertAndGetModel <ExtendedPagedList <PatientViewModel> >(result);
                Assert.AreEqual(0, model.NumberOfElements);
                Assert.AreEqual(page, model.Number);
                Assert.AreEqual(totalElements, model.TotalElements);

                // the list shall be empty
                Assert.False(model.Content.Any());
            }, "Check if the number the patients returned is correct");
        }
        public async Task GetAllPatients_Paged_Should_Return_List_Of_Patients_After_Last_Page()
        {
            int totalElements   = 90;
            int page            = 5;
            int elementsPerPage = 18;

            string testId             = string.Empty;
            IQueryable <Patient> list = this.GetPatientList(totalElements);

            try
            {
                testId = Test.AddTest(
                    new testDefinition
                {
                    name        = "Get list of patients",
                    description = "This test should return a list of patients",
                    storyName   = "Patient Retrieve",
                    featureName = "Positive Tests",
                    epicName    = "Unit Tests"
                });

                // Arrange
                Test.AddStep(new step {
                    description = "Arrange", name = "Step 1: Arrange"
                });
                this.mockPatientRepository
                .Setup(repo => repo.GetAllWithPaginationPatients(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(
                    new PagedList <Patient>(list, page + 1, elementsPerPage));
                PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object);
                Test.StopStep(Status.passed);

                // Act
                Test.AddStep(
                    new step
                {
                    description = $" Get all the patients of page {page}, just {elementsPerPage} items",
                    name        = "Step 2: Act"
                });
                var result = await sut.GetAllPatients(page, 18);

                Test.StopStep(Status.passed);

                // Assert
                Test.AddStep(
                    new step
                {
                    description = "Check if the number the patients returned is correct",
                    name        = "Step 3: Assert"
                });
                var viewResult = Assert.IsType <OkObjectResult>(result);
                var model      = Assert.IsAssignableFrom <ExtendedPagedList <PatientViewModel> >(viewResult.Value);
                Assert.Equal(0, model.NumberOfElements);
                Assert.Equal(page, model.Number);
                Assert.Equal(totalElements, model.TotalElements);

                // the list shall be empty
                Assert.False(model.Content.Any());
                Test.StopStep(Status.passed);
                Test.StopTest(testId, Status.passed, "Test success", "Passed");
            }
            catch (Exception ex)
            {
                Test.StopStep(Status.failed);
                Test.StopTest(testId, Status.passed, "Test failed", ex.ToString());
                Assert.True(false, ex.ToString());
            }
        }