Example #1
0
        public async void SearchHospitals_Should_Call_IApiClient_Send()
        {
            Func <HttpResponseMessage, Task <HospitalsResponse> > mapper = null;
            var request = new HttpRequestMessage();

            _requestProvider.CreateGetRequest(Arg.Any <string>()).Returns(request);
            await _apiClient.Send(Arg.Any <HttpRequestMessage>(), Arg.Do <Func <HttpResponseMessage, Task <HospitalsResponse> > >(a => mapper = a));

            await _repository.SearchHospitals(new SearchHospitalsRequest { PageIndex = 0 });

            await _apiClient.Received(1).Send <HospitalsResponse>(request, Arg.Any <Func <HttpResponseMessage, Task <HospitalsResponse> > >());

            var expected = new HospitalsResponse
            {
                _embedded = new HospitalsObject
                {
                    Hospitals = new [] { new HospitalObject() }
                },
                Page = new PageObject {
                    Number = 123
                }
            };
            var body = JObject.FromObject(expected);

            var response = new HttpResponseMessage();

            response.Content = new StringContent(body.ToString());
            var actual = await mapper(response);

            actual.Should().BeEquivalentTo(expected);

            request.Dispose();
        }
Example #2
0
        public void ToSearchHospitalResponse_Should_Map_Correctly()
        {
            var source = new HospitalsResponse
            {
                _embedded = new HospitalsObject
                {
                    Hospitals = new []
                    {
                        new HospitalObject {
                            Id = 1
                        },
                        new HospitalObject {
                            Id = 2
                        },
                        new HospitalObject {
                            Id = 3
                        }
                    }
                },
                Page = new PageObject {
                    Number = 123
                }
            };

            var actual = source.ToSearchHospitalsResponse();

            actual.Data.Should().HaveSameCount(source._embedded.Hospitals);
            actual.CurrentPageIndex.Should().Be(source.Page.Number);
        }
Example #3
0
        public void ToSearchHospitalResponse_Should_Handle_Null()
        {
            HospitalsResponse source = null;

            var actual = source.ToSearchHospitalsResponse();

            actual.Should().BeNull();
        }
Example #4
0
        public void ToSearchHospitalResponse_Should_Handle_Null_Embedded()
        {
            var source = new HospitalsResponse();

            var actual = source.ToSearchHospitalsResponse();

            actual.Should().BeNull();
        }
Example #5
0
        public static SearchHospitalsResponse ToSearchHospitalsResponse(this HospitalsResponse source)
        {
            if (source == null || source._embedded == null)
            {
                return(null);
            }

            var response = new SearchHospitalsResponse
            {
                Data = source._embedded.Hospitals.ToHospitalDetailsList()
            };

            return(response.PopulatePageDetails(source.Page));
        }
Example #6
0
        public async void SearchHospitals_Should_Call_IRequestProvider_CreateGetRequest_Until_There_Are_No_More_Pages()
        {
            var request = new HttpRequestMessage();

            _requestProvider.CreateGetRequest(Arg.Any <string>()).Returns(request);

            var embedded = new HospitalsObject
            {
                Hospitals = new []
                {
                    new HospitalObject {
                    }
                }
            };
            var withNext = new LinksObject {
                Next = new LinkObject {
                    Href = "nextUrl"
                }
            };
            var withoutNext = new LinksObject {
                Next = new LinkObject()
            };
            var response1 = new HospitalsResponse
            {
                _embedded = embedded,
                _links    = withNext
            };
            var response2 = new HospitalsResponse
            {
                _embedded = embedded,
                _links    = withNext
            };
            var response3 = new HospitalsResponse
            {
                _embedded = embedded,
                _links    = withoutNext
            };

            _apiClient.Send(Arg.Any <HttpRequestMessage>(), Arg.Any <Func <HttpResponseMessage, Task <HospitalsResponse> > >()).Returns(response1, response2, response3);

            var url = $"{_database}/hospitals";

            var search = new SearchHospitalsRequest();
            await _repository.SearchHospitals(search);

            _requestProvider.Received(1).CreateGetRequest(url);
            _requestProvider.Received(2).CreateGetRequest(withNext.Next.Href);

            request.Dispose();
        }
Example #7
0
        public async void SearchHospitals_Should_Call_Return_Correctly()
        {
            var request = new HttpRequestMessage();

            _requestProvider.CreateGetRequest(Arg.Any <string>()).Returns(request);

            var response = new HospitalsResponse
            {
                _embedded = new HospitalsObject
                {
                    Hospitals = new []
                    {
                        new HospitalObject {
                            Id = 1
                        },
                        new HospitalObject {
                            Id = 2
                        },
                        new HospitalObject {
                            Id = 3
                        }
                    }
                },
                Page = new PageObject
                {
                    Number        = 123,
                    Size          = 456,
                    TotalElements = 789,
                    TotalPages    = 111
                }
            };
            var expected = response.ToSearchHospitalsResponse();

            _apiClient.Send(Arg.Any <HttpRequestMessage>(), Arg.Any <Func <HttpResponseMessage, Task <HospitalsResponse> > >()).Returns(response);

            var actual = await _repository.SearchHospitals(new SearchHospitalsRequest { PageIndex = 0 });

            actual.Should().BeEquivalentTo(expected);

            request.Dispose();
        }