public bool IsValid(ApprenticeshipEmployerType apprenticeshipEmployerType, Apprenticeship apprenticeship, ApprenticeshipCreatedEvent apprenticeshipCreatedEvent) { var isValid = apprenticeshipCreatedEvent.ApprenticeshipId == apprenticeship.Id && apprenticeshipCreatedEvent.CreatedOn.Date == DateTime.UtcNow.Date && apprenticeshipCreatedEvent.AgreedOn == apprenticeship.Cohort.EmployerAndProviderApprovedOn && apprenticeshipCreatedEvent.AccountId == apprenticeship.Cohort.EmployerAccountId && apprenticeshipCreatedEvent.AccountLegalEntityPublicHashedId == apprenticeship.Cohort.AccountLegalEntity.PublicHashedId && apprenticeshipCreatedEvent.LegalEntityName == apprenticeship.Cohort.AccountLegalEntity.Name && apprenticeshipCreatedEvent.ProviderId == apprenticeship.Cohort.Provider.UkPrn && apprenticeshipCreatedEvent.TransferSenderId == apprenticeship.Cohort.TransferSenderId && apprenticeshipCreatedEvent.ApprenticeshipEmployerTypeOnApproval == apprenticeshipEmployerType && apprenticeshipCreatedEvent.Uln == apprenticeship.Uln && apprenticeshipCreatedEvent.TrainingType == apprenticeship.ProgrammeType.Value && apprenticeshipCreatedEvent.TrainingCode == apprenticeship.CourseCode && apprenticeshipCreatedEvent.StartDate == apprenticeship.StartDate.Value && apprenticeshipCreatedEvent.EndDate == apprenticeship.EndDate.Value && apprenticeshipCreatedEvent.PriceEpisodes.Count() == apprenticeship.PriceHistory.Count; for (var i = 0; i < apprenticeship.PriceHistory.Count; i++) { var priceHistory = apprenticeship.PriceHistory.ElementAt(i); var priceEpisode = apprenticeshipCreatedEvent.PriceEpisodes.ElementAtOrDefault(i); isValid = isValid && priceEpisode?.FromDate == priceHistory.FromDate & priceEpisode?.ToDate == priceHistory.ToDate & priceEpisode?.Cost == priceHistory.Cost; } return(isValid); }
public void VerifyAccountLevyStatusCommandIsSent(long accountId, ApprenticeshipEmployerType apprenticeshipEmployerType) { _mediator.Verify(e => e.SendAsync(It.Is <AccountLevyStatusCommand>(m => m.AccountId.Equals(accountId) && m.ApprenticeshipEmployerType.Equals(apprenticeshipEmployerType))), Times.Once); }
public async Task ThenFrameworkCoursesAreIncludeOrNotInMediatorRequest(ApprenticeshipEmployerType levyStatus, bool frameworksAreIncluded) { _accountLegalEntityResponse.LevyStatus = levyStatus; await _mapper.Map(_source); _mediator.Verify(x => x.Send(It.Is <GetTrainingCoursesQueryRequest>(p => p.IncludeFrameworks == frameworksAreIncluded), It.IsAny <CancellationToken>())); }
protected Account CreateAccount(long accountId, ApprenticeshipEmployerType apprenticeshipEmployerType) { return(new Account { Id = accountId, ApprenticeshipEmployerType = apprenticeshipEmployerType }); }
public async Task Then_CanContinueAnyway_Is_Mapped(ApprenticeshipEmployerType apprenticeshipEmployerType, bool canContinue) { //Arrange _account.ApprenticeshipEmployerType = apprenticeshipEmployerType; //Act var result = await _mapper.Map(_legalEntitySignedAgreementViewModel); //Assert Assert.AreEqual(canContinue, result.CanContinueAnyway); }
public Task SetAccountLevyStatus(long accountId, ApprenticeshipEmployerType apprenticeshipEmployerType) { var parameters = new DynamicParameters(); parameters.Add("@accountId", accountId, DbType.Int64); parameters.Add("@apprenticeshipEmployerType", apprenticeshipEmployerType, DbType.Int16); return(_db.Value.Database.Connection.ExecuteAsync( sql: "[employer_account].[UpdateAccount_SetAccountApprenticeshipEmployerType]", param: parameters, transaction: _db.Value.Database.CurrentTransaction.UnderlyingTransaction, commandType: CommandType.StoredProcedure)); }
public void Handle_WhenHandlingCommand_ThenShouldPublishEvents(ApprenticeshipEmployerType apprenticeshipEmployerType, bool isFundedByTransfer) { var f = new ProcessFullyApprovedCohortCommandFixture(); f.SetApprenticeshipEmployerType(apprenticeshipEmployerType) .SetApprovedApprenticeships(isFundedByTransfer) .Handle(); f.Apprenticeships.ForEach( a => f.EventPublisher.Verify( p => p.Publish(It.Is <ApprenticeshipCreatedEvent>( e => f.IsValid(apprenticeshipEmployerType, a, e))), Times.Once)); }
public void Handle_WhenHandlingCommand_ThenShouldProcessFullyApprovedCohort(ApprenticeshipEmployerType apprenticeshipEmployerType) { var f = new ProcessFullyApprovedCohortCommandFixture(); f.SetApprenticeshipEmployerType(apprenticeshipEmployerType) .Handle(); f.Db.Verify(d => d.ExecuteSqlCommandAsync( "EXEC ProcessFullyApprovedCohort @cohortId, @accountId, @apprenticeshipEmployerType", It.Is <SqlParameter>(p => p.ParameterName == "cohortId" && p.Value.Equals(f.Command.CohortId)), It.Is <SqlParameter>(p => p.ParameterName == "accountId" && p.Value.Equals(f.Command.AccountId)), It.Is <SqlParameter>(p => p.ParameterName == "apprenticeshipEmployerType" && p.Value.Equals(apprenticeshipEmployerType))), Times.Once); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { try { string hashedAccountId = string.Empty; if (filterContext.ActionParameters != null && filterContext.ActionParameters.ContainsKey("HashedAccountId")) { hashedAccountId = filterContext.ActionParameters["HashedAccountId"].ToString(); } else if (filterContext.RouteData?.Values?.ContainsKey("HashedAccountId") == true) { hashedAccountId = filterContext.RouteData.Values["HashedAccountId"].ToString(); } if (string.IsNullOrWhiteSpace(hashedAccountId)) { filterContext.Result = new ViewResult { ViewName = ControllerConstants.BadRequestViewName }; return; } var accountApi = DependencyResolver.Current.GetService <IAccountApiClient>(); var task = Task.Run(async() => await accountApi.GetAccount(hashedAccountId)); AccountDetailViewModel account = task.Result; ApprenticeshipEmployerType apprenticeshipEmployerType = (ApprenticeshipEmployerType)Enum.Parse(typeof(ApprenticeshipEmployerType), account.ApprenticeshipEmployerType, true); if (apprenticeshipEmployerType == ApprenticeshipEmployerType.Levy) { base.OnActionExecuting(filterContext); } else { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary( new { controller = ControllerConstants.AccessDeniedControllerName, action = "Index", })); } } catch (Exception ex) { filterContext.Result = new ViewResult { ViewName = ControllerConstants.BadRequestViewName }; } }
public void SetsReportingAimFundingLineType(ContractType contractType, ApprenticeshipEmployerType employerType, string fundingLineType, string expected) { var fundingSourceEvent = new EmployerCoInvestedFundingSourcePaymentEvent { ContractType = contractType, LearningAim = new LearningAim { FundingLineType = fundingLineType }, ApprenticeshipEmployerType = employerType }; var providerPayment = mapper.Map <ProviderPaymentEventModel>(fundingSourceEvent); providerPayment.ReportingAimFundingLineType.Should().StartWith(expected); }
public async Task ThenTasksServiceIsInvoked(ApprenticeshipEmployerType actualApprenticeshipEmployerType, TaskEnum.ApprenticeshipEmployerType expectedApprenticeshipEmployerType) { //Arrange _mockValidator.Setup(x => x.Validate(It.IsAny <GetAccountTasksQuery>())).Returns(new ValidationResult { ValidationDictionary = new Dictionary <string, string>() }); var sut = GetSut(); _validQuery.ApprenticeshipEmployerType = actualApprenticeshipEmployerType; //Act await sut.Handle(_validQuery); //Assert _mockTaskService.Verify(s => s.GetAccountTasks(_validQuery.AccountId, _validQuery.ExternalUserId, expectedApprenticeshipEmployerType), Times.Once); }
public async Task ThenAccountIsReturned() { const int accountId = 1; const ApprenticeshipEmployerType apprenticeshipEmployerType = ApprenticeshipEmployerType.Levy; _accountApiClient.Setup(c => c.GetAccount(accountId)).ReturnsAsync(new AccountDetailViewModel { AccountId = accountId, ApprenticeshipEmployerType = apprenticeshipEmployerType.ToString() }); var account = await _employerAccountsService.GetAccount(accountId); Assert.AreEqual(accountId, account.Id); Assert.AreEqual(apprenticeshipEmployerType, account.ApprenticeshipEmployerType); }
public void ThenTheApprenticeshipEmployerTypeIsCorrectInTheRequiredPayment( ApprenticeshipEmployerType testApprenticeshipEmployerType) { testEarning.Amount = 0; paymentHistory.Add(new Payment { Amount = 50, SfaContributionPercentage = 0.9m, FundingSource = FundingSourceType.Levy, ApprenticeshipEmployerType = testApprenticeshipEmployerType, }); var actual = sut.GetRequiredPayments(testEarning, paymentHistory); actual.Should().BeEquivalentTo(new { ApprenticeshipEmployerType = testApprenticeshipEmployerType, }); }
public void ShowYourFundingReservationsLink_GivenValues_ReturnsExpectedResult( ApprenticeshipEmployerType apprenticeshipEmployerType, AccountAgreementType agreementType, bool expectedValue) { // Arrange var model = new AccountDashboardViewModel { ApprenticeshipEmployerType = apprenticeshipEmployerType, AgreementInfo = new AgreementInfoViewModel { Type = agreementType } }; // Act var result = AccountDashboardViewModelExtensions.ShowYourFundingReservationsLink(model); // Assert Assert.AreEqual(expectedValue, result); }
public Apprenticeship( long id, string firstName, string lastName, DateTime dateOfBirth, long uniqueLearnerNumber, ApprenticeshipEmployerType employerType, string courseName, DateTime?employmentStartDate) { if (id <= 0) { throw new ArgumentException("Apprenticeship Id must be greater than 0", nameof(id)); } if (string.IsNullOrWhiteSpace(firstName)) { throw new ArgumentException("FirstName must be set", nameof(firstName)); } if (string.IsNullOrWhiteSpace(lastName)) { throw new ArgumentException("LastName must be set", nameof(lastName)); } if (uniqueLearnerNumber <= 0) { throw new ArgumentException("UniqueLearnerNumber must be greater than 0", nameof(uniqueLearnerNumber)); } if (string.IsNullOrWhiteSpace(courseName)) { throw new ArgumentException("CourseName must be set", nameof(courseName)); } Id = id; FirstName = firstName; LastName = lastName; DateOfBirth = dateOfBirth; UniqueLearnerNumber = uniqueLearnerNumber; EmployerType = employerType; CourseName = courseName; EmploymentStartDate = employmentStartDate; }
public void RefundProducesRequiredPaymentsWithOriginalEmployerType( ApprenticeshipEmployerType testType, RefundService sut) { var expectedAmount = -123.2m; var actual = sut.GetRefund(expectedAmount, new List <Payment> { new Payment { Amount = -1 * expectedAmount, FundingSource = FundingSourceType.Levy, ApprenticeshipEmployerType = testType, } }); actual.Should().BeEquivalentTo( new { ApprenticeshipEmployerType = testType, } ); }
public async Task AndWhenGettingCourseListVerifyIfFrameworksAreIncludedOrNot(bool isTransfer, ApprenticeshipEmployerType levyStatus, bool areFrameworksIncluded) { _fixture.SetupLevyStatus(levyStatus).SetupCohortFundedByTransfer(isTransfer); await _fixture.AddDraftApprenticeshipWithReservation(); _fixture.VerifyWhetherFrameworkCourseWereRequested(areFrameworksIncluded); }
public CohortBuilder WithEmployer(long accountId, string legalEntityId, string name, string accountLegalEntityPublicHashedId, long accountLegalEntityId, ApprenticeshipEmployerType apprenticeshipEmployerType) { _commitment.EmployerAccountId = accountId; _commitment.LegalEntityId = legalEntityId; _commitment.LegalEntityName = name; _commitment.LegalEntityAddress = "Some address"; _commitment.LegalEntityOrganisationType = 1; _commitment.AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId; _commitment.AccountLegalEntityId = accountLegalEntityId; _commitment.ApprenticeshipEmployerTypeOnApproval = apprenticeshipEmployerType; return(this); }
private async Task <TrainingProgramme[]> GetCourses(ApprenticeshipEmployerType levyStatus) { var result = await _mediator.Send(new GetTrainingCoursesQueryRequest { IncludeFrameworks = levyStatus != ApprenticeshipEmployerType.NonLevy }); return(result.TrainingCourses); }
public async Task Handle_WithSpecifiedApprovals_ShouldReturnExpectedLevyStatus(ApprenticeshipEmployerType levyStatus) { LevyStatus = levyStatus; await CheckQueryResponse(response => Assert.AreEqual(LevyStatus, response.LevyStatus, "Did not return expected LevyStatus")); }
public Task WhenMessageIsHandled_AccountLevyStatusCommandIsSent(decimal levyValue, ApprenticeshipEmployerType apprenticeshipEmployerType) { var timestamp = DateTime.UtcNow; const long accountId = 666; const bool levyImported = true; const short periodMonth = 7; const string periodYear = "2018"; return(TestAsync(f => f.Handle(new RefreshEmployerLevyDataCompletedEvent { AccountId = accountId, LevyImported = levyImported, PeriodMonth = periodMonth, PeriodYear = periodYear, LevyTransactionValue = levyValue, Created = timestamp }) , (f) => { f.VerifyAccountLevyStatusCommandIsSent(accountId, apprenticeshipEmployerType); })); }
public bool IsValid(ApprenticeshipEmployerType levyStatus) { return(levyStatus == Db.Object.Accounts.First().LevyStatus); }
public async Task TestPriceEpisodeIdentifierPickedFromHistoryForRefunds2(ApprenticeshipEmployerType employerType, OnProgrammeEarning earning, PaymentHistoryEntity previousPayment) { // arrange var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 3); var deliveryPeriod = (byte)2; var earningEvent = new ApprenticeshipContractType2EarningEvent { Ukprn = 1, CollectionPeriod = period, CollectionYear = period.AcademicYear, Learner = EarningEventDataHelper.CreateLearner(), LearningAim = EarningEventDataHelper.CreateLearningAim(), OnProgrammeEarnings = new List <OnProgrammeEarning>() { earning, }, PriceEpisodes = new List <PriceEpisode> { new PriceEpisode { LearningAimSequenceNumber = 1234 } } }; earning.Periods[0].ApprenticeshipEmployerType = previousPayment.ApprenticeshipEmployerType = employerType; earning.Type = OnProgrammeEarningType.Balancing; earning.Periods = earning.Periods.Take(1).ToList().AsReadOnly(); earning.Periods[0].Period = deliveryPeriod; earning.Periods[0].Amount = previousPayment.Amount - 1; var requiredPayments = new List <RequiredPayment> { new RequiredPayment { Amount = -1, EarningType = EarningType.CoInvested, ApprenticeshipEmployerType = employerType, ApprenticeshipId = previousPayment.ApprenticeshipId, ApprenticeshipPriceEpisodeId = previousPayment.ApprenticeshipPriceEpisodeId, }, }; previousPayment.LearnAimReference = earningEvent.LearningAim.Reference; previousPayment.DeliveryPeriod = deliveryPeriod; previousPayment.TransactionType = (int)earning.Type; var paymentHistory = ConditionalValue.WithArray(previousPayment); paymentHistoryCacheMock .Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>())) .ReturnsAsync(paymentHistory); requiredPaymentService .Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >())) .Returns(requiredPayments); // act var actualRequiredPayment = await act2EarningEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None); // assert actualRequiredPayment.Should().BeEquivalentTo( new { previousPayment.ApprenticeshipEmployerType, previousPayment.ApprenticeshipId, previousPayment.ApprenticeshipPriceEpisodeId, }); }
public DraftApprenticeshipControllerTestFixture SetupLevyStatus(ApprenticeshipEmployerType status) { _cohortResponse.LevyStatus = status; return(this); }
public async Task <IEnumerable <TaskDto> > GetTasks(string employerAccountId, string userId, ApprenticeshipEmployerType applicableToApprenticeshipEmployerType = ApprenticeshipEmployerType.All) { var baseUrl = GetBaseUrl(); var url = $"{baseUrl}api/tasks/{employerAccountId}/{userId}?{nameof(applicableToApprenticeshipEmployerType)}={(int)applicableToApprenticeshipEmployerType}"; _logger.Info($"Get: {url}"); var json = await _httpClient.GetAsync(url); return(JsonConvert.DeserializeObject <IEnumerable <TaskDto> >(json)); }
internal Apprenticeship(Guid id, long apprenticeshipId, string firstName, string lastName, DateTime dateOfBirth, long uln, DateTime plannedStartDate, ApprenticeshipEmployerType apprenticeshipEmployerTypeOnApproval, long?ukprn, string courseName) { IsNew = false; Model = new ApprenticeshipModel { Id = id, ApprenticeshipId = apprenticeshipId, FirstName = firstName, LastName = lastName, DateOfBirth = dateOfBirth, ULN = uln, PlannedStartDate = plannedStartDate, ApprenticeshipEmployerTypeOnApproval = apprenticeshipEmployerTypeOnApproval, TotalIncentiveAmount = CalculateTotalIncentiveAmount(dateOfBirth, plannedStartDate), UKPRN = ukprn, CourseName = courseName }; }
public ProcessFullyApprovedCohortCommandFixture SetApprenticeshipEmployerType(ApprenticeshipEmployerType apprenticeshipEmployerType) { AccountApiClient.Setup(c => c.GetAccount(Command.AccountId)) .ReturnsAsync(new AccountDetailViewModel { ApprenticeshipEmployerType = apprenticeshipEmployerType.ToString() }); return(this); }
public async Task <IHttpActionResult> GetUserTasks(string employerAccountId, string userId, ApprenticeshipEmployerType applicableToApprenticeshipEmployerType) { _logger.Debug($"Getting tasks for employer account {employerAccountId}"); var result = await _mediator.SendAsync(new GetTasksByEmployerAccountIdRequest { EmployerAccountId = employerAccountId, UserId = userId, ApplicableToApprenticeshipEmployerType = applicableToApprenticeshipEmployerType }); if (result?.Tasks == null) { return(Ok(Enumerable.Empty <TaskDto>())); } var tasks = result.Tasks.Select(x => new TaskDto { EmployerAccountId = x.EmployerAccountId, Type = x.Type.ToString(), ItemsDueCount = x.ItemsDueCount }).AsEnumerable(); return(Ok(tasks)); }
public ITransactionFormatter GetTransactionsFormatterByType(DownloadFormatType format, ApprenticeshipEmployerType apprenticeshipEmployerType) { return(_formatters.FirstOrDefault(f => f.DownloadFormatType == format && f.ApprenticeshipEmployerType == apprenticeshipEmployerType)); }
public void Then_the_payment_is_created(DateTime dob, DateTime plannedStartDate, ApprenticeshipEmployerType employerType, SubnominalCode expectedSubnominalCode) { // arrange var apprenticeship = new Apprenticeship(_fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), dob, _fixture.Create <long>(), employerType, _fixture.Create <string>(), _fixture.Create <DateTime>()); _sutModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(x => x.StartDate, plannedStartDate) .With(x => x.Apprenticeship, apprenticeship) .With(x => x.PaymentModels, new List <PaymentModel>()).Create(); _sut = Sut(_sutModel); var pendingPayment = _sut.PendingPayments.First(); // act _sut.CreatePayment(pendingPayment.Id, _collectionPeriod); // assert _sut.Payments.Count.Should().Be(1); var actualPayment = _sut.Payments.First(); actualPayment.SubnominalCode.Should().Be(expectedSubnominalCode); }