public void Arrange() { _commitmentView = new CommitmentView(); _commitmentsApi = new Mock <IEmployerCommitmentApi>(); _commitmentsApi.Setup(x => x.GetEmployerApprenticeship(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(new Apprenticeship()); _commitmentsApi.Setup(x => x.GetEmployerCommitment(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(_commitmentView); _commitmentsApi.Setup(x => x.DeleteEmployerApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <DeleteRequest>())) .Returns(Task.FromResult <object>(null)); _providerEmailNotificationService = new Mock <IProviderEmailNotificationService>(); _providerEmailNotificationService .Setup(x => x.SendProviderTransferRejectedCommitmentEditNotification(It.IsAny <CommitmentView>())) .Returns(() => Task.CompletedTask); _validator = new Mock <IValidator <DeleteApprenticeshipCommand> >(); _validator.Setup(x => x.Validate(It.IsAny <DeleteApprenticeshipCommand>())) .Returns(new ValidationResult()); _handler = new DeleteApprenticeshipCommandHandler(_commitmentsApi.Object, _validator.Object, _providerEmailNotificationService.Object); }
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() { _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 Arrange() { _commitmentsService = new Mock <IEmployerCommitmentApi>(); _commitmentsService.Setup(x => x.DeleteEmployerApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <DeleteRequest>())) .Returns(Task.FromResult <object>(null)); _validator = new Mock <IValidator <DeleteApprenticeshipCommand> >(); _validator.Setup(x => x.Validate(It.IsAny <DeleteApprenticeshipCommand>())) .Returns(new ValidationResult()); _handler = new DeleteApprenticeshipCommandHandler(_commitmentsService.Object, _validator.Object); }
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)); }