Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }