Exemplo n.º 1
0
        public void Record_appeal_Throws_Exception_If_Already_Recorded_Unless_InProgress(string originalStatus, bool expectThrows)
        {
            var applicationId = Guid.NewGuid();

            var command = new RecordAppealOutcomeCommand
            {
                ApplicationId    = applicationId,
                AppealStatus     = AppealStatus.Successful,
                UserName         = "******",
                UserId           = "testUser",
                InternalComments = "testInternalComments",
                ExternalComments = "testExternalComments"
            };

            var existingAppeal = new Appeal
            {
                Status = originalStatus
            };

            var appealRepository = new Mock <IAppealRepository>();

            appealRepository.Setup(x => x.Update(It.IsAny <Appeal>()));
            appealRepository.Setup(x => x.GetByApplicationId(It.IsAny <Guid>())).ReturnsAsync(() => existingAppeal);

            var repository = new Mock <IApplicationRepository>();

            repository.Setup(x => x.GetApplication(command.ApplicationId)).ReturnsAsync(() => new Domain.Entities.Apply
            {
                ApplicationId = command.ApplicationId, Status = ApplicationStatus.Submitted
            });

            var logger  = new Mock <ILogger <RecordAppealOutcomeHandler> >();
            var handler = new RecordAppealOutcomeHandler(logger.Object, appealRepository.Object, repository.Object, Mock.Of <IAuditService>(), Mock.Of <IUnitOfWork>(), Mock.Of <IApplicationUpdatedEmailService>());

            if (expectThrows)
            {
                Assert.ThrowsAsync <InvalidOperationException>(async() => await handler.Handle(command, new CancellationToken()));
            }
            else
            {
                Assert.DoesNotThrowAsync(async() => await handler.Handle(command, new CancellationToken()));
            }
        }
Exemplo n.º 2
0
        public async Task Record_appeal_InProgress_Is_Recorded_In_Relevant_Properties()
        {
            var command = new RecordAppealOutcomeCommand
            {
                ApplicationId    = Guid.NewGuid(),
                AppealStatus     = AppealStatus.InProgress,
                UserName         = "******",
                UserId           = "testUser",
                InternalComments = "testInternalComments",
                ExternalComments = "testExternalComments"
            };

            var appealRepository = new Mock <IAppealRepository>();

            appealRepository.Setup(x => x.Add(It.IsAny <Appeal>()));
            appealRepository.Setup(x => x.GetByApplicationId(It.IsAny <Guid>())).ReturnsAsync(() => null);

            var repository = new Mock <IApplicationRepository>();

            repository.Setup(x => x.GetApplication(command.ApplicationId)).ReturnsAsync(() => new Domain.Entities.Apply
            {
                ApplicationId = command.ApplicationId, Status = ApplicationStatus.Submitted
            });
            repository.Setup(x => x.Update(It.IsAny <Domain.Entities.Apply>()));

            var logger  = new Mock <ILogger <RecordAppealOutcomeHandler> >();
            var handler = new RecordAppealOutcomeHandler(logger.Object, appealRepository.Object, repository.Object, Mock.Of <IAuditService>(), Mock.Of <IUnitOfWork>(), Mock.Of <IApplicationUpdatedEmailService>());

            var result = await handler.Handle(command, new CancellationToken());

            result.Should().BeTrue();

            appealRepository.Verify(
                x => x.Add(It.Is <Appeal>(
                               r => r.ApplicationId == command.ApplicationId &&
                               r.InProgressDate.Value.Date == DateTime.UtcNow.Date &&
                               r.AppealDeterminedDate == null &&
                               r.InProgressUserId == command.UserId &&
                               r.InProgressUserName == command.UserName &&
                               r.InProgressInternalComments == command.InternalComments &&
                               r.InProgressExternalComments == command.ExternalComments &&
                               r.InternalComments == null &&
                               r.ExternalComments == null &&
                               r.Status == AppealStatus.InProgress
                               )),
                Times.Once);

            repository.Verify(x => x.Update(It.Is <Domain.Entities.Apply>(apply =>
                                                                          apply.ApplicationId == command.ApplicationId && apply.ApplicationStatus == ApplicationStatus.InProgressAppeal)),
                              Times.Once);
        }
Exemplo n.º 3
0
        public async Task Record_appeal_outcome_updates_appeal_status_and_applies_correct_application_status(string appealStatus, string applicationStatus, string gatewayReviewStatus, int noOfCallsToApply)
        {
            var command = new RecordAppealOutcomeCommand
            {
                ApplicationId    = Guid.NewGuid(),
                AppealStatus     = appealStatus,
                UserName         = "******",
                UserId           = "testUser",
                InternalComments = "testInternalComments",
                ExternalComments = "testExternalComments"
            };

            var appealRepository = new Mock <IAppealRepository>();

            appealRepository.Setup(x => x.Add(It.IsAny <Appeal>()));
            appealRepository.Setup(x => x.GetByApplicationId(It.IsAny <Guid>())).ReturnsAsync(() => null);

            var repository = new Mock <IApplicationRepository>();

            repository.Setup(x => x.GetApplication(command.ApplicationId)).ReturnsAsync(() => new Domain.Entities.Apply
            {
                ApplicationId = command.ApplicationId, Status = ApplicationStatus.Submitted, GatewayReviewStatus = gatewayReviewStatus
            });
            repository.Setup(x => x.Update(It.IsAny <Domain.Entities.Apply>()));

            var logger  = new Mock <ILogger <RecordAppealOutcomeHandler> >();
            var handler = new RecordAppealOutcomeHandler(logger.Object, appealRepository.Object, repository.Object, Mock.Of <IAuditService>(), Mock.Of <IUnitOfWork>(), Mock.Of <IApplicationUpdatedEmailService>());

            var result = await handler.Handle(command, new CancellationToken());

            result.Should().BeTrue();

            appealRepository.Verify(
                x => x.Add(It.Is <Appeal>(
                               r => r.ApplicationId == command.ApplicationId &&
                               r.AppealDeterminedDate.Value.Date == DateTime.UtcNow.Date &&
                               r.InternalComments == command.InternalComments &&
                               r.ExternalComments == command.ExternalComments &&
                               r.Status == command.AppealStatus
                               )),
                Times.Once);

            repository.Verify(x => x.Update(It.Is <Domain.Entities.Apply>(apply =>
                                                                          apply.ApplicationId == command.ApplicationId && apply.ApplicationStatus == applicationStatus)),
                              Times.Exactly(noOfCallsToApply));
        }
Exemplo n.º 4
0
        public async Task Handle_User_Is_Notified_Of_Update_To_Applicant()
        {
            var request = new RecordAppealOutcomeCommand
            {
                ApplicationId    = _applicationId,
                UserId           = "test user id",
                UserName         = "******",
                AppealStatus     = AppealStatus.Successful,
                ExternalComments = "External Commnets",
                InternalComments = "Internal Comments",
            };

            _handler = new RecordAppealOutcomeHandler(_logger.Object, _appealRepository.Object, _applicationRepository.Object, _auditService.Object, _unitOfWork.Object, _applicationUpdatedEmailService.Object);

            await _handler.Handle(request, CancellationToken.None);

            _applicationUpdatedEmailService.Verify(x => x.SendEmail(request.ApplicationId), Times.Once);
        }