Ejemplo n.º 1
0
        public void SectoionControllerRedirectedToCorrectPage()
        {
            var requestDispatcherFactoryMock = new Mock <IRequestDispatcherFactory>();
            var routeNavigationServiceMock   = new Mock <IRouteNavigationService>();

            routeNavigationServiceMock.Setup(i => i.GetInitialRoute(It.IsAny <long?> ()))
            .Returns(new RouteInfo("GeneralInformationSection", 0));
            var patientAccessControlManagerMock = new Mock <IPatientAccessControlManager>();

            var assessmentController = new AssessmentController(requestDispatcherFactoryMock.Object,
                                                                routeNavigationServiceMock.Object,
                                                                patientAccessControlManagerMock.Object);

            var result = assessmentController.Edit(It.IsAny <long>());

            Assert.IsNotNull(result);
            var redirectToRouteResult = result as RedirectToRouteResult;

            Assert.AreEqual(redirectToRouteResult.RouteName, "SectionRoute");

            var routes = new RouteCollection();

            RouteConfig.RegisterRoutes(routes);
            RouteTestHelper.AssertRoute(routes, redirectToRouteResult.RouteValues, new { id = "0", section = "GeneralInformationSection" });
        }
Ejemplo n.º 2
0
        public void CanEditAssessmentExpectJsonResult()
        {
            // Arrange
            const bool canSubmit = true;
            var        asyncRequestDispatcherMock = new Mock <IAsyncRequestDispatcher>();

            asyncRequestDispatcherMock.Setup(rd => rd.GetAsync <SaveAssessmentItemResponse>())
            .Returns(
                Task.FromResult(new SaveAssessmentItemResponse
            {
                CanSubmit = canSubmit
            }));

            var requestDisplatcherFactoryMock = new Mock <IRequestDispatcherFactory>();

            requestDisplatcherFactoryMock.Setup(r => r.CreateRequestDispatcher())
            .Returns(asyncRequestDispatcherMock.Object);

            var controller = new AssessmentController(requestDisplatcherFactoryMock.Object,
                                                      new Mock <IResourcesManager>().Object,
                                                      new Mock <IDbConnectionFactory>().Object);

            ActionResult actionResult = null;
            var          wait         = new ManualResetEvent(false);


            // Act
            var task = controller.Edit(Guid.NewGuid(), Guid.NewGuid(), "123345", "");

            task.ContinueWith(result =>
            {
                actionResult = result.Result;
                wait.Set();
            });
            wait.WaitOne();


            // Assert
            var jsonResult      = actionResult as JsonResult;
            var data            = jsonResult.Data;
            var canSubmitResult = (bool)data.GetType().GetProperty("CanSubmit").GetValue(data, null);

            Assert.AreEqual(canSubmit, canSubmitResult);
        }
Ejemplo n.º 3
0
        public void CanEditAssessment()
        {
            // Arrange
            const string assessmentName          = "Test Assessment";
            var          patientKey              = Guid.NewGuid();
            var          key                     = Guid.NewGuid();
            var          initiatingAssessmentKey = Guid.NewGuid();
            var          workflowMessageDto      = new WorkflowMessageDto()
            {
                InitiatingAssessmentKey = initiatingAssessmentKey,
                Key        = key,
                PatientKey = patientKey,
                RecommendedAssessmentDefinitionKey = Guid.NewGuid()
            };
            var asyncRequestDispatcherMock = new Mock <IAsyncRequestDispatcher>();

            asyncRequestDispatcherMock.Setup(rd => rd.GetAsync <DtoResponse <AssessmentSectionSummaryDto> >())
            .Returns(
                Task.FromResult(new DtoResponse <AssessmentSectionSummaryDto>
            {
                DataTransferObject = new AssessmentSectionSummaryDto
                {
                    Messages =
                        new List <IMessageDto>
                    {
                        workflowMessageDto
                    },
                    AssessmentName = assessmentName
                }
            }));
            asyncRequestDispatcherMock.Setup(rd => rd.GetAsync <GetSectionDtoByKeyResponse>())
            .Returns(
                Task.FromResult(new GetSectionDtoByKeyResponse
            {
                DataTransferObject = new SectionDto()
            }));
            asyncRequestDispatcherMock.Setup(rd => rd.Get <GetPatientDtoResponse>()).Returns(new GetPatientDtoResponse
            {
                DataTransferObject =
                    new PatientDto {
                    Key = patientKey, Gender = new LookupDto()
                    {
                        Code = "Male", Name = "Male"
                    }
                }
            });
            var requestDisplatcherFactoryMock = new Mock <IRequestDispatcherFactory>();

            requestDisplatcherFactoryMock.Setup(r => r.CreateRequestDispatcher())
            .Returns(asyncRequestDispatcherMock.Object);

            var resourcesManager = new Mock <IResourcesManager>();

            resourcesManager.Setup(rm => rm.GetResourceManagerByName(assessmentName))
            .Returns(It.IsAny <ResourceManager>);
            var controller = new AssessmentController(requestDisplatcherFactoryMock.Object,
                                                      resourcesManager.Object,
                                                      new Mock <IDbConnectionFactory>().Object);

            ActionResult acttionResult = null;
            var          wait          = new ManualResetEvent(false);


            // Act
            var task = controller.Edit(key, patientKey);

            task.ContinueWith(result =>
            {
                acttionResult = result.Result;
                wait.Set();
            });
            wait.WaitOne();


            // Assert
            var viewResult          = acttionResult as ViewResult;
            var assessmentViewModel = viewResult.Model as AssessmentViewModel;

            Assert.IsNotNull(assessmentViewModel);
            Assert.AreEqual(assessmentName, assessmentViewModel.AssessmentSectionSummaryDto.AssessmentName);
            var viewData   = viewResult.ViewData;
            var messageDto = (viewData["Messages"] as List <IMessageDto>)[0] as WorkflowMessageDto;

            Assert.AreEqual(initiatingAssessmentKey, messageDto.InitiatingAssessmentKey);
            Assert.AreEqual(patientKey, messageDto.PatientKey);
            Assert.AreEqual("Male", (viewData["Patient"] as PatientDto).Gender.Code);
        }
Ejemplo n.º 4
0
        public void EditGET_GivenAssessmentId_DefaultViewShouldBeReturned()
        {
            var result = _assessmentController.Edit(A <Guid> ._) as ViewResult;

            result.ViewName.Should().BeEmpty();
        }