Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitAuto: [FEATURE] Implement Products API #306

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Src/VTEX.SDK/Products/ProductsApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace VTEX.SDK.Products
{
public class ProductsApi
{
private readonly HttpClient _httpClient;

public ProductsApi(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<string> GetProductAsync(string productId)
{
// Implement the logic to get a product by ID using VTEX API
throw new NotImplementedException();
}
}
}
35 changes: 35 additions & 0 deletions Tests/VTEX.SDK.Tests/Products/ProductsApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
using Moq;
using Moq.Protected;
using System.Threading;
using System.Net;

namespace VTEX.SDK.Tests.Products
{
public class ProductsApiTests
{
[Fact]
public async Task GetProductAsync_ShouldReturnProductData()
{
var handlerMock = new Mock<HttpMessageHandler>();
handlerMock.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent("{ 'id': '123', 'name': 'Test Product' }"),
});

var httpClient = new HttpClient(handlerMock.Object);
var api = new ProductsApi(httpClient);
var result = await api.GetProductAsync("123");
Assert.Contains("Test Product", result);
}
}
}
Loading