Exemple #1
0
        public void WhenThereAreNoRelationshipsReturnsEmptyListForPersonalRelationships()
        {
            var(person, _, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, withRelationship: false);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.Should().BeEmpty();
        }
Exemple #2
0
        public void WhenIncludeEndedRelationshipsIsTrueReturnsPersonalRelationships()
        {
            var(person, _, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, hasEnded: true);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id, includeEndedRelationships: true);

            response.PersonalRelationships.Should().NotBeEmpty();
        }
Exemple #3
0
        public void WhenThereIsARelationshipWithDetailsReturnsTheDetails()
        {
            var(person, _, _, _, personalRelationshipDetail) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, details: "Emergency contact");

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.FirstOrDefault().Details.Details.Should().BeEquivalentTo(personalRelationshipDetail.Details);
        }
Exemple #4
0
        public void WhenThereIsARelationshipReturnsTheDescriptionOfThePersonalRelationshipType()
        {
            var(person, _, _, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, relationshipType: "stepParent");

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);
            var personalRelationshipTypeInResponse = response.PersonalRelationships.FirstOrDefault().Type;

            personalRelationshipTypeInResponse.Description.Should().Equals(personalRelationshipType.Description);
        }
Exemple #5
0
        public void WhenMatchingIDReturnsRelationship()
        {
            var(person, _, personalRelationship, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var response = _databaseGateway.GetPersonalRelationshipById(personalRelationship.Id);

            response.Id.Should().Be(personalRelationship.Id);
            response.PersonId.Should().Be(person.Id);
        }
Exemple #6
0
        public void WhenThereIsARelationshipReturnsThePersonalRelationship()
        {
            var(person, _, personalRelationship, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.FirstOrDefault().Id.Should().Be(personalRelationship.Id);
            response.PersonalRelationships.FirstOrDefault().PersonId.Should().Be(personalRelationship.PersonId);
            response.PersonalRelationships.FirstOrDefault().OtherPersonId.Should().Be(personalRelationship.OtherPersonId);
            response.PersonalRelationships.FirstOrDefault().TypeId.Should().Be(personalRelationship.TypeId);
        }
Exemple #7
0
        public void WhenThereIsARelationshipReturnsTheDetailsOfTheOtherPerson()
        {
            var(person, otherPerson, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);
            var otherPersonInResponse = response.PersonalRelationships.FirstOrDefault().OtherPerson;

            otherPersonInResponse.Id.Should().Be(otherPerson.Id);
            otherPersonInResponse.FirstName.Should().Be(otherPerson.FirstName);
            otherPersonInResponse.LastName.Should().Be(otherPerson.LastName);
            otherPersonInResponse.Gender.Should().Be(otherPerson.Gender);
        }
Exemple #8
0
        public void WhenThereAreMultipleRelationshipsReturnsAllRelevantPersonalRelationships()
        {
            var(person, _, _, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);
            var anotherPerson          = TestHelpers.CreatePerson();
            var anotherRelationship    = PersonalRelationshipsHelper.CreatePersonalRelationship(person, anotherPerson, personalRelationshipType, id: 1);
            var andAnotherPerson       = TestHelpers.CreatePerson();
            var andAnotherRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(person, andAnotherPerson, personalRelationshipType, hasEnded: true, id: 2);

            DatabaseContext.Persons.Add(anotherPerson);
            DatabaseContext.Persons.Add(andAnotherPerson);
            DatabaseContext.PersonalRelationships.Add(anotherRelationship);
            DatabaseContext.PersonalRelationships.Add(andAnotherRelationship);
            DatabaseContext.SaveChanges();

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.Should().HaveCount(2);
        }
Exemple #9
0
        public void WhenThereAreRelationshipsDoesNotReturnRelationshipsAgainstPersonsMarkedForDeletion()
        {
            var(person, _, _, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var anotherPerson       = TestHelpers.CreatePerson();
            var anotherRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(person, anotherPerson, personalRelationshipType, id: 1);

            var personMarkedForDeletion = TestHelpers.CreatePerson();

            personMarkedForDeletion.MarkedForDeletion = true;

            var andAnotherRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(person, personMarkedForDeletion, personalRelationshipType, id: 2);

            DatabaseContext.Persons.Add(anotherPerson);
            DatabaseContext.Persons.Add(personMarkedForDeletion);
            DatabaseContext.PersonalRelationships.Add(anotherRelationship);
            DatabaseContext.PersonalRelationships.Add(andAnotherRelationship);
            DatabaseContext.SaveChanges();

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.Should().HaveCount(2);
        }
        public void SetsTheMarkedForDeletionFlagToFalseForPersonAndRelatedEntitiesAndRemovesTheRecordFromDeletedPersonRecordTable()
        {
            //person to be restored, new master record and relationship
            var(deletedPerson, newMasterPersonRecord, personalRelationship, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            //address
            var address = DatabaseGatewayHelper.CreateAddressDatabaseEntity(personId: deletedPerson.Id);

            address.MarkedForDeletion = true;
            DatabaseContext.Addresses.Add(address);

            //telephone numbers
            var telephoneNumber = DatabaseGatewayHelper.CreatePhoneNumberEntity(personId: deletedPerson.Id);

            address.MarkedForDeletion = true;
            DatabaseContext.PhoneNumbers.Add(telephoneNumber);

            //other names
            var otherName = DatabaseGatewayHelper.CreatePersonOtherNameDatabaseEntity(personId: deletedPerson.Id);

            otherName.MarkedForDeletion = true;
            DatabaseContext.PersonOtherNames.Add(otherName);

            //allocations
            var allocation = TestHelpers.CreateAllocation(personId: (int)deletedPerson.Id);

            allocation.MarkedForDeletion = true;
            DatabaseContext.Allocations.Add(allocation);

            //warning notes
            var warningNote = TestHelpers.CreateWarningNote(personId: deletedPerson.Id);

            warningNote.MarkedForDeletion = true;
            DatabaseContext.WarningNotes.Add(warningNote);

            //inverse relationship (type not handled for simplicity)
            var inversePersonalRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(newMasterPersonRecord, deletedPerson, personalRelationshipType);

            inversePersonalRelationship.MarkedForDeletion = true;
            DatabaseContext.PersonalRelationships.Add(inversePersonalRelationship);

            //record marked as soft deleted
            DatabaseContext.DeletedPersonRecords.Add(new DeletedPersonRecord()
            {
                DeletedId = deletedPerson.Id,
                MasterId  = newMasterPersonRecord.Id
            });

            DatabaseContext.SaveChanges();

            //TODO: wrap into transaction when running manually (BEGIN; <SCRIPT> END;)
            //TODO: this is designed to be run against individual IDs. Replace the {deletedPerson.Id} with appropriate MosaicId (long)
            DatabaseContext.Database.ExecuteSqlInterpolated($@"
                   UPDATE dbo.dm_persons SET marked_for_deletion = false WHERE person_id = {deletedPerson.Id};
                   UPDATE dbo.dm_addresses SET marked_for_deletion = false WHERE person_id = {deletedPerson.Id};
                   UPDATE dbo.dm_telephone_numbers SET marked_for_deletion = false WHERE person_id = {deletedPerson.Id};
                   UPDATE dbo.sccv_person_other_name SET marked_for_deletion = false WHERE person_id = {deletedPerson.Id};
                   UPDATE dbo.sccv_allocations_combined SET marked_for_deletion = false WHERE mosaic_id = {deletedPerson.Id};
                   UPDATE dbo.sccv_warning_note SET marked_for_deletion = false WHERE person_id = {deletedPerson.Id};
                   UPDATE dbo.sccv_personal_relationship SET marked_for_deletion = false WHERE fk_person_id = {deletedPerson.Id};
                   UPDATE dbo.sccv_personal_relationship SET marked_for_deletion = false WHERE fk_other_person_id = {deletedPerson.Id};
                   DELETE from dbo.sccv_deleted_person_record where deleted_person_id = {deletedPerson.Id};
            ");

            DatabaseContext.Persons.First(x => x.Id == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.Addresses.First(x => x.PersonId == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.PhoneNumbers.First(x => x.PersonId == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.PersonOtherNames.First(x => x.PersonId == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.Allocations.First(x => x.PersonId == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.WarningNotes.First(x => x.PersonId == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.PersonalRelationships.First(x => x.PersonId == deletedPerson.Id).MarkedForDeletion.Should().BeFalse();
            DatabaseContext.PersonalRelationships.First(x => x.OtherPersonId == newMasterPersonRecord.Id).MarkedForDeletion.Should().BeFalse();

            DatabaseContext.DeletedPersonRecords.Any(x => x.DeletedId == deletedPerson.Id).Should().BeFalse();
        }
Exemple #11
0
        public void SetsTheMarkedForDeletionFlagForPersonAndRelatedEntitiesAndUpdatesTheDeletedPersonRecordsTableWithCorrectRecords()
        {
            //person to be deleted, new master record and relationship
            var(personToBeDeleted, newMasterPersonRecord, personalRelationship, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            //address
            var address = DatabaseGatewayHelper.CreateAddressDatabaseEntity(personId: personToBeDeleted.Id);

            DatabaseContext.Addresses.Add(address);

            //telephone numbers
            var telephoneNumber = DatabaseGatewayHelper.CreatePhoneNumberEntity(personId: personToBeDeleted.Id);

            DatabaseContext.PhoneNumbers.Add(telephoneNumber);

            //other names
            var otherName = DatabaseGatewayHelper.CreatePersonOtherNameDatabaseEntity(personId: personToBeDeleted.Id);

            DatabaseContext.PersonOtherNames.Add(otherName);

            //allocations
            var allocation = TestHelpers.CreateAllocation(personId: (int)personToBeDeleted.Id);

            DatabaseContext.Allocations.Add(allocation);

            //warning notes
            var warningNote = TestHelpers.CreateWarningNote(personId: personToBeDeleted.Id);

            DatabaseContext.WarningNotes.Add(warningNote);

            //inverse relationship (type not handled for simplicity)
            var inversePersonalRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(newMasterPersonRecord, personToBeDeleted, personalRelationshipType);

            DatabaseContext.PersonalRelationships.Add(inversePersonalRelationship);

            //record marked for deletion
            DatabaseContext.PersonRecordsToBeDeleted.Add(new PersonRecordToBeDeleted()
            {
                IdToDelete = personToBeDeleted.Id,
                MasterId   = newMasterPersonRecord.Id
            });

            DatabaseContext.SaveChanges();

            DatabaseContext.Database.ExecuteSqlInterpolated(_queryUnderTest);

            //flags
            DatabaseContext.Persons.First(x => x.Id == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.Addresses.First(x => x.PersonId == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.PhoneNumbers.First(x => x.PersonId == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.PersonOtherNames.First(x => x.PersonId == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.Allocations.First(x => x.PersonId == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.WarningNotes.First(x => x.PersonId == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.PersonalRelationships.First(x => x.PersonId == personToBeDeleted.Id).MarkedForDeletion.Should().BeTrue();
            DatabaseContext.PersonalRelationships.First(x => x.OtherPersonId == newMasterPersonRecord.Id).MarkedForDeletion.Should().BeTrue();

            //record in deleted person record table
            var expectedDeletedPersonRecordEntry = new DeletedPersonRecord()
            {
                DeletedId = personToBeDeleted.Id,
                MasterId  = newMasterPersonRecord.Id,
                Timestamp = DateTime.Now.ToUniversalTime()
            };

            DatabaseContext.DeletedPersonRecords.First(x => x.DeletedId == personToBeDeleted.Id).MasterId.Should().Be(expectedDeletedPersonRecordEntry.MasterId);
            DatabaseContext.DeletedPersonRecords.First(x => x.DeletedId == personToBeDeleted.Id).DeletedId.Should().Be(expectedDeletedPersonRecordEntry.DeletedId);
            DatabaseContext.DeletedPersonRecords.First(x => x.DeletedId == personToBeDeleted.Id).Timestamp.Should().BeCloseTo(expectedDeletedPersonRecordEntry.Timestamp, precision: 5000);
        }