public void GetMerchantsResultsForSearchCriterias(KeyValuePair <string, string>[] queryExpected,
                                                          MarketMerchantsTestSource.FunctionHolder getCall)
        {
            var httpClient = Substitute.For <IHttpClient>();
            var response   = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                                    resultCount : 1,
                                                    pageSize : 1,
                                                    offest : 0,
                                                    sort : 'timeAscending',
                                                    results : 
                                                    [
                                                        {
                                                            partnerReference : 'abs234',
                                                            merchantLegalName : 'merchant',
                                                            accessGranted : '2012-07-19T14:30:00+09:30',
                                                            lastTransaction : '2012-07-19T14:30:00+09:30',
                                                            scopes : 'test scope',
                                                            locations : 
                                                            [
                                                                {
	                                                                partnerReference : 'cbd230',
	                                                                tradingName : 'mertrade',
	                                                                judoId : '1235465'
	                                                            }
                                                            ]
                                                        }
                                                    ]
                                                }")
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var responseTask = new TaskCompletionSource <HttpResponseMessage>();

            responseTask.SetResult(response);

            httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task);

            var client = new Client(new Connection(httpClient,
                                                   DotNetLoggerFactory.Create,
                                                   "http://judo.com"));

            var judo = new JudoPayApi(DotNetLoggerFactory.Create, client);

            var results = getCall.Func(judo.Market.Merchants);

            Assert.IsNotNull(results);
            Assert.IsFalse(results.HasError);
            Assert.AreEqual(1, results.Response.ResultCount);
            Assert.AreEqual(1, results.Response.Results.Count());
// ReSharper disable PossibleNullReferenceException
            Assert.AreEqual(1, results.Response.Results.FirstOrDefault().Locations.Count());
            Assert.AreEqual("1235465", results.Response.Results.FirstOrDefault().Locations.FirstOrDefault().JudoId);
// ReSharper restore PossibleNullReferenceException
        }
        public void GetMerchantsForSearchCriterias(KeyValuePair <string, string>[] queryExpected,
                                                   MarketMerchantsTestSource.FunctionHolder getCall)
        {
            var httpClient = Substitute.For <IHttpClient>();
            var response   = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                                    resultCount : 1,
                                                    pageSize : 1,
                                                    offest : 0,
                                                    sort : 'timeAscending',
                                                    results : 
                                                    [
                                                        {
                                                            partnerReference : 'abs234',
                                                            merchantLegalName : 'merchant',
                                                            accessGranted : '2012-07-19T14:30:00+09:30',
                                                            lastTransaction : '2012-07-19T14:30:00+09:30',
                                                            scopes : 'test scope',
                                                            locations : 
                                                            [
                                                                {
	                                                                partnerReference : 'cbd230',
	                                                                tradingName : 'mertrade',
	                                                                judoId : '1235465'
	                                                            }
                                                            ]
                                                        }
                                                    ]
                                                }")
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var responseTask = new TaskCompletionSource <HttpResponseMessage>();

            responseTask.SetResult(response);

            httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task);

            var client = new Client(new Connection(httpClient,
                                                   DotNetLoggerFactory.Create,
                                                   "http://judo.com"));

            var judo = new JudoPayApi(DotNetLoggerFactory.Create, client);

            getCall.Func(judo.Market.Merchants);

            httpClient.Received().SendAsync(Arg.Any <HttpRequestMessage>());
            var calls = httpClient.ReceivedCalls();

// ReSharper disable once PossibleNullReferenceException
            var request = calls.FirstOrDefault(call => call.GetMethodInfo().Name == "SendAsync").
                          GetArguments().FirstOrDefault() as HttpRequestMessage;

            Assert.IsNotNull(request);

            var numberOfMatchingParameters = request.RequestUri.Query
                                             .Remove(0, 1)
                                             .Split('&').Select(kv =>
            {
                var keyValue = kv.Split('=');
                return(new KeyValuePair <string, string>(keyValue[0], keyValue[1]));
            }).Intersect(queryExpected).Count();

            Assert.AreEqual(queryExpected.Count(), numberOfMatchingParameters);
        }