public async Task ShouldEndReclaim() { var package = TestDataHelper.CreateCarePackage(packageType: PackageType.ResidentialCare, status: PackageStatus.Approved); var coreCost = TestDataHelper.CreateCarePackageDetail(package.Id, PackageDetailType.CoreCost); package.Details.Add(coreCost); package.Reclaims.Add(TestDataHelper.CreateCarePackageReclaim(package.Id, type: ReclaimType.CareCharge, subType: ReclaimSubType.CareChargeProvisional, collector: ClaimCollector.Supplier, startDate: coreCost.StartDate, endDate: coreCost.EndDate, cost: 10M)); package = _generator.CreateCarePackage(package); var reclaim = package.Reclaims.First(); var endDate = DateTimeOffset.UtcNow; var response = await _fixture.RestClient .PutAsync <CarePackageReclaimResponse>( $"api/v1/care-packages/{package.Id}/reclaims/care-charges/{reclaim.Id}/end", new CarePackageReclaimEndRequest { EndDate = endDate }); reclaim = _fixture.DatabaseContext.CarePackageReclaims.First(r => r.Id == reclaim.Id); response.Message.StatusCode.Should().Be(HttpStatusCode.OK); response.Content.Status.Should().Be(ReclaimStatus.Ended); reclaim.Status.Should().Be(ReclaimStatus.Ended); reclaim.EndDate.Value.Date.Should().Be(endDate.Date); }
public void ShouldFailWhenReclaimsExceedsCoreCost() { var package = TestDataHelper .CreateCarePackage() .AddCoreCost(1000.0m, "01-12-2022", "31-12-2022") .AddCareChargeProvisional(2500.0m, ClaimCollector.Supplier, "01-12-2022", "31-12-2022") .SetCurrentDate("01-12-2022"); FluentActions.Invoking(() => ReclaimCostValidator.Validate(package)).Should().Throw <ApiException>(); }
public void ShouldPassWhenReclaimsLessThanCosts() { var package = TestDataHelper .CreateCarePackage() .AddCoreCost(1000.0m, "01-12-2022", "31-12-2022") .AddWeeklyNeed(500.0m, "01-12-2022", "15-12-2022") .AddCareChargeProvisional(250.0m, ClaimCollector.Supplier, "01-12-2022", "31-12-2022") .SetCurrentDate("01-12-2022"); FluentActions.Invoking(() => ReclaimCostValidator.Validate(package)).Should().NotThrow(); }
public void CreateShouldAddCarePackage() { var mockSet = new Mock <DbSet <CarePackage> >(); Context.CarePackages = mockSet.Object; var carePackage = TestDataHelper.CreateCarePackage(); _carePackageGateway.Create(carePackage); // Check add was called only once mockSet.Verify(x => x.Add(It.IsAny <CarePackage>()), Times.Once()); }
public CarePackage CreateCarePackage(PackageType type = PackageType.ResidentialCare, PackageStatus status = PackageStatus.New) { var carePackage = TestDataHelper.CreateCarePackage(type, status); carePackage.SupplierId = _context.Suppliers.FirstOrDefault()?.Id; _context.CarePackages.Add(carePackage); _context.SaveChanges(); return(carePackage); }
public async void ShouldGetAcceptedInvoicesForPackage() { var fixture = new Fixture(); var package = TestDataHelper.CreateCarePackage(); package.ServiceUser = TestDataHelper.CreateServiceUser(); package.Supplier = TestDataHelper.CreateSupplier(); var invoice = fixture.Build <Invoice>() .OmitAutoProperties() .With(i => i.PackageId, package.Id) .With(i => i.GrossTotal, 5m) .With(i => i.TotalCost, 5m) .With(i => i.NetTotal, 5m); var periodFrom = DateTimeOffset.UtcNow.Date.AddDays(-300); var periodTo = DateTimeOffset.UtcNow.Date; var payRun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, startDate: periodFrom, paidUpToDate: periodTo, endDate: periodTo, status: PayrunStatus.Paid); var payRunInvoices = fixture.Build <PayrunInvoice>() .OmitAutoProperties() .With(pi => pi.Invoice, invoice.Create()) .With(pi => pi.Payrun, payRun) .With(pi => pi.PayrunId, payRun.Id) .CreateMany(100).ToList(); _carePackageGateway .Setup(g => g.GetPackageAsync(It.IsAny <Guid>(), It.IsAny <PackageFields>(), It.IsAny <bool>())) .ReturnsAsync(package); _payRunGateway .Setup(g => g.GetPackageLatestPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayrunStatus[]>(), It.IsAny <InvoiceStatus[]>())).ReturnsAsync(payRun); _payRunInvoiceGateway.Setup(g => g.GetPackageInvoicesAsync(It.IsAny <Guid>(), It.IsAny <PayrunStatus[]>(), It.IsAny <InvoiceStatus[]>(), It.IsAny <PayRunInvoiceFields>(), It.IsAny <bool>())) .ReturnsAsync(payRunInvoices); var requestParams = new RequestParameters { PageNumber = 1, PageSize = 20 }; var result = await _useCase.GetAsync(package.Id, requestParams); result.Payments.PagingMetaData.Should().BeEquivalentTo(requestParams, options => options.ExcludingMissingMembers()); result.Payments.Data.Count().Should().Be(requestParams.PageSize); result.PackagePayment.DateTo.Should().Be(periodTo); result.PackagePayment.PackageId.Should().Be(package.Id); result.PackagePayment.TotalPaid.Should().Be(500M); result.PackageType.Should().Be(package.PackageType); result.CedarId.Should().Be(package.Supplier.CedarId); }
public async Task ShouldThrowExceptionIfPackageNotFound() { var carePackage = TestDataHelper.CreateCarePackage(); var updateRequest = TestDataHelper.CarePackageUpdateRequest(carePackage, TestDataHelper.CreateCarePackageSettings()); Func <Task> action = () => _useCase.UpdateAsync(carePackage.Id, updateRequest.ToDomain()); await action.Should().ThrowAsync <ApiException>(); _carePackageGateway.Verify(x => x.GetPackagePlainAsync(It.IsAny <Guid>(), It.IsAny <bool>()), Times.Once); _carePackageSettingsGateway.Verify(x => x.GetPackageSettingsPlainAsync(It.IsAny <Guid>(), It.IsAny <bool>()), Times.Never); _dbManager.Verify(x => x.SaveAsync(It.IsAny <string>()), Times.Never); }
public EndCarePackageUseCaseTests() { _package = TestDataHelper .CreateCarePackage() .AddCoreCost(1000.0m, _today.AddDays(-5), _today.AddDays(30)); _coreCost = _package.GetCoreCostDetail(); _dbManager = new Mock <IDatabaseManager>(); var gateway = new Mock <ICarePackageGateway>(); gateway .Setup(g => g.GetPackageAsync(It.IsAny <Guid>(), It.IsAny <PackageFields>(), It.IsAny <bool>())) .ReturnsAsync(_package); _useCase = new EndCarePackageUseCase(gateway.Object, _dbManager.Object); }
public async Task ShouldCreatePackageSettingsIfNotFound() { var carePackage = TestDataHelper.CreateCarePackage(); carePackage.Settings = TestDataHelper.CreateCarePackageSettings(); _dbManager.Setup(dm => dm.SaveAsync(It.IsAny <string>())).Returns(() => Task.FromResult(carePackage)); _carePackageGateway.Setup(cp => cp.GetPackagePlainAsync(It.IsAny <Guid>(), It.IsAny <bool>())).ReturnsAsync(() => carePackage); var updateRequest = TestDataHelper.CarePackageUpdateRequest(carePackage, carePackage.Settings); await _useCase.UpdateAsync(carePackage.Id, updateRequest.ToDomain()); carePackage.Settings.Should().BeEquivalentTo(carePackage.Settings, opt => opt.ExcludingMissingMembers().ExcludingNestedObjects()); _carePackageGateway.Verify(x => x.GetPackagePlainAsync(It.IsAny <Guid>(), It.IsAny <bool>()), Times.Once); _carePackageSettingsGateway.Verify(x => x.GetPackageSettingsPlainAsync(It.IsAny <Guid>(), It.IsAny <bool>()), Times.Once); _dbManager.Verify(x => x.SaveAsync(It.IsAny <string>()), Times.Once); }
public async Task ShouldCreateNewCareCharge() { var package = TestDataHelper.CreateCarePackage(packageType: PackageType.ResidentialCare, status: PackageStatus.Approved); package.Settings = TestDataHelper.CreateCarePackageSettings(carePackageId: package.Id, isS117Client: false); package.Details.Add( TestDataHelper.CreateCarePackageDetail(package.Id, type: PackageDetailType.CoreCost, cost: 100M)); package = _generator.CreateCarePackage(package); var request = new CareChargesCreationRequest() { CareCharges = new List <CareChargeReclaimCreationRequest>() { new CareChargeReclaimCreationRequest() { Cost = 12.34m, ClaimCollector = ClaimCollector.Hackney, SubType = ReclaimSubType.CareCharge1To12Weeks, StartDate = package.Details.First().StartDate, EndDate = package.Details.First().StartDate.AddDays(83), Description = "test", ClaimReason = "test", CarePackageId = package.Id } } }; var response = await _fixture.RestClient .PutAsync <object>($"api/v1/care-packages/{package.Id}/reclaims/care-charges", request); var reclaims = _fixture.DatabaseContext.CarePackageReclaims .Where(r => r.CarePackageId == package.Id).ToList(); response.Message.StatusCode.Should().Be(HttpStatusCode.OK); reclaims.Count.Should().Be(1); //reclaims.Should().ContainSingle(r => r.Cost == request.Cost); }
public void ShouldFailWhenUserHaveActivePackageOfSameType() { var package = TestDataHelper.CreateCarePackage(); package.Settings = TestDataHelper.CreateCarePackageSettings(); _carePackageGateway .Setup(g => g.GetPackagePlainAsync(package.Id, It.IsAny <bool>())) .ReturnsAsync(package); _carePackageGateway .Setup(g => g.GetServiceUserActivePackagesCount(package.ServiceUserId, package.PackageType, package.Id)) .ReturnsAsync(1); var updateRequest = TestDataHelper.CarePackageUpdateRequest(package, package.Settings); _useCase .Invoking(useCase => useCase.UpdateAsync(package.Id, updateRequest.ToDomain())) .Should().Throw <ApiException>() .Where(ex => ex.StatusCode == StatusCodes.Status500InternalServerError); _dbManager.Verify(mock => mock.SaveAsync(It.IsAny <string>()), Times.Never); }
public async Task ShouldCreateFundedNursingCareReclaimForExistingNursingCarePackage() { var startDate = "01-12-2022".ToUtcDate(); var endDate = "31-12-2022".ToUtcDate(); var fncCost = 500M; var package = TestDataHelper .CreateCarePackage(PackageType.NursingCare) .AddCoreCost(fncCost * 2, startDate, endDate) .Save(_fixture.DatabaseContext); var response = await CreateFncReclaim(package.Id, fncCost, startDate, endDate); var reclaims = await _fixture.DatabaseContext.CarePackageReclaims .Where(c => c.CarePackageId == package.Id) .ToListAsync(); response.Message.StatusCode.Should().Be(HttpStatusCode.OK); reclaims.Count.Should().Be(2); reclaims.Should().OnlyContain(r => r.Type == ReclaimType.Fnc && r.StartDate == startDate && r.EndDate == endDate); reclaims.Should().ContainSingle(r => r.SubType == ReclaimSubType.FncPayment && r.Cost == fncCost); reclaims.Should().ContainSingle(r => r.SubType == ReclaimSubType.FncReclaim && r.Cost == -fncCost); }
private static CarePackage CreateSinglePackage(PackageType type, PackageStatus status, ServiceUser client, Supplier supplier) { return(TestDataHelper.CreateCarePackage(type, status, client.Id, supplier.Id)); }