public async Task UpdateCarePackageDetailsShouldFailIfAnpDatesOutsideCoreCostDates()
        {
            var package = _generator.CreateCarePackage();
            var details = _generator.CreateCarePackageDetails(package, 1, PackageDetailType.AdditionalNeed);

            var request = new CarePackageBrokerageCreationRequest
            {
                CoreCost   = 123.45m,
                StartDate  = DateTimeOffset.UtcNow.Date.AddDays(-30),
                EndDate    = DateTimeOffset.UtcNow.Date.AddDays(30),
                SupplierId = 2,
                Details    = details.ToRequest().ToList()
            };

            request.Details.Add(TestDataHelper.CreateCarePackageDetailDomainList(2, PackageDetailType.AdditionalNeed).First().ToRequest());

            foreach (var detail in request.Details)
            {
                detail.Cost     += 10.0m;
                detail.StartDate = request.StartDate?.AddDays(-40);
                detail.EndDate   = request.EndDate?.AddDays(40);
            }

            var response = await _fixture.RestClient
                           .PutAsync <object>($"api/v1/care-packages/{package.Id}/details", request);

            response.Message.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
        }
        public void ShouldCreateCarePackageDetails()
        {
            var brokerageInfo = new CarePackageBrokerageDomain
            {
                Details = TestDataHelper.CreateCarePackageDetailDomainList(3, PackageDetailType.AdditionalNeed)
            };

            _useCase.ExecuteAsync(_package.Id, brokerageInfo);

            VerifyPackageDetails(brokerageInfo);
            VerifyDatabaseCalls();
        }
        private List <CarePackageDetailDomain> FillPackageDetails()
        {
            var packageDetails = TestDataHelper.CreateCarePackageDetailDomainList(3, PackageDetailType.AdditionalNeed);

            foreach (var detail in packageDetails)
            {
                detail.Id = Guid.NewGuid();
            }

            _package.Details.AddRange(packageDetails.ToEntity());

            return(packageDetails);
        }
        public void ShouldFailOnMissingPackage()
        {
            var brokerageInfo = new CarePackageBrokerageDomain
            {
                Details = TestDataHelper.CreateCarePackageDetailDomainList(1, PackageDetailType.AdditionalNeed)
            };

            _useCase
            .Invoking(useCase => useCase.ExecuteAsync(Guid.NewGuid(), brokerageInfo))
            .Should().Throw <ApiException>()
            .Where(ex => ex.StatusCode == StatusCodes.Status404NotFound);

            _dbManagerMock.Verify(mock => mock.SaveAsync(It.IsAny <string>()), Times.Never);
        }
        public void ShouldFailOnSecondCoreCostCreation()
        {
            FillPackageDetails();

            var brokerageInfo = new CarePackageBrokerageDomain
            {
                Details = TestDataHelper.CreateCarePackageDetailDomainList(1, PackageDetailType.CoreCost)
            };

            _useCase
            .Invoking(useCase => useCase.ExecuteAsync(_package.Id, brokerageInfo))
            .Should().Throw <ApiException>()
            .Where(ex => ex.StatusCode == StatusCodes.Status400BadRequest);

            _dbManagerMock.Verify(mock => mock.SaveAsync(It.IsAny <string>()), Times.Never);
        }
        public async Task ShouldUpdateCarePackageDetails()
        {
            var package = _generator.CreateCarePackage();
            var details = _generator.CreateCarePackageDetails(package, 5, PackageDetailType.AdditionalNeed);

            var request = new CarePackageBrokerageCreationRequest
            {
                CoreCost   = 123.45m,
                StartDate  = DateTimeOffset.UtcNow.Date.AddDays(-500),
                SupplierId = 2,
                Details    = details.ToRequest().ToList()
            };

            // Imitate remove, create and update at once
            request.Details.RemoveAt(1);
            request.Details.RemoveAt(2);
            request.Details.Add(TestDataHelper.CreateCarePackageDetailDomainList(1, PackageDetailType.AdditionalNeed).First().ToRequest());

            foreach (var detail in request.Details)
            {
                detail.Cost     += 1.0m;
                detail.StartDate = detail.StartDate?.AddDays(-10) ?? DateTimeOffset.UtcNow.Date.AddDays(-10);
                detail.EndDate   = detail.EndDate?.AddDays(-10) ?? DateTimeOffset.UtcNow.Date.AddDays(-10);
            }

            var response = await _fixture.RestClient
                           .PutAsync <object>($"api/v1/care-packages/{package.Id}/details", request);

            package = _fixture.DatabaseContext.CarePackages
                      .Include(p => p.Details)
                      .First(p => p.Id == package.Id);

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

            VerifyPackageDetails(package, request);
        }