Add initial implementation of product management API
This commit is contained in:
44
EndavaTask.Tests/InMemoryProductRepositoryTests.cs
Normal file
44
EndavaTask.Tests/InMemoryProductRepositoryTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using EndavaTask.Contracts;
|
||||
using EndavaTask.Data;
|
||||
using Xunit;
|
||||
|
||||
namespace EndavaTask.Tests;
|
||||
|
||||
public class InMemoryProductRepositoryTests
|
||||
{
|
||||
private readonly InMemoryProductRepository _repository = new();
|
||||
|
||||
[Fact]
|
||||
public void GetFilteredProducts_FiltersByNameCategoryAndPriceRange_WithPagination()
|
||||
{
|
||||
var filter = new ProductFilterQuery
|
||||
{
|
||||
Name = "mon",
|
||||
CategoryId = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"),
|
||||
MinPrice = 200m,
|
||||
MaxPrice = 350m
|
||||
};
|
||||
|
||||
var result = _repository.GetFilteredProducts(filter, new PaginationQuery { PageNumber = 1, PageSize = 10 });
|
||||
|
||||
Assert.Single(result.Items);
|
||||
|
||||
var product = Assert.Single(result.Items);
|
||||
|
||||
Assert.Equal("Monitor", product.Name);
|
||||
Assert.Equal(1, result.TotalCount);
|
||||
Assert.Equal(1, result.TotalPages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFilteredProducts_ReturnsPagedData_WhenNoFilters()
|
||||
{
|
||||
var result = _repository.GetFilteredProducts(new ProductFilterQuery(), new PaginationQuery { PageNumber = 2, PageSize = 2 });
|
||||
|
||||
Assert.Equal(2, result.Items.Count);
|
||||
Assert.Equal(5, result.TotalCount);
|
||||
Assert.Equal(3, result.TotalPages);
|
||||
Assert.Equal(2, result.PageNumber);
|
||||
Assert.Equal(2, result.PageSize);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user