Exemple #1
0
        private IEnumerable <Dtos.Product> _GetResults(HttpStatusCode statusCode)
        {
            MockHttpMessageHandler mockHttp = new MockHttpMessageHandler();

            mockHttp.When("http://localhost:24697/api/*").Respond(statusCode);
            HttpClient client = new HttpClient(mockHttp);

            client.BaseAddress = new Uri("http://localhost/api/");
            Dictionary <string, Uri> uri = new Dictionary <string, Uri> {
                { "Fake", new Uri("http://localhost:24697/api/Products") }
            };
            var service = new Repos.ProductRepo(client, uri);

            return(service.GetHttpProducts().Result);
        }
Exemple #2
0
        public void GetProductsHttp_OKWithContent_HttpProducts()
        {
            var mockHttp     = new MockHttpMessageHandler();
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK);

            fakeResponse.Content = new StringContent(JsonConvert.SerializeObject(mockData.HttpDataFake().Result), Encoding.UTF8, "application/json");
            mockHttp.When("http://localhost:24697/api/*").Respond(fakeResponse);
            var client = new HttpClient(mockHttp);
            Dictionary <string, Uri> uri = new Dictionary <string, Uri> {
                { "Fake", new Uri("http://localhost:24697/api/Products") }
            };
            var service  = new Repos.ProductRepo(client, uri);
            var result   = service.GetHttpProducts().Result;
            var expected = mockData.HttpDataFake().Result;

            expected.ShouldBeEquivalentTo(result, "Expected result not equal to actual result.");
        }