45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|