Ejemplo n.º 1
0
        public void GetResidentByIdReturnsPhoneContactDetailsWithPhoneType()
        {
            var person      = AddPersonRecordToDatabase();
            var tenure      = AddTenureTypeLookupToDatabase();
            var tenancy     = AddTenancyAgreementToDatabase(person.HouseRef, tenureTypeId: tenure.UhTenureTypeId);
            var contactLink = AddContactLinkForPersonToDatabase(tenancy.TagRef, person.PersonNo);

            var phone = TestHelper.CreateDatabaseTelephoneNumberForPersonId(contactLink.ContactID);

            var type = PhoneType.X;

            phone.Type = type.ToString();

            UHContext.TelephoneNumbers.Add(phone);
            UHContext.SaveChanges();

            var expectedPhoneNumberList = new List <Phone>
            {
                new Phone
                {
                    PhoneNumber  = phone.Number,
                    Type         = PhoneType.X,
                    LastModified = phone.DateCreated
                }
            };

            var response = _classUnderTest.GetResidentById(person.HouseRef, person.PersonNo);

            response.PhoneNumber.Should().BeEquivalentTo(expectedPhoneNumberList);
        }
Ejemplo n.º 2
0
        private TelephoneNumber AddTelephoneNumberToDatabase(int contactLinkId)
        {
            var telephone = TestHelper.CreateDatabaseTelephoneNumberForPersonId(contactLinkId);

            UHContext.TelephoneNumbers.Add(telephone);
            UHContext.SaveChanges();
            return(telephone);
        }
Ejemplo n.º 3
0
        private EmailAddresses AddEmailAddressToDatabase(int contactLinkId)
        {
            var databaseEmailEntity = TestHelper.CreateDatabaseEmailForPerson(contactLinkId);

            UHContext.EmailAddresses.Add(databaseEmailEntity);
            UHContext.SaveChanges();
            return(databaseEmailEntity);
        }
Ejemplo n.º 4
0
        private Address AddAddressRecordToDatabase(string houseRef, string postcode = null, string address1 = null)
        {
            var address = TestHelper.CreateDatabaseAddressForPersonId(houseRef, postcode, address1);

            UHContext.Addresses.Add(address);
            UHContext.SaveChanges();
            return(address);
        }
Ejemplo n.º 5
0
        private Person AddPersonRecordToDatabase(string firstname = null, string lastname = null, string houseRef = null, int?personNo = null)
        {
            var databaseEntity = TestHelper.CreateDatabasePersonEntity(firstname, lastname, houseRef, personNo);

            UHContext.Persons.Add(databaseEntity);
            UHContext.SaveChanges();
            return(databaseEntity);
        }
Ejemplo n.º 6
0
        private ContactLink AddContactLinkForPersonToDatabase(string tagRef, int?personNumber)
        {
            var contactLink = TestHelper.CreateDatabaseContactLinkForPerson(tagRef, personNumber);

            UHContext.ContactLinks.Add(contactLink);
            UHContext.SaveChanges();

            return(contactLink);
        }
Ejemplo n.º 7
0
        private UhTenureType AddTenureTypeLookupToDatabase(string tenureTypeId = null)
        {
            var tenureTypeLookup = TestHelper.CreateTenureType();

            tenureTypeLookup.UhTenureTypeId = tenureTypeId ?? tenureTypeLookup.UhTenureTypeId;
            UHContext.UhTenure.Add(tenureTypeLookup);
            UHContext.SaveChanges();
            return(tenureTypeLookup);
        }
Ejemplo n.º 8
0
        public void CanGetADatabaseEntity()
        {
            var databaseEntity = TestHelper.CreateDatabasePersonEntity();

            UHContext.Add(databaseEntity);
            UHContext.SaveChanges();

            var result = UHContext.Persons.ToList().FirstOrDefault();

            result.Should().BeEquivalentTo(databaseEntity);
        }
Ejemplo n.º 9
0
        private TenancyAgreement AddTenancyAgreementToDatabase(string houseReference, string tagRef = null,
                                                               string tenureTypeId = null, bool isTerminated = false)
        {
            var tenancyDatabaseEntity = TestHelper.CreateDatabaseTenancyEntity(houseReference);

            tenancyDatabaseEntity.IsTerminated   = isTerminated;
            tenancyDatabaseEntity.TagRef         = tagRef ?? tenancyDatabaseEntity.TagRef;
            tenancyDatabaseEntity.UhTenureTypeId = tenureTypeId ?? tenancyDatabaseEntity.UhTenureTypeId;

            UHContext.TenancyAgreements.Add(tenancyDatabaseEntity);
            UHContext.SaveChanges();
            return(tenancyDatabaseEntity);
        }
Ejemplo n.º 10
0
        public void GetResidentByIdReturnsTheUPRNInTheResponse()
        {
            var person  = AddPersonRecordToDatabase();
            var address = AddAddressRecordToDatabase(person.HouseRef);
            var tenure  = AddTenureTypeLookupToDatabase();
            var tenancy = AddTenancyAgreementToDatabase(person.HouseRef, tenureTypeId: tenure.UhTenureTypeId);

            UHContext.Contacts.Add(TestHelper.CreateContactRecordFromTagRef(tenancy.TagRef));
            UHContext.SaveChanges();

            var response = _classUnderTest.GetResidentById(person.HouseRef, person.PersonNo);

            response.UPRN.Should().Be(address.UPRN);
        }
Ejemplo n.º 11
0
        public void GetResidentByIdReturnsTheContactKey()
        {
            var person  = AddPersonRecordToDatabase();
            var tenure  = AddTenureTypeLookupToDatabase();
            var tenancy = AddTenancyAgreementToDatabase(person.HouseRef, tenureTypeId: tenure.UhTenureTypeId);
            var contact = TestHelper.CreateContactRecordFromTagRef(tenancy.TagRef);

            var addedEntity = UHContext.Contacts.Add(contact);

            UHContext.SaveChanges();

            var response = _classUnderTest.GetResidentById(person.HouseRef, person.PersonNo);

            response.ContactKey.Should().Be(addedEntity.Entity.ContactKey.ToString());
        }
Ejemplo n.º 12
0
        public void GetAllResidentsReturnsTheContactKeyForEachResult()
        {
            var person = AddPersonRecordToDatabase();

            AddAddressRecordToDatabase(person.HouseRef);
            var tenure  = AddTenureTypeLookupToDatabase();
            var tenancy = AddTenancyAgreementToDatabase(person.HouseRef, tenureTypeId: tenure.UhTenureTypeId);

            AddContactLinkForPersonToDatabase(tenancy.TagRef, person.PersonNo);

            var contact = UHContext.Contacts.Add(TestHelper.CreateContactRecordFromTagRef(tenancy.TagRef));

            UHContext.SaveChanges();

            var response = _classUnderTest.GetAllResidents(null, 10).Result;

            response.First().ContactKey.Should().BeEquivalentTo(contact.Entity.ContactKey.ToString());
        }
Ejemplo n.º 13
0
        public static ResidentInformation AddPersonWithRelatedEntitiesToDb(UHContext context, string houseRef = null,
                                                                           int?personNo        = null, string firstname    = null, string lastname   = null, string postcode = null,
                                                                           string addressLines = null, string tenureTypeId = null, bool isTerminated = false)
        {
            //create person record
            var person = TestHelper.CreateDatabasePersonEntity(firstname, lastname);

            person.HouseRef = houseRef ?? person.HouseRef;
            person.PersonNo = personNo ?? person.PersonNo;

            var addedPerson = context.Persons.Add(person);

            context.SaveChanges();

            //create tenure record
            var tenure = TestHelper.CreateTenureType();

            tenure.UhTenureTypeId = tenureTypeId ?? tenure.UhTenureTypeId;
            context.UhTenure.Add(tenure);
            context.SaveChanges();

            //create address, and tenancy entities with tenuretypeId
            var address          = TestHelper.CreateDatabaseAddressForPersonId(addedPerson.Entity.HouseRef, address1: addressLines, postcode: postcode);
            var tenancyAgreement = TestHelper.CreateDatabaseTenancyEntity(addedPerson.Entity.HouseRef, tenure.UhTenureTypeId);

            tenancyAgreement.IsTerminated = isTerminated;
            tenancyAgreement.TagRef       = houseRef ?? tenancyAgreement.TagRef;

            //create contact Link record
            var contactLink  = TestHelper.CreateDatabaseContactLinkForPerson(tenancyAgreement.TagRef, addedPerson.Entity.PersonNo);
            var addedContact = context.ContactLinks.Add(contactLink);

            context.SaveChanges();
            var phone   = TestHelper.CreateDatabaseTelephoneNumberForPersonId(addedContact.Entity.ContactID);
            var email   = TestHelper.CreateDatabaseEmailForPerson(addedContact.Entity.ContactID);
            var contact = TestHelper.CreateContactRecordFromTagRef(tenancyAgreement.TagRef);

            context.TenancyAgreements.Add(tenancyAgreement);
            context.Addresses.Add(address);
            context.TelephoneNumbers.Add(phone);
            context.EmailAddresses.Add(email);
            context.Contacts.Add(contact);
            context.SaveChanges();

            return(new ResidentInformation
            {
                HouseReference = person.HouseRef,
                PersonNumber = person.PersonNo,
                TenancyReference = tenancyAgreement.TagRef,
                TenureType = $"{tenure.UhTenureTypeId}: {tenure?.Description}",
                FirstName = person.FirstName,
                LastName = person.LastName,
                NiNumber = person.NINumber,
                Uprn = address.UPRN,
                HousingWaitingListContactKey = contact.ContactKey.ToString(),
                PhoneNumbers =
                    new List <Phone>
                {
                    new Phone
                    {
                        PhoneNumber = phone.Number,
                        PhoneType = phone.Type,
                        LastModified = phone.DateCreated.ToString("O", CultureInfo.InvariantCulture)
                    }
                },
                EmailAddresses = new List <Email>
                {
                    new Email
                    {
                        EmailAddress = email.EmailAddress,
                        LastModified = email.DateModified.ToString("O", CultureInfo.InvariantCulture)
                    }
                },
                Address = new Address
                {
                    PropertyRef = address.PropertyRef,
                    AddressLine1 = address.AddressLine1,
                    Postcode = address.PostCode
                },
                DateOfBirth = person.DateOfBirth.ToString("O", CultureInfo.InvariantCulture)
            });
        }