Пример #1
0
        public void GetByFacetsTest()
        {
            // Setup the handler
            var json        = File.ReadAllText("Product/TestProductsByFacets.json");
            var jsonData    = JObject.Parse(json);
            var mockHandler = GetHttpMessageHandlerMock(json);

            // Use HttpClient with mocked HttpMessageHandler
            var httpClient = new HttpClient(mockHandler.Object);

            var objectToTest = new ProductApi(new Uri("https://test.com/"), ref httpClient);

            // Prepare query
            var query = new Dictionary <string, string>
            {
                { "language", "italian" },
                { "brand", "monoprix" }
            };

            // Perform test
            var res = objectToTest.GetByFacets(query).Result;

            res.Should().NotBeNull().And.HaveCount(1);
            res.First().Id.Should().Be("3350033164765");

            // Check the http call was as expected
            var expectedUri = new Uri("https://test.com/brand/monoprix/language/italian.json");

            VerifyMockCalls(mockHandler, HttpMethod.Get, expectedUri);
        }