public async Task <(OpenFoodFactsData, ProductData)> InsertFromBarcode(string code) { HttpClient httpClient = new HttpClient(); ProductApi productApi = new ProductApi(Utils.BuildBaseUri(), ref httpClient); ProductData productData = await productApi.GetAsync(code); OpenFoodFactsData openFoodFactsData = new OpenFoodFactsData(productData); return(base.Insert(openFoodFactsData).GetAwaiter().GetResult(), productData); }
public void GetAsyncTest() { // Setup the handler var json = File.ReadAllText("Product/TestProduct.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); // Perform test var res = objectToTest.GetAsync("3222475893421").Result; res.Should().NotBeNull(); res.Id.Should().Be("3222475893421"); // Check the http call was as expected var expectedUri = new Uri("https://test.com/api/v0/product/3222475893421.json"); VerifyMockCalls(mockHandler, HttpMethod.Get, expectedUri); }