public async Task FirstNameLastNameQueryParametersWildcardSearchReturnsMatchingResidentRecords()
        {
            var expectedResidentResponseOne   = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext, firstname: "ciasom", lastname: "tessellate");
            var expectedResidentResponseTwo   = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext, firstname: "ciasom", lastname: "shape");
            var expectedResidentResponseThree = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext);

            var response   = CallEndpointWithQueryString("?first_name=ciaso&last_name=sell");
            var statusCode = response.Result.StatusCode;

            statusCode.Should().Be(200);

            var convertedResponse = await DeserializeResponse(response.Result).ConfigureAwait(true);

            convertedResponse.Residents.Count.Should().Be(1);
            convertedResponse.Residents.Should().ContainEquivalentOf(expectedResidentResponseOne);
        }
        public async Task WithCursorAndLimitGivenWillCorrectlyPaginateResidentsReturned()
        {
            var allSavedEntities = Enumerable.Range(0, 17)
                                   .Select(r =>
                                           E2ETestsHelper
                                           .AddPersonWithRelatedEntitiesToDb(ResidentContactContext, r + 1))
                                   .ToList();

            var response = await CallEndpointWithQueryString("?limit=12&cursor=3").ConfigureAwait(true);

            response.StatusCode.Should().Be(200);

            var returnedTenancies = await DeserializeResponse(response).ConfigureAwait(true);

            returnedTenancies.Residents.Should().BeEquivalentTo(allSavedEntities.Skip(3).Take(12));
        }
        public async Task GetResidentInformationByIdReturn200()
        {
            var residentId       = _fixture.Create <int>();
            var expectedResponse = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext, residentId);
            var uri        = new Uri($"api/v1/contacts/{residentId}", UriKind.Relative);
            var response   = Client.GetAsync(uri);
            var statuscode = response.Result.StatusCode;

            statuscode.Should().Be(200);

            var content       = response.Result.Content;
            var stringContent = await content.ReadAsStringAsync().ConfigureAwait(true);

            var convertedResponse = JsonConvert.DeserializeObject <ResidentResponse>(stringContent);

            convertedResponse.Should().BeEquivalentTo(expectedResponse);
        }
        public async Task WithNoCursorAndLimitWillReturnTheFirstPageOfResidentsWithTheNextCursor()
        {
            var allSavedResidents = Enumerable.Range(0, 25)
                                    .Select(r =>
                                            E2ETestsHelper
                                            .AddPersonWithRelatedEntitiesToDb(ResidentContactContext, r + 1))
                                    .ToList();

            var response = await CallEndpointWithQueryString().ConfigureAwait(true);

            response.StatusCode.Should().Be(200);

            var returnedResidents = await DeserializeResponse(response).ConfigureAwait(true);

            returnedResidents.Residents.Should().BeEquivalentTo(allSavedResidents.Take(20));

            returnedResidents.NextCursor.Should().Be("20");
        }
        public async Task IfNoQueryParametersReturnsAllResidentRecords()
        {
            var expectedResidentResponseOne   = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext);
            var expectedResidentResponseTwo   = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext);
            var expectedResidentResponseThree = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext);

            var response = CallEndpointWithQueryString();

            var statusCode = response.Result.StatusCode;

            statusCode.Should().Be(200);

            var convertedResponse = await DeserializeResponse(response.Result).ConfigureAwait(true);

            convertedResponse.Residents.Should().ContainEquivalentOf(expectedResidentResponseOne);
            convertedResponse.Residents.Should().ContainEquivalentOf(expectedResidentResponseTwo);
            convertedResponse.Residents.Should().ContainEquivalentOf(expectedResidentResponseThree);
        }
        public async Task Returns201IfNewContactRecordIsCreatedForResident()
        {
            var contactRequest = new ResidentContact
            {
                SubtypeId = _faker.Random.Int(1, 50),
                TypeId    = _faker.Random.Int(1, 50),
                Value     = "test@test",
                Active    = _faker.Random.Bool(),
                Default   = _faker.Random.Bool()
            };


            var resident = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext,
                                                                           contactTypeLookupId: contactRequest.TypeId,
                                                                           contactSubTypeLookupId: contactRequest.SubtypeId);

            contactRequest.ResidentId = resident.Id;
            var response = await CallPostEndpointWithRequest(contactRequest).ConfigureAwait(true);

            response.StatusCode.Should().Be(201);
            CheckContactHasBeSavedInDatabaseForResidentId(resident.Id, contactRequest);
        }
        public async Task CanCreateANewContactDetailGivenAnExternalContactIdToIdentifyTheResident()
        {
            var contactRequest = new ResidentContact
            {
                SubtypeId = _faker.Random.Int(1, 50),
                TypeId    = _faker.Random.Int(1, 50),
                Value     = "test@test",
                Active    = _faker.Random.Bool(),
                Default   = _faker.Random.Bool()
            };


            var resident = E2ETestsHelper.AddPersonWithRelatedEntitiesToDb(ResidentContactContext,
                                                                           contactTypeLookupId: contactRequest.TypeId,
                                                                           contactSubTypeLookupId: contactRequest.SubtypeId);

            contactRequest.NccContactId = E2ETestsHelper.AddCrmContactIdForResidentId(ResidentContactContext, resident.Id).ExternalIdValue;

            var response = await CallPostEndpointWithRequest(contactRequest).ConfigureAwait(true);

            response.StatusCode.Should().Be(201);
            CheckContactHasBeSavedInDatabaseForResidentId(resident.Id, contactRequest);
        }