public void GivenSearchParametersStatusFilterUpperCaseMatchingOrganisationsGetReturned()
        {
            var organisations = EntityHelpers.CreateOrganisations(10).ToList();
            var orgToFind     = EntityHelpers.CreateOrganisation();

            orgToFind.Status = "published";
            organisations.Add(orgToFind);
            DatabaseContext.AddRange(organisations);
            DatabaseContext.SaveChanges();
            var searchParams = new OrganisationSearchRequest();

            searchParams.Search    = orgToFind.Name;
            searchParams.Sort      = "Name";
            searchParams.Status    = "PUBLISHED";
            searchParams.Direction = SortDirection.Asc.ToString();
            var gatewayResult = _classUnderTest.SearchOrganisations(searchParams).Result;

            gatewayResult.Should().NotBeNull();
            gatewayResult.First().Should().BeEquivalentTo(orgToFind, options =>
            {
                options.Excluding(ex => ex.ReviewerU);
                options.Excluding(ex => ex.Services);
                options.Excluding(ex => ex.UserOrganisations);
                return(options);
            });
        }
        public async Task SearchOrganisationBySearchParamsReturnsOrganisationsInTheSortOrderSpecified()
        {
            var session = EntityHelpers.CreateSession("Admin");

            DatabaseContext.Sessions.Add(session);
            Client.DefaultRequestHeaders.Add("Cookie", $"access_token={session.Payload}");
            var rand          = new Random();
            var organisations = EntityHelpers.CreateOrganisations(10).ToList();
            var searchParam   = Randomm.Word();
            var first         = rand.Next(10, 20);
            var second        = rand.Next(20, 30);

            organisations[5].Name = searchParam + first;
            organisations[3].Name = searchParam + second;
            DatabaseContext.Organisations.AddRange(organisations);
            DatabaseContext.SaveChanges();
            var requestUri = new Uri($"api/v1/organisations?search={searchParam}&sort=name&direction=asc", UriKind.Relative);
            var response   = await Client.GetAsync(requestUri).ConfigureAwait(true);

            response.StatusCode.Should().Be(200);
            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <OrganisationResponseList>(stringResponse);

            deserializedBody.Should().NotBeNull();
            deserializedBody.Organisations[0].Name.Should().BeEquivalentTo(organisations[5].Name);
            deserializedBody.Organisations[1].Name.Should().BeEquivalentTo(organisations[3].Name);
        }
        public void GivenSearchParametersStatusFilterNoMatchingOrganisationsGetReturned()
        {
            var organisations = EntityHelpers.CreateOrganisations(10).ToList();
            var orgToFind     = EntityHelpers.CreateOrganisation();

            orgToFind.Status = "published";
            organisations.Add(orgToFind);
            DatabaseContext.AddRange(organisations);
            DatabaseContext.SaveChanges();
            var searchParams = new OrganisationSearchRequest();

            searchParams.Search    = orgToFind.Name;
            searchParams.Sort      = "Name";
            searchParams.Status    = "rejected";
            searchParams.Direction = SortDirection.Asc.ToString();
            var gatewayResult = _classUnderTest.SearchOrganisations(searchParams).Result;

            gatewayResult.Should().NotBeNull();
            gatewayResult.Count.Should().Be(0);
        }