public async Task ThenIfTheCohortWasRejectedByTransferSenderThenNotifyProviderOfEdit() { //Arrange var command = new DeleteApprenticeshipCommand { AccountId = 1, ApprenticeshipId = 2, UserId = "ABC123", UserDisplayName = "Bob", UserEmailAddress = "*****@*****.**" }; _commitmentView.TransferSender = new TransferSender { TransferApprovalStatus = TransferApprovalStatus.Rejected }; //Act await _handler.Handle(command); //Assert _providerEmailNotificationService.Verify(x => x.SendProviderTransferRejectedCommitmentEditNotification( It.Is <CommitmentView>(c => c == _commitmentView)), Times.Once); }
public async Task ShouldCallMediatorToDelete() { DeleteApprenticeshipCommand arg = null; _mockMediator.Setup(x => x.Send(It.IsAny <DeleteApprenticeshipCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new Unit()) .Callback <DeleteApprenticeshipCommand, CancellationToken>((command, token) => arg = command); _mockMediator.Setup(x => x.Send(It.IsAny <GetApprenticeshipQueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetApprenticeshipQueryResponse { Apprenticeship = new Apprenticeship() }); var signInUser = new SignInUserModel { DisplayName = "Bob", Email = "*****@*****.**" }; await _orchestrator.DeleteApprenticeship("user123", new Web.Models.DeleteConfirmationViewModel { ProviderId = 123L, HashedCommitmentId = "ABBA99", HashedApprenticeshipId = "ABBA66" }, signInUser); _mockMediator.Verify(x => x.Send(It.IsAny <DeleteApprenticeshipCommand>(), It.IsAny <CancellationToken>()), Times.Once); arg.ProviderId.Should().Be(123); arg.ApprenticeshipId.Should().Be(321); arg.UserDisplayName.Should().Be(signInUser.DisplayName); arg.UserEmailAddress.Should().Be(signInUser.Email); }
public void Setup() { _mockCommitmentRepository = new Mock <ICommitmentRepository>(); _mockApprenticeshipRepository = new Mock <IApprenticeshipRepository>(); _mockApprenticeshipEvents = new Mock <IApprenticeshipEvents>(); _mockHistoryRepository = new Mock <IHistoryRepository>(); _mockV2EventsPublisher = new Mock <IV2EventsPublisher>(); _mockHistoryRepository.Setup(x => x.InsertHistory(It.IsAny <IEnumerable <HistoryItem> >())) .Callback((object o) => { _historyResult = o as IEnumerable <HistoryItem>; }) .Returns(() => Task.CompletedTask); _mockV2EventsPublisher.Setup(x => x.PublishApprenticeshipDeleted(It.IsAny <Commitment>(), It.IsAny <Apprenticeship>())) .Returns(() => Task.CompletedTask); _validator = new DeleteApprenticeshipValidator(); _handler = new DeleteApprenticeshipCommandHandler(_mockCommitmentRepository.Object, _mockApprenticeshipRepository.Object, _validator, Mock.Of <ICommitmentsLogger>(), _mockApprenticeshipEvents.Object, _mockHistoryRepository.Object, _mockV2EventsPublisher.Object); _validCommand = new DeleteApprenticeshipCommand { ApprenticeshipId = 2, Caller = new Domain.Caller { Id = 123, CallerType = Domain.CallerType.Provider }, UserName = "******", UserId = "User" }; _apprenticeship = new Apprenticeship { PaymentStatus = PaymentStatus.PendingApproval, ProviderId = 123, EmployerAccountId = 123 }; _mockApprenticeshipRepository.Setup(r => r.GetApprenticeship(It.IsAny <long>())).ReturnsAsync(_apprenticeship); }
public void Setup() { _validCommand = new DeleteApprenticeshipCommand { ProviderId = 111L, ApprenticeshipId = 123L }; _handler = new DeleteApprenticeshipCommandHandler(new DeleteApprenticeshipCommandValidator(), Mock.Of <IProviderCommitmentsApi>()); }
public void Setup() { _validator = new DeleteApprenticeshipValidator(); _handler = new DeleteApprenticeshipCommandHandler(Mock.Of <ICommitmentRepository>(), Mock.Of <IApprenticeshipRepository>(), _validator, Mock.Of <ICommitmentsLogger>(), Mock.Of <IApprenticeshipEvents>(), Mock.Of <IHistoryRepository>()); _validCommand = new DeleteApprenticeshipCommand() { ApprenticeshipId = 2, Caller = new Domain.Caller { Id = 123, CallerType = Domain.CallerType.Provider } }; }
public void Setup() { _validCommand = new DeleteApprenticeshipCommand { UserId = "user123", ProviderId = 111L, ApprenticeshipId = 123L, UserDisplayName = "Bob", UserEmailAddress = "*****@*****.**" }; _mockCommitmentsApi = new Mock <IProviderCommitmentsApi>(); _handler = new DeleteApprenticeshipCommandHandler(new DeleteApprenticeshipCommandValidator(), _mockCommitmentsApi.Object); }
public void ThenApprenticeshipIdMustBeGreaterThanZero() { //Arrange var command = new DeleteApprenticeshipCommand { AccountId = 1, ApprenticeshipId = 0 }; //Act var actual = _validator.Validate(command); //Assert Assert.IsFalse(actual.IsValid()); }
public void ThenTheRequestIsValidIfAllRequiredPropertiesAreProvided() { //Arrange var command = new DeleteApprenticeshipCommand { AccountId = 1, ApprenticeshipId = 1, UserId = "externalUserId" }; //Act var actual = _validator.Validate(command); //Assert Assert.IsTrue(actual.IsValid()); }
public void Setup() { _mockCommitmentRepository = new Mock <ICommitmentRepository>(); _mockApprenticeshipRepository = new Mock <IApprenticeshipRepository>(); _mockApprenticeshipEvents = new Mock <IApprenticeshipEvents>(); _mockHistoryRepository = new Mock <IHistoryRepository>(); _validator = new DeleteApprenticeshipValidator(); _handler = new DeleteApprenticeshipCommandHandler(_mockCommitmentRepository.Object, _mockApprenticeshipRepository.Object, _validator, Mock.Of <ICommitmentsLogger>(), _mockApprenticeshipEvents.Object, _mockHistoryRepository.Object); _validCommand = new DeleteApprenticeshipCommand { ApprenticeshipId = 2, Caller = new Domain.Caller { Id = 123, CallerType = Domain.CallerType.Provider }, UserName = "******", UserId = "User" }; _apprenticeship = new Apprenticeship { PaymentStatus = PaymentStatus.PendingApproval, ProviderId = 123, EmployerAccountId = 123 }; _mockApprenticeshipRepository.Setup(r => r.GetApprenticeship(It.IsAny <long>())).ReturnsAsync(_apprenticeship); }
public void ThenIShouldGetAInvalidRequestExceptionIfValidationFails() { //Arrange var command = new DeleteApprenticeshipCommand(); _validator = new Mock <IValidator <DeleteApprenticeshipCommand> >(); _validator.Setup(x => x.Validate(It.IsAny <DeleteApprenticeshipCommand>())) .Returns(new ValidationResult { ValidationDictionary = new Dictionary <string, string> { { "test", "test validation error" } } }); _handler = new DeleteApprenticeshipCommandHandler(_commitmentsService.Object, _validator.Object); //Act + Assert Assert.ThrowsAsync <InvalidRequestException>(async() => await _handler.Handle(command)); }
public async Task TheCommitmentsServiceShouldBeCalledIfTheRequestIsValid() { //Arrange var command = new DeleteApprenticeshipCommand { AccountId = 1, ApprenticeshipId = 2, UserId = "ABC123", UserDisplayName = "Bob", UserEmailAddress = "*****@*****.**" }; //Act await _handler.Handle(command); //Assert _commitmentsService.Verify( x => x.DeleteEmployerApprenticeship(command.AccountId, command.ApprenticeshipId, It.Is <DeleteRequest>(r => r.UserId == command.UserId && r.LastUpdatedByInfo.Name == command.UserDisplayName && r.LastUpdatedByInfo.EmailAddress == command.UserEmailAddress)), Times.Once); }