public void Arrange() { _cancellationToken = new CancellationToken(); _reservationCreated = new Reservation(null, _expectedReservationId, ExpectedAccountId, false, DateTime.UtcNow, DateTime.UtcNow.AddMonths(1), DateTime.UtcNow.AddMonths(3), ReservationStatus.Pending, new Course { CourseId = "1", Level = 1, Title = "Test Course" }, ExpectedProviderId, 198, "TestName", 0, null); _validator = new Mock <IValidator <CreateAccountReservationCommand> >(); _validator.Setup(x => x.ValidateAsync(It.IsAny <CreateAccountReservationCommand>())) .ReturnsAsync(new ValidationResult { ValidationDictionary = new Dictionary <string, string> { { "", "" } } }); _validator.Setup(x => x.ValidateAsync( It.Is <CreateAccountReservationCommand>(c => c.Id.Equals(_expectedReservationId)))) .ReturnsAsync(new ValidationResult()); _globalRulesService = new Mock <IGlobalRulesService>(); _globalRulesService.Setup(x => x.GetActiveRules(It.IsAny <DateTime>())) .ReturnsAsync(new List <GlobalRule>()); _command = new CreateAccountReservationCommand { Id = _expectedReservationId, AccountId = ExpectedAccountId, AccountLegalEntityId = 198, AccountLegalEntityName = "TestName", StartDate = _expectedStartDate, CreatedDate = _expectedExpiryDate, ProviderId = ExpectedProviderId }; _accountReservationsService = new Mock <IAccountReservationService>(); _accountReservationsService .Setup(x => x.CreateAccountReservation(_command)) .ReturnsAsync(_reservationCreated); _accountLegalEntitiesService = new Mock <IAccountLegalEntitiesService>(); _expectedAccountLegalEntity = new AccountLegalEntity(Guid.NewGuid(), _command.AccountId, "Test Name 2", 1, _command.AccountLegalEntityId, true, true); _accountLegalEntitiesService.Setup(x => x.GetAccountLegalEntity(_command.AccountLegalEntityId)) .ReturnsAsync(_expectedAccountLegalEntity); _unitOfWork = new Mock <IUnitOfWorkContext>(); _handler = new CreateAccountReservationCommandHandler(_accountReservationsService.Object, _validator.Object, _globalRulesService.Object, _unitOfWork.Object, _accountLegalEntitiesService.Object); }
public async Task Then_If_The_Request_Is_For_A_NonLevy_Agreement_That_Is_Not_Signed_Then_The_Reservation_Is_Not_Created() { //Arrange _expectedAccountLegalEntity = new AccountLegalEntity(Guid.NewGuid(), _command.AccountId, "Test Name 2", 1, _command.AccountLegalEntityId, false, false); _accountLegalEntitiesService.Setup(x => x.GetAccountLegalEntity(_command.AccountLegalEntityId)) .ReturnsAsync(_expectedAccountLegalEntity); //Act var actual = await _handler.Handle(_command, _cancellationToken); //Assert _accountReservationsService.Verify(x => x.CreateAccountReservation(_command), Times.Never); }