public void Arrange() { _cacheService = new Mock <ICacheStorageService>(); _authorisationService = new Mock <IReservationAuthorisationService>(); _reservation = new CachedReservation(); _repository = new CachedReservationRepository(_cacheService.Object, _authorisationService.Object); }
public void Arrange() { var fixture = new Fixture() .Customize(new AutoMoqCustomization { ConfigureMembers = true }); _expectedCourse = fixture.Freeze <Course>(); _mockValidator = fixture.Freeze <Mock <IValidator <CacheReservationCourseCommand> > >(); _mockValidator .Setup(validator => validator.ValidateAsync(It.IsAny <CacheReservationCourseCommand>())) .ReturnsAsync(new ValidationResult()); _cachedReservation = fixture.Freeze <CachedReservation>(); _mockCacheStorageService = new Mock <ICacheStorageService>(); _mockCacheRepository = fixture.Freeze <Mock <ICachedReservationRespository> >(); _mockCacheRepository.Setup(s => s.GetProviderReservation(It.IsAny <Guid>(), It.IsAny <uint>())) .ReturnsAsync(_cachedReservation); _mockCourseService = fixture.Freeze <Mock <ICourseService> >(); _mockCourseService.Setup(cs => cs.GetCourse(It.IsAny <string>())) .ReturnsAsync(_expectedCourse); _commandHandler = new CacheReservationCourseCommandHandler( _mockValidator.Object, _mockCacheStorageService.Object, _mockCacheRepository.Object, _mockCourseService.Object); }
public void Arrange() { _expectedUserId = Guid.NewGuid(); var fixture = new Fixture() .Customize(new AutoMoqCustomization { ConfigureMembers = true }); _cachedReservation = fixture.Create <CachedReservation>(); _expectedStartDate = fixture.Create <DateTime>().Date; _cachedReservation.TrainingDate = new TrainingDateModel { StartDate = _expectedStartDate }; _cachedReservation.AccountId = _expectedAccountId; _cachedReservation.AccountLegalEntityName = _expectedLegalEntityName; _cachedReservation.IsEmptyCohortFromSelect = false; _apiResponse = fixture.Create <CreateReservationResponse>(); _mockCreateCommandValidator = fixture.Freeze <Mock <IValidator <CreateReservationCommand> > >(); _mockCreateCommandValidator .Setup(validator => validator.ValidateAsync(It.IsAny <CreateReservationCommand>())) .ReturnsAsync(new ValidationResult()); _mockCachedReservationValidator = fixture.Freeze <Mock <IValidator <CachedReservation> > >(); _mockCachedReservationValidator .Setup(validator => validator.ValidateAsync(It.IsAny <CachedReservation>())) .ReturnsAsync(new ValidationResult()); _options = fixture.Freeze <IOptions <ReservationsApiConfiguration> >(); _mockApiClient = fixture.Freeze <Mock <IApiClient> >(); _mockApiClient .Setup(client => client.Create <CreateReservationResponse>(It.IsAny <ReservationApiRequest>())) .ReturnsAsync(_apiResponse); _mockCacheService = fixture.Freeze <Mock <ICacheStorageService> >(); _mockCacheRepository = fixture.Freeze <Mock <ICachedReservationRespository> >(); _mockCacheRepository.Setup(r => r.GetProviderReservation(It.IsAny <Guid>(), It.IsAny <uint>())) .ReturnsAsync(_cachedReservation); _commandHandler = new CreateReservationCommandHandler( _mockCreateCommandValidator.Object, _mockCachedReservationValidator.Object, _options, _mockApiClient.Object, _mockCacheService.Object, _mockCacheRepository.Object); }
public async Task And_Start_Date_Not_Set_Then_Returns_Error( CachedReservationValidator validator) { var cachedReservation = new CachedReservation { AccountId = 1, TrainingDate = new TrainingDateModel(), AccountLegalEntityName = "Test Name" }; var result = await validator.ValidateAsync(cachedReservation); result.IsValid().Should().BeFalse(); result.ValidationDictionary.Count.Should().Be(1); result.ValidationDictionary.ContainsKey(nameof(CachedReservation.TrainingDate)); }
public async Task <Unit> Handle(CacheReservationEmployerCommand command, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(command); if (!validationResult.IsValid()) { throw new ValidationException(validationResult.ConvertToDataAnnotationsValidationResult(), null, null); } if (validationResult.FailedRuleValidation) { throw new ReservationLimitReachedException(command.AccountId); } if (validationResult.FailedAuthorisationValidation) { throw new ProviderNotAuthorisedException(command.AccountId, command.UkPrn.Value); } if (validationResult.FailedGlobalRuleValidation) { throw new GlobalReservationRuleException(command.AccountId); } if (validationResult.FailedEoiCheck) { throw new NonEoiUserAccessDeniedException(command.AccountId); } var reservation = new CachedReservation { Id = command.Id, AccountId = command.AccountId, AccountLegalEntityId = command.AccountLegalEntityId, AccountLegalEntityPublicHashedId = command.AccountLegalEntityPublicHashedId, AccountLegalEntityName = command.AccountLegalEntityName, AccountName = command.AccountName, CohortRef = command.CohortRef, UkPrn = command.UkPrn, EmployerHasSingleLegalEntity = command.EmployerHasSingleLegalEntity, IsEmptyCohortFromSelect = command.IsEmptyCohortFromSelect }; await _cacheStorageService.SaveToCache(reservation.Id.ToString(), reservation, 1); return(Unit.Value); }
public async Task And_All_Fields_Valid_Then_Valid( CachedReservationValidator validator) { var cachedReservation = new CachedReservation { AccountId = 1, TrainingDate = new TrainingDateModel() { StartDate = DateTime.Now }, AccountLegalEntityName = "Test Name" }; var result = await validator.ValidateAsync(cachedReservation); result.IsValid().Should().BeTrue(); result.ValidationDictionary.Count.Should().Be(0); }
public async Task And_All_Fields_Invalid_Then_Returns_All_Errors( CachedReservationValidator validator) { var cachedReservation = new CachedReservation { AccountId = 0, TrainingDate = null, AccountLegalEntityName = "" }; var result = await validator.ValidateAsync(cachedReservation); result.IsValid().Should().BeFalse(); result.ValidationDictionary.Count.Should().Be(3); result.ValidationDictionary .Should().ContainKey(nameof(CachedReservation.AccountId)) .And.ContainKey(nameof(CachedReservation.TrainingDate)) .And.ContainKey(nameof(CachedReservation.AccountLegalEntityName)); }
public void Arrange() { var fixture = new Fixture() .Customize(new AutoMoqCustomization { ConfigureMembers = true }); _reservation = fixture.Create <CachedReservation>(); _employer = fixture.Create <Employer>(); _providerPermissionService = new Mock <IProviderPermissionsService>(); _service = new ReservationAuthorisationService(_providerPermissionService.Object); _reservation.AccountLegalEntityId = _employer.AccountLegalEntityId; _providerPermissionService.Setup(s => s.GetTrustedEmployers(It.IsAny <uint>())) .ReturnsAsync(new List <Employer> { _employer }); }
public bool ProviderReservationAccessAllowed(uint ukPrn, CachedReservation reservation) { if (reservation == null) { throw new ArgumentException("CachedReservation is null", nameof(reservation)); } if (reservation.UkPrn == default(uint)) { throw new ArgumentException("CachedReservation UkPrn is null", nameof(reservation)); } if (ukPrn == default(uint)) { throw new ArgumentException("ukPrn is not set", nameof(ukPrn)); } return(ukPrn == reservation.UkPrn); }
public void Arrange() { var fixture = new Fixture().Customize(new AutoMoqCustomization()); _cachedReservation = fixture.Create <CachedReservation>(); _validator = fixture.Freeze <Mock <IValidator <IReservationQuery> > >(); _validator .Setup(x => x.ValidateAsync(It.Is <GetCachedReservationQuery>(c => c.Id.Equals(_cachedReservation.Id)))) .ReturnsAsync(new ValidationResult()); _cacheReservationRepository = fixture.Freeze <Mock <ICachedReservationRespository> >(); _cacheReservationRepository .Setup(r => r.GetProviderReservation(It.IsAny <Guid>(), It.IsAny <uint>())) .ReturnsAsync(_cachedReservation); _handler = fixture.Create <GetCachedReservationQueryHandler>(); }
public async Task And_AccountId_Less_Than_One_Then_Invalid( CachedReservationValidator validator) { var cachedReservation = new CachedReservation { Id = Guid.NewGuid(), AccountId = 0, TrainingDate = new TrainingDateModel { StartDate = DateTime.Now }, AccountLegalEntityName = "Test Name" }; var result = await validator.ValidateAsync(cachedReservation); result.IsValid().Should().BeFalse(); result.ValidationDictionary.Count.Should().Be(1); result.ValidationDictionary .Should().ContainKey(nameof(CachedReservation.AccountId)) .WhichValue.Should().Be($"{nameof(CachedReservation.AccountId)} has not been supplied"); }