public void ThenShouldThrowErrorIfAdjustmentLevyYtdIsNullAndIsNotANonPayment() { //Arrange var latestDeclaration = new DasDeclaration { LevyDueYtd = 20 }; _hmrcDateService.Setup(x => x.IsSubmissionEndOfYearAdjustment("16-17", 12, It.IsAny <DateTime>())) .Returns(true); _levyRepository.Setup(x => x.GetSubmissionByEmprefPayrollYearAndMonth(ExpectedEmpRef, "16-17", 8)) .ReturnsAsync(latestDeclaration); var data = RefreshEmployerLevyDataCommandObjectMother.CreateEndOfYearAdjustment(ExpectedEmpRef, ExpectedAccountId); var newDeclaration = data.EmployerLevyData.First().Declarations.Declarations.First(); newDeclaration.LevyDueYtd = null; newDeclaration.NoPaymentForPeriod = false; //Act Func <Task> action = () => _refreshEmployerLevyDataCommandHandler.Handle(data); action.ShouldThrow <ArgumentNullException>(); }
public async Task ThenTheValidatorIsCalled() { //Act await _refreshEmployerLevyDataCommandHandler.Handle(RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef)); //Assert _validator.Verify(x => x.Validate(It.IsAny <RefreshEmployerLevyDataCommand>())); }
public async Task ThenIfTheDeclarationHasNoSubmissionThenTheLevyDueYtdIsTakenFromThePreviousSubmission() { //Act var data = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId); await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclaration(It.Is <DasDeclaration>(c => c.NoPaymentForPeriod && c.LevyDueYtd.Equals(1000) && c.LevyAllowanceForFullYear.Equals(1200m)), ExpectedEmpRef, ExpectedAccountId), Times.Once); }
public async Task ThenARefreshEmployerLevyDataCompletedEventIsPublished() { //Act await _refreshEmployerLevyDataCommandHandler.Handle(RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId)); //Assert Assert.IsTrue(_eventPublisher.Events.OfType <RefreshEmployerLevyDataCompletedEvent>().Any(e => e.AccountId.Equals(ExpectedAccountId))); }
public async Task ThenIfTheDeclarationHasNoSubmissionForPeriodThenTheLAstSubmissionIsReadFromTheRepository() { //Arrange var data = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.GetLastSubmissionForScheme(ExpectedEmpRef), Times.Exactly(data.EmployerLevyData[0].Declarations.Declarations.Count(c => c.NoPaymentForPeriod))); }
public async Task ThenIfThereAreDeclarationsToProcessTheProcessDeclarationsEventIsPublished() { //Arrange var data = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _mediator.Verify(x => x.PublishAsync(It.IsAny <ProcessDeclarationsEvent>()), Times.Once); }
public async Task ThenDataIsTakenFromTheDataStoreForTheEmployerRefAndEachDeclarationRow() { //Arrange var refreshEmployerLevyDataCommand = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef); //Act await _refreshEmployerLevyDataCommandHandler.Handle(refreshEmployerLevyDataCommand); //Assert _levyRepository.Verify(x => x.GetEmployerDeclaration(It.Is <string>(c => c.Equals("1") || c.Equals("2") || c.Equals("4")), ExpectedEmpRef), Times.Exactly(refreshEmployerLevyDataCommand.EmployerLevyData[0].Declarations.Declarations.Count(c => !c.NoPaymentForPeriod))); }
public async Task ThenTheExistingDeclarationIdsAreCollected() { //Arrange var refreshEmployerLevyDataCommand = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef); //Act await _refreshEmployerLevyDataCommandHandler.Handle(refreshEmployerLevyDataCommand); //Assert _levyRepository.Verify(x => x.GetEmployerDeclarationSubmissionIds(ExpectedEmpRef), Times.Once()); }
public async Task ThenTheLevyRepositoryIsUpdatedIfTheDeclarationDoesNotExist() { //Arrange _levyRepository.Setup(x => x.GetEmployerDeclaration("1", ExpectedEmpRef)).ReturnsAsync(null); _levyRepository.Setup(x => x.GetEmployerDeclaration("2", ExpectedEmpRef)).ReturnsAsync(new DasDeclaration()); //Act await _refreshEmployerLevyDataCommandHandler.Handle(RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId)); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclaration(It.IsAny <DasDeclaration>(), ExpectedEmpRef, ExpectedAccountId)); }
public async Task ThenIfThereAreNoNewDeclarationsThenTheProcessDeclarationEventIsNotPublished() { //Arrange _levyRepository.Setup(x => x.GetEmployerDeclaration(It.IsAny <string>(), ExpectedEmpRef)).ReturnsAsync(new DasDeclaration()); var data = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _mediator.Verify(x => x.PublishAsync(It.IsAny <ProcessDeclarationsEvent>()), Times.Never); }
public async Task ThenTheLevyRepositoryIsUpdatedIfTheDeclarationDoesNotExist() { //Arrange _levyRepository.Setup(x => x.GetEmployerDeclarationSubmissionIds(ExpectedEmpRef)).ReturnsAsync(new List <long> { 2 }); //Act await _refreshEmployerLevyDataCommandHandler.Handle(RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId)); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclarations(It.IsAny <IEnumerable <DasDeclaration> >(), ExpectedEmpRef, ExpectedAccountId)); }
public async Task ThenIfThePayrollYearPreDatesTheLevyItIsNotProcessed() { //Arrange var data = RefreshEmployerLevyDataCommandObjectMother.CreateLevyDataWithFutureSubmissions(ExpectedEmpRef, DateTime.Now); _hmrcDateService.Setup(x => x.DoesSubmissionPreDateLevy(It.IsAny <string>())).Returns(true); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclaration(It.IsAny <DasDeclaration>(), It.IsAny <string>(), It.IsAny <long>()), Times.Never); }
public async Task ThenTheProcessTopupSchemeIsCalledForEachEmprefToBeUpdated() { //Arrange _levyRepository.Setup(x => x.GetEmployerDeclarationSubmissionIds(ExpectedEmpRef)).ReturnsAsync(new List <long> { 2 }); //Act await _refreshEmployerLevyDataCommandHandler.Handle(RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef)); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclarations(It.IsAny <IEnumerable <DasDeclaration> >(), ExpectedEmpRef)); _levyRepository.Verify(x => x.ProcessTopupsForScheme(ExpectedEmpRef), Times.Once); }
public async Task ThenIfTheSubmissionIsForATaxMonthInTheFutureItWillNotBeProcessed() { //Arrange var data = RefreshEmployerLevyDataCommandObjectMother.CreateLevyDataWithFutureSubmissions(ExpectedEmpRef, DateTime.UtcNow, ExpectedAccountId); var declaration = data.EmployerLevyData.Last().Declarations.Declarations.Last(); _hmrcDateService.Setup(x => x.IsSubmissionForFuturePeriod(declaration.PayrollYear, declaration.PayrollMonth.Value, It.IsAny <DateTime>())).Returns(true); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclaration(It.IsAny <DasDeclaration>(), ExpectedEmpRef, ExpectedAccountId), Times.Exactly(4)); }
public async Task ThenIfTheSubmissionIsAnEndOfYearAdjustmentTheAmountIsWorkedOutFromThePreviousTaxYearValue() { //Arrange _hmrcDateService.Setup(x => x.IsSubmissionEndOfYearAdjustment("16-17", 12, It.IsAny <DateTime>())).Returns(true); _levyRepository.Setup(x => x.GetSubmissionByEmprefPayrollYearAndMonth(ExpectedEmpRef, "16-17", 12)).ReturnsAsync(new DasDeclaration { LevyDueYtd = 20 }); var data = RefreshEmployerLevyDataCommandObjectMother.CreateEndOfYearAdjustment(ExpectedEmpRef, ExpectedAccountId); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclaration(It.Is <DasDeclaration>(c => c.EndOfYearAdjustment && c.EndOfYearAdjustmentAmount.Equals(10m)), ExpectedEmpRef, ExpectedAccountId), Times.Once); }
public async Task ThenIfTheSubmissionIsAnEndOfYearAdjustmentTheFlagIsSetOnTheRecord() { //Arrange _hmrcDateService.Setup(x => x.IsSubmissionEndOfYearAdjustment("16-17", 12, It.IsAny <DateTime>())).Returns(true); _levyRepository.Setup(x => x.GetSubmissionByEmprefPayrollYearAndMonth(ExpectedEmpRef, "16-17", 12)).ReturnsAsync(new DasDeclaration { LevyDueYtd = 20 }); var data = RefreshEmployerLevyDataCommandObjectMother.CreateEndOfYearAdjustment(ExpectedEmpRef); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.CreateEmployerDeclarations(It.Is <IEnumerable <DasDeclaration> >(c => c.Any(d => d.EndOfYearAdjustment)), ExpectedEmpRef), Times.Once); }
public async Task ThenIfLevyDataHasChangedThenALevyDeclarationUpdatedEventIsPublished() { //Arrange var data = RefreshEmployerLevyDataCommandObjectMother.CreateLevyDataWithMultiplePeriods(ExpectedAccountId, DateTime.UtcNow); var hashedAccountId = "ABC123"; _hashingService.Setup(x => x.HashValue(ExpectedAccountId)).Returns(hashedAccountId); var expectedLevyEvents = new List <LevyDeclarationUpdatedEvent> { new LevyDeclarationUpdatedEvent { ResourceUri = "ABC" }, new LevyDeclarationUpdatedEvent { ResourceUri = "ZZZ" } }; var expectedGenericEvents = new List <GenericEvent> { new GenericEvent { Id = 1 }, new GenericEvent { Id = 2 } }; _levyEventFactory.Setup( x => x.CreateDeclarationUpdatedEvent(hashedAccountId, data.EmployerLevyData[0].Declarations.Declarations[0].PayrollYear, data.EmployerLevyData[0].Declarations.Declarations[0].PayrollMonth)).Returns(expectedLevyEvents[0]); _genericEventFactory.Setup(x => x.Create(expectedLevyEvents[0])).Returns(expectedGenericEvents[0]); _levyEventFactory.Setup( x => x.CreateDeclarationUpdatedEvent(hashedAccountId, data.EmployerLevyData[1].Declarations.Declarations[0].PayrollYear, data.EmployerLevyData[1].Declarations.Declarations[0].PayrollMonth)).Returns(expectedLevyEvents[1]); _genericEventFactory.Setup(x => x.Create(expectedLevyEvents[1])).Returns(expectedGenericEvents[1]); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _mediator.Verify(x => x.SendAsync(It.IsAny <PublishGenericEventCommand>()), Times.Exactly(2)); _mediator.Verify(x => x.SendAsync(It.Is <PublishGenericEventCommand>(y => y.Event == expectedGenericEvents[0])), Times.Exactly(1)); _mediator.Verify(x => x.SendAsync(It.Is <PublishGenericEventCommand>(y => y.Event == expectedGenericEvents[1])), Times.Exactly(1)); }
public async Task ThenIfThereAreDeclarationsToProcessTheLevyAddedToAccountEventAndAccountLevyStatusEventIsPublished() { //Arrange var data = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId); _levyRepository.Setup(m => m.ProcessDeclarations(ExpectedAccountId, It.IsAny <string>())).Returns(Task.FromResult(decimal.One)); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.ProcessDeclarations(ExpectedAccountId, ExpectedEmpRef), Times.Once); Assert.IsTrue(_eventPublisher.Events.OfType <LevyAddedToAccount>().Any(e => e.AccountId.Equals(ExpectedAccountId) && e.Amount.Equals(decimal.One))); Assert.IsTrue(_eventPublisher.Events.OfType <RefreshEmployerLevyDataCompletedEvent>().Any(e => e.AccountId.Equals(ExpectedAccountId) && e.LevyImported.Equals(true) && e.LevyTransactionValue.Equals(decimal.One))); }
public async Task ThenIfThereAreNoNewDeclarationsThenTheProcessDeclarationEventIsNotPublished() { //Arrange _levyRepository.Setup(x => x.GetEmployerDeclarationSubmissionIds(ExpectedEmpRef)).ReturnsAsync(new List <long> { 1, 2, 3, 4 }); var data = RefreshEmployerLevyDataCommandObjectMother.Create(ExpectedEmpRef, ExpectedAccountId); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert _levyRepository.Verify(x => x.ProcessDeclarations(ExpectedAccountId, ExpectedEmpRef), Times.Never); Assert.IsFalse(_eventPublisher.Events.OfType <LevyAddedToAccount>().Any(e => e.AccountId.Equals(ExpectedAccountId) && e.Amount.Equals(decimal.One))); Assert.IsTrue(_eventPublisher.Events.OfType <RefreshEmployerLevyDataCompletedEvent>().Any(e => e.AccountId.Equals(ExpectedAccountId) && e.LevyImported.Equals(false) && e.LevyTransactionValue.Equals(decimal.Zero))); }
public async Task ThenIfTheSubmissionIsAnEndOfYearAdjustmentThePeriod12ValueWillBeTakenFromHmrcIfItExists() { const decimal period12Value = 5; var period12SubmissionDate = new DateTime(2017, 04, 19); const decimal yearEndAdjustment = 20; var yearEndAdjustmentSubmissionDate = new DateTime(2017, 05, 01); // the sign on the end of year adjustment value stored on the levy declaration table is inverted (i.e. it will be -15 here, not 15). const decimal endOfYearAdjustmentAmount = -15; List <DasDeclaration> savedDeclarations = null; //Arrange _hmrcDateService.Setup(x => x.IsSubmissionEndOfYearAdjustment("16-17", 12, yearEndAdjustmentSubmissionDate)).Returns(true); _hmrcDateService.Setup(x => x.IsDateOntimeForPayrollPeriod("16-17", 12, period12SubmissionDate)).Returns(true); _levyRepository .Setup(x => x.CreateEmployerDeclarations(It.IsAny <IEnumerable <DasDeclaration> >(), ExpectedEmpRef, ExpectedAccountId)) .Callback <IEnumerable <DasDeclaration>, string, long>((declarations, empref, accountId) => savedDeclarations = declarations.ToList()) .Returns(Task.CompletedTask); // this creates a period 12 declaration and a year-end adjustment. The GetSubmissionByEmprefPayrollYearAndMonth() method should not be called var data = RefreshEmployerLevyDataCommandObjectMother.CreateEndOfYearAdjustmentToPeriod12DeclarationOnHmrcFeed( ExpectedEmpRef, ExpectedAccountId, period12Value, period12SubmissionDate, yearEndAdjustment, yearEndAdjustmentSubmissionDate); //Act await _refreshEmployerLevyDataCommandHandler.Handle(data); //Assert Assert.AreEqual(data.EmployerLevyData.Sum(eld => eld.Declarations.Declarations.Count), savedDeclarations.Count, "Incorrect number of declarations saved"); Assert.IsTrue(savedDeclarations.Any(ld => ld.EndOfYearAdjustment && ld.EndOfYearAdjustmentAmount == endOfYearAdjustmentAmount), "Year end adjustment not saved with expected end of year adjustment value"); }