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 async Task ShouldUpdateCarePackage() { // using local fixture to isolate this test from data created by other tests using var localFixture = new MockWebApplicationFactory(); var carePackage = localFixture.Generator.CreateCarePackage(); var carePackageSettings = localFixture.Generator.CreateCarePackageSettings(carePackage.Id); var updatedCarePackageSettings = new CarePackageSettings { HasRespiteCare = true, HasDischargePackage = true, HospitalAvoidance = true, IsReEnablement = true, IsS117Client = true }; // Update some care package settings carePackage.PrimarySupportReasonId = 2; carePackage.PackageScheduling = PackageScheduling.LongTerm; var carePackageUpdateRequest = TestDataHelper.CarePackageUpdateRequest(carePackage, updatedCarePackageSettings); var response = await localFixture.RestClient .UpdateFormAsync <CarePackagePlainResponse>($"api/v1/care-packages/{carePackage.Id}", carePackageUpdateRequest) .ConfigureAwait(false); var packageSettingsEntity = localFixture.DatabaseContext.CarePackageSettings.SingleOrDefault(ps => ps.CarePackageId.Equals(carePackage.Id)); Assert.Equal(HttpStatusCode.OK, response.Message.StatusCode); response.Content.Id.Should().Be(carePackage.Id); response.Content.PackageType.Should().Be((int)carePackageUpdateRequest.PackageType); response.Content.Status.Should().Be(PackageStatus.InProgress); // Check package settings updated Assert.NotNull(packageSettingsEntity); var newSettings = new { updatedCarePackageSettings.HasRespiteCare, updatedCarePackageSettings.HasDischargePackage, updatedCarePackageSettings.HospitalAvoidance, updatedCarePackageSettings.IsReEnablement, updatedCarePackageSettings.IsS117Client }; packageSettingsEntity.Should().BeEquivalentTo(newSettings, opt => opt.ExcludingMissingMembers().ExcludingNestedObjects()); }
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 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); }