Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            Notification = await NotificationRepository.GetNotificationAsync(NotificationId);
            await SetValuesForValidation();

            ModelState.Clear();
            TryValidateModel(TransferRequest, nameof(TransferRequest));
            if (!ModelState.IsValid)
            {
                await SetDropdownsAsync();
                await AuthorizeAndSetBannerAsync();

                return(Page());
            }

            var transferAlert = new TransferAlert
            {
                NotificationId         = NotificationId,
                TransferDate           = TransferRequest.TransferDate,
                TbServiceCode          = TransferRequest.TbServiceCode,
                CaseManagerId          = TransferRequest.CaseManagerId,
                TransferReason         = TransferRequest.TransferReason,
                OtherReasonDescription = TransferRequest.OtherReasonDescription,
                TransferRequestNote    = TransferRequest.TransferRequestNote
            };
            await _alertService.AddUniqueOpenAlertAsync(transferAlert);

            return(RedirectToPage("/Notifications/Overview", new { NotificationId }));
        }
        public async Task IsUserAuthorizedToManageAlert_AllowsUserWithCorrectTbServiceToManageTransferAlert()
        {
            // Arrange
            var testUser  = new ClaimsPrincipal(new ClaimsIdentity("TestDev"));
            var tbService = new TBService()
            {
                Code = "TBS0008"
            };
            var testAlert = new TransferAlert()
            {
                NotificationId = 2, AlertType = AlertType.TransferRequest, TbServiceCode = tbService.Code
            };

            _mockUserHelper.Setup(uh => uh.UserIsReadOnly(It.IsAny <ClaimsPrincipal>())).Returns(false);
            _mockUserService.Setup(us => us.GetTbServicesAsync(It.IsAny <ClaimsPrincipal>()))
            .Returns(Task.FromResult((new List <TBService> {
                tbService
            }).AsEnumerable()));

            // Act
            var result = await _authorizationService.IsUserAuthorizedToManageAlert(testUser, testAlert);

            // Assert
            Assert.True(result);
        }