コード例 #1
0
 protected void SetupAuthorize(AuthorizationResult result)
 {
     AuthorizationServiceMock
     .Setup(aus => aus.AuthorizeAsync(
                It.IsAny <ClaimsPrincipal>(),
                It.IsAny <ILocationPath>(),
                It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
     .Returns(Task.FromResult(result));
 }
コード例 #2
0
        public void UpdatePatientDetails_ReturnsForbid_WhenNoPermissionAtNewMEOfficeLocation()
        {
            // Arrange
            AuthorizationServiceMock
            .SetupSequence(aus => aus.AuthorizeAsync(
                               It.IsAny <ClaimsPrincipal>(),
                               It.IsAny <ILocationPath>(),
                               It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
            .Returns(Task.FromResult(AuthorizationResult.Success()))
            .Returns(Task.FromResult(AuthorizationResult.Failed()));
            var expectedExaminationId = "expectedExaminationId";
            var expectedExamination   = new Examination()
            {
                ExaminationId = expectedExaminationId,
            };

            var examinationRetrievalService = new Mock <IAsyncQueryHandler <ExaminationRetrievalQuery, Examination> >();
            var patientDetailsUpdateService = new Mock <IAsyncQueryHandler <PatientDetailsUpdateQuery, Examination> >();

            UsersRetrievalByOktaIdServiceMock
            .Setup(service => service.Handle(It.IsAny <UserRetrievalByOktaIdQuery>()))
            .Returns(Task.FromResult(AuthorizedUser));

            examinationRetrievalService
            .Setup(service => service.Handle(It.IsAny <ExaminationRetrievalQuery>()))
            .Returns(Task.FromResult(expectedExamination));

            patientDetailsUpdateService
            .Setup(pdus => pdus.Handle(It.IsAny <PatientDetailsUpdateQuery>()))
            .Returns(Task.FromResult(expectedExamination));

            Controller = new PatientDetailsController(
                LoggerMock.Object,
                Mapper,
                UsersRetrievalByOktaIdServiceMock.Object,
                AuthorizationServiceMock.Object,
                PermissionServiceMock.Object,
                examinationRetrievalService.Object,
                patientDetailsUpdateService.Object,
                _locationParentsQueryServiceMock.Object);

            Controller.ControllerContext = GetControllerContext();

            var expectedPutPatientDetailsRequest = new PutPatientDetailsRequest();

            // Act
            var response = Controller.UpdatePatientDetails(expectedExaminationId, expectedPutPatientDetailsRequest).Result;

            // Assert
            var taskResult = response.Should().BeOfType <ActionResult <PutPatientDetailsResponse> >().Subject;

            taskResult.Result.Should().BeAssignableTo <ForbidResult>();
        }
コード例 #3
0
        public async Task SiUsuarioNoEsAdmin_Obtenemos2Links()
        {
            // Preparación
            var authorizationService = new AuthorizationServiceMock();

            authorizationService.Resultado = AuthorizationResult.Failed();
            var rootController = new RootController(authorizationService);

            rootController.Url = new URLHelperMock();

            // Ejecución
            var resultado = await rootController.Get();

            // Verificación
            Assert.AreEqual(2, resultado.Value.Count());
        }