public void GetMashReferralsWithIdQueryReturnsReferralsMatchingId() { const int numberOfMashReferralsToAdd = 5; var id = -1L; MashReferral referral = null !; for (var i = 0; i < numberOfMashReferralsToAdd; i++) { var tempRef = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); if (i == 0) { referral = tempRef.ToDomain(); id = referral.Id; } } var query = TestHelpers.CreateQueryMashReferral(id); query.WorkerEmail = null; var response = _mashReferralGateway.GetReferralsUsingQuery(query).ToList(); response.Count.Should().Be(1); response[0].Id.Should().Equals(referral.Id); }
public void SuccessfulUpdateOfMashReferralFromFinalToPostFinalUpdatesAndReturnsMashReferralDomain() { var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, "FINAL"); var request = TestHelpers.CreateUpdateMashReferral(updateType: "FINAL-DECISION"); var response = _mashReferralGateway.UpdateReferral(request, mashReferral.Id); response.Should().BeEquivalentTo(mashReferral.ToDomain()); }
public void SuccessfulUpdateOfMashReferralAssignsWorkerAndReturnsMashReferralDomain() { var worker = MashReferralHelper.SaveWorkerToDatabase(DatabaseContext); var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, "CONTACT"); var request = TestHelpers.CreateUpdateMashReferral(updateType: "ASSIGN-WORKER", workerId: worker.Id); var response = _mashReferralGateway.UpdateReferral(request, mashReferral.Id); response.Should().BeEquivalentTo(mashReferral.ToDomain()); }
public void SuccessfulUpdateOfMashReferralFromContactToInitialUpdatesAndReturnsMashReferralDomain() { var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, "CONTACT"); var request = TestHelpers.CreateUpdateMashReferral(updateType: "CONTACT-DECISION"); request.WorkerEmail = null; var response = _mashReferralGateway.UpdateReferral(request, mashReferral.Id); response.Should().BeEquivalentTo(mashReferral.ToDomain()); }
public void UpdatingMashReferralThrowsWorkerNotFoundExceptionWhenWorkerIsNotFoundUsingId() { var workerId = _faker.Random.Int(); var request = TestHelpers.CreateUpdateMashReferral(updateType: "ASSIGN-WORKER", workerId: workerId); var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); Action act = () => _mashReferralGateway.UpdateReferral(request, mashReferral.Id); act.Should().Throw <WorkerNotFoundException>() .WithMessage($"Worker with id {workerId} not found"); }
UpdatingMashReferralThrowsMashReferralStageMismatchExceptionWhenRequestUpdateIsForFinalDecisionAndReferralIsNotInFinalStage() { var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); var request = TestHelpers.CreateUpdateMashReferral(updateType: "FINAL-DECISION"); Action act = () => _mashReferralGateway.UpdateReferral(request, mashReferral.Id); act.Should().Throw <MashReferralStageMismatchException>() .WithMessage( $"Referral {mashReferral.Id} is in stage '{mashReferral.Stage}', this request requires the referral to be in stage 'FINAL'"); }
public void SuccessfulUpdateOfMashReferralUnAssignsWorkerAndReturnsMashReferralDomain() { var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); mashReferral.WorkerId = 1; var request = TestHelpers.CreateUpdateMashReferral(updateType: "UNASSIGN-WORKER"); var response = _mashReferralGateway.UpdateReferral(request, mashReferral.Id); mashReferral.WorkerId.Equals(null); response.Should().BeEquivalentTo(mashReferral.ToDomain()); }
public void UpdatingMashReferralThrowsWorkerNotFoundExceptionWhenWorkerIsNotFoundUsingEmail() { var workerEmail = _faker.Person.Email; var request = TestHelpers.CreateUpdateMashReferral(updateType: "ASSIGN-WORKER", workerEmail: workerEmail); request.WorkerId = null; var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); Action act = () => _mashReferralGateway.UpdateReferral(request, mashReferral.Id); act.Should().Throw <WorkerNotFoundException>() .WithMessage($"Worker with email {workerEmail} not found"); }
public void IfPersonWithTheIdProvidedDoesNotExistThrowsNotFoundException() { var nonExistingPersonId = _faker.Random.Int(); var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, "CONTACT"); var mashResident = MashResidentHelper.SaveMashResidentToDatabase(DatabaseContext, mashReferral.Id); var request = TestHelpers.CreateMashResidentUpdateRequest(nonExistingPersonId); Action act = () => _mashReferralGateway.UpdateMashResident(request, mashResident.Id); act.Should().Throw <PersonNotFoundException>() .WithMessage($"Person with id {nonExistingPersonId} not found"); }
public void GetMashReferralsWithNoQueryReturnsAllMashReferrals() { var query = TestHelpers.CreateQueryMashReferral(); query.Id = null; query.WorkerEmail = null; const int numberOfMashReferralsToAdd = 5; for (var i = 0; i < numberOfMashReferralsToAdd; i++) { MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); } var response = _mashReferralGateway.GetReferralsUsingQuery(query); response.ToList().Count.Should().Be(numberOfMashReferralsToAdd); }
public void WhenMashResidentWithLinkedPersonExistAndUpdateTypeIsUnLinkPersonUpdatesSocialCareIdValueOnMashResident() { var personMatch = TestHelpers.CreatePerson(); DatabaseContext.Persons.Add(personMatch); DatabaseContext.SaveChanges(); var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, "CONTACT"); var mashResident = MashResidentHelper.SaveMashResidentToDatabase(DatabaseContext, mashReferral.Id, personMatch.Id); mashResident.SocialCareId.Should().NotBeNull(); var request = TestHelpers.CreateMashResidentUpdateRequest(personMatch.Id, updateType: "UNLINK-PERSON"); var response = _mashReferralGateway.UpdateMashResident(request, mashResident.Id); response.Should().BeEquivalentTo(mashResident.ToDomain()); response.SocialCareId.Should().BeNull(); }
public void WhenMashResidentAndMatchingPersonExistUpdatesSocialCareIdValueOnMashResident() { var personMatch = TestHelpers.CreatePerson(); DatabaseContext.Persons.Add(personMatch); DatabaseContext.SaveChanges(); var mashReferral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, "CONTACT"); var mashResident = MashResidentHelper.SaveMashResidentToDatabase(DatabaseContext, mashReferral.Id, null); mashResident.SocialCareId.Should().BeNull(); var request = TestHelpers.CreateMashResidentUpdateRequest(personMatch.Id); var response = _mashReferralGateway.UpdateMashResident(request, mashResident.Id); response.Should().BeEquivalentTo(mashResident.ToDomain()); response.SocialCareId.Should().Be(personMatch.Id); }
public void GetReferralUsingIdReturnsDomainMashReferral() { const long referralId = 1L; var referral = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext, mashReferralId: referralId); for (var i = 0; i < 8; i++) { MashResidentHelper.SaveMashResidentToDatabase(DatabaseContext, referralId); } var response = _mashReferralGateway.GetReferralUsingId(referral.Id); response.Should().BeEquivalentTo(referral.ToDomain(), options => { options.Using <DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1000)).WhenTypeIs <DateTime>(); return(options); }); }
public void GetMashReferralsWithEmailQueryReturnsReferralsMatchingEmail() { const int numberOfMashReferralsToAdd = 4; var exisitingDbReferall = MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); string workerEmail = exisitingDbReferall.Worker !.Email; for (var i = 0; i < numberOfMashReferralsToAdd; i++) { MashReferralHelper.SaveMashReferralToDatabase(DatabaseContext); } var query = TestHelpers.CreateQueryMashReferral(null, workerEmail); query.Id = null; var response = _mashReferralGateway.GetReferralsUsingQuery(query).ToList(); response.Count.Should().Be(1); response[0].Worker !.Email.Should().Equals(workerEmail); }