示例#1
0
        public ChangePayRunInvoiceStatusUseCaseTests()
        {
            _payRunGateway        = new Mock <IPayRunGateway>();
            _payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>();
            _dbManager            = new Mock <IDatabaseManager>();
            _payrun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.WaitingForApproval);

            var fixture = new Fixture();

            _payrunInvoice = fixture.Build <PayrunInvoice>()
                             .OmitAutoProperties()
                             .With(pi => pi.PayrunId, _payrun.Id)
                             .With(pi => pi.InvoiceStatus, InvoiceStatus.Draft)
                             .Create();
            _payrun.PayrunInvoices.Add(_payrunInvoice);

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            _payRunInvoiceGateway.Setup(g => g.GetPayRunInvoiceAsync(It.IsAny <Guid>(), It.IsAny <PayRunInvoiceFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrunInvoice);

            _useCase = new ChangePayRunInvoiceStatusUseCase(_dbManager.Object, _payRunGateway.Object,
                                                            _payRunInvoiceGateway.Object);
        }
示例#2
0
        public HoldInvoiceUseCaseTests()
        {
            _dbManager            = new Mock <IDatabaseManager>();
            _heldInvoiceGateway   = new Mock <IHeldInvoiceGateway>();
            _payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>();
            _payRunGateway        = new Mock <IPayRunGateway>();

            _payrun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.WaitingForApproval);

            var fixture = new Fixture();

            _payrunInvoice = fixture.Build <PayrunInvoice>()
                             .OmitAutoProperties()
                             .With(pi => pi.PayrunId, _payrun.Id)
                             .With(pi => pi.InvoiceStatus, InvoiceStatus.Draft)
                             .Create();
            _payrun.PayrunInvoices.Add(_payrunInvoice);

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            _payRunInvoiceGateway.Setup(g => g.GetPayRunInvoiceAsync(It.IsAny <Guid>(), It.IsAny <PayRunInvoiceFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrunInvoice);

            _useCase = new HoldInvoiceUseCase(_dbManager.Object, _heldInvoiceGateway.Object,
                                              _payRunInvoiceGateway.Object, _payRunGateway.Object);

            _heldInvoiceCreationDomain = new HeldInvoiceCreationDomain
            {
                PayRunInvoiceId      = _payrunInvoice.Id,
                ActionRequiredFromId = 1,
                ReasonForHolding     = "Incorrect values"
            };
        }
示例#3
0
        public async Task ShouldGetPayRunList()
        {
            ClearDatabase();
            var payRunDateRanges = CreateDateRanges(DateTimeOffset.UtcNow.Date.AddDays(-600), 30, 15);
            var payRuns          = payRunDateRanges.Select(dateRange =>
                                                           TestDataHelper.CreatePayRun(startDate: dateRange.Start, endDate: dateRange.End,
                                                                                       paidUpToDate: dateRange.End)).ToList();

            _generator.CreatePayRuns(payRuns);

            var parameters = new PayRunListParameters {
                PageNumber = 1, PageSize = 15
            };
            var url = new UrlFormatter()
                      .SetBaseUrl($"api/v1/payruns")
                      .AddParameter("pageNumber", parameters.PageNumber)
                      .AddParameter("pageSize", parameters.PageSize)
                      .ToString();

            var response = await _fixture.RestClient
                           .GetAsync <PagedResponse <PayRunListResponse> >(url);

            Assert.NotNull(response);
            response.Message.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Data.Count().Should().Be(15);
        }
        public GetPayRunDetailsUseCaseTests()
        {
            _payrun  = TestDataHelper.CreatePayRun();
            _fixture = new Fixture();

            _payRunGateway        = new Mock <IPayRunGateway>();
            _payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>();

            _useCase = new GetPayRunDetailsUseCase(_payRunGateway.Object, _payRunInvoiceGateway.Object);
        }
示例#5
0
        public RejectPayRunUseCaseTests()
        {
            _payrun        = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.Approved);
            _payRunGateway = new Mock <IPayRunGateway>();
            _dbManager     = new Mock <IDatabaseManager>();

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            _useCase = new ArchivePayRunUseCase(_payRunGateway.Object, _dbManager.Object);
        }
示例#6
0
        private Payrun CreateFullPayRun(bool hasHeldInvoices = false, bool hasReleasedInvoices = false)
        {
            ClearDatabase();
            var packages = CreateCarePackages();
            var invoices = CreateInvoices(packages);

            // Create pay run with 10 items
            var payRun = TestDataHelper.CreatePayRun(PayrunType.ResidentialRecurring,
                                                     PayrunStatus.Approved, startDate: _periodFrom, endDate: _periodTo, paidUpToDate: _periodTo);

            payRun.PayrunInvoices = CreatePayRunInvoices(payRun, invoices, hasHeldInvoices, hasReleasedInvoices);
            return(_generator.CreatePayRun(payRun));
        }
        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);
        }
示例#8
0
        public async Task ShouldGetPreviousPayRunEndDate()
        {
            ClearDatabase();
            var payRun = TestDataHelper.CreatePayRun(PayrunType.ResidentialRecurring, PayrunStatus.Approved,
                                                     startDate: _periodFrom, endDate: _periodTo, paidUpToDate: _periodTo);

            _generator.CreatePayRun(payRun);

            var url = new UrlFormatter()
                      .SetBaseUrl($"api/v1/payruns/{payRun.Type}/previous-pay-run-end-date")
                      .ToString();
            var response = await _fixture.RestClient
                           .GetAsync <DateTimeOffset>(url);

            Assert.NotNull(response);
            response.Message.StatusCode.Should().Be(HttpStatusCode.OK);
            Assert.Equal(payRun.EndDate, response.Content);
        }
        public ApprovePayRunUseCaseTests()
        {
            _payrun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.Approved);
            var fixture        = new Fixture();
            var payRunInvoices = fixture.Build <PayrunInvoice>()
                                 .OmitAutoProperties()
                                 .With(pi => pi.PayrunId, _payrun.Id)
                                 .With(pi => pi.InvoiceStatus, InvoiceStatus.Accepted)
                                 .CreateMany(5).ToList();

            _payrun.PayrunInvoices = payRunInvoices;

            _payRunGateway = new Mock <IPayRunGateway>();
            _dbManager     = new Mock <IDatabaseManager>();

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            _useCase = new ApprovePayRunUseCase(_payRunGateway.Object, _dbManager.Object);
        }
示例#10
0
        public async Task ShouldFailIfExistsAnUnApprovedPayRun(PayrunStatus status)
        {
            ClearDatabase();
            _fixture.DatabaseContext.Add(TestDataHelper.CreatePayRun(status: status));
            await _fixture.DatabaseContext.SaveChangesAsync();

            var payRunCreationRequest = new DraftPayRunCreationRequest
            {
                Type         = PayrunType.ResidentialRecurring,
                PaidFromDate = _periodFrom,
                PaidUpToDate = _periodTo
            };
            var url      = $"api/v1/payruns";
            var response = await _fixture.RestClient.PostAsync <object>(url, payRunCreationRequest);

            response.Message.StatusCode.Should().Be(HttpStatusCode.PreconditionFailed);

            var payRuns = _fixture.DatabaseContext.Payruns.ToList();

            payRuns.Should().HaveCount(1);
        }
示例#11
0
        public MakePayRunPaymentUseCaseTests()
        {
            _payrun         = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.Approved);
            _payRunInsights = new PayRunInsightsDomain
            {
                TotalInvoiceAmount = 1000M,
                HoldsCount         = 5,
                TotalHeldAmount    = 100M
            };

            var payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>();

            _payRunGateway = new Mock <IPayRunGateway>();
            _dbManager     = new Mock <IDatabaseManager>();

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            payRunInvoiceGateway.Setup(g => g.GetPayRunInsightsAsync(It.IsAny <Guid>())).ReturnsAsync(_payRunInsights);

            _useCase = new MakePayRunPaymentUseCase(_payRunGateway.Object, _dbManager.Object,
                                                    payRunInvoiceGateway.Object);
        }