Exemple #1
0
        public async Task InformationsPOST_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            var mockService = new Mock <IPatientViewModelService>();

            mockService.Setup(service => service.UpdatePatientWithInformation(GetInformationViewModel().Patient));
            var controller = new InformationsController(mockService.Object);

            controller.ModelState.AddModelError("Name", "Required");
            var newInformationViewModel = GetInformationViewModel();

            var result = await controller.Informations(newInformationViewModel);

            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.IsType <SerializableError>(badRequestResult.Value);
        }
Exemple #2
0
        public async Task InformationsGET_ReturnsViewResultWithInformationViewModel_ShouldShowInformations()
        {
            // Arrange
            int testPatientId = 2;
            var mockService   = new Mock <IPatientViewModelService>();

            mockService.Setup(service => service.GetPatientWithInformation(testPatientId))
            .Returns(Task.FromResult(GetInformationPatientViewModelList().FirstOrDefault(p => p.Id == testPatientId)));
            var controller = new InformationsController(mockService.Object);

            // Act
            var result = await controller.Informations(testPatientId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsType <InformationViewModel>(viewResult.ViewData.Model);
        }
Exemple #3
0
        public async Task InformationsPOST_ReturnsARedirectAndUpdatePatient_WhenModelStateIsValid()
        {
            var mockService = new Mock <IPatientViewModelService>();

            mockService.Setup(service => service.UpdatePatientWithInformation(It.IsAny <InformationPatientViewModel>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var controller = new InformationsController(mockService.Object);

            // Give the controller an HttpContext.
            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            // Request is not null anymore.
            controller.Request.Form = GetRequestFormCollection();
            var informationViewModel = GetInformationViewModel();

            var result = await controller.Informations(informationViewModel);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
            mockService.Verify();
        }