src/Services/Catalog/Catalog.UnitTests/Application/CatalogControllerTest.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Catalog.API;
using Microsoft.eShopOnContainers.Services.Catalog.API.Controllers;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
using Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel;
using Microsoft.Extensions.Options;
using Moq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace UnitTest.Catalog.Application;
public class CatalogControllerTest
{
private readonly DbContextOptions<CatalogContext> _dbOptions;
public CatalogControllerTest()
{
_dbOptions = new DbContextOptionsBuilder<CatalogContext>()
.UseInMemoryDatabase(databaseName: "in-memory")
.Options;
using var dbContext = new CatalogContext(_dbOptions);
dbContext.AddRange(GetFakeCatalog());
dbContext.SaveChanges();
}
[Fact]
public async Task Get_catalog_items_success()
{
//Arrange
var brandFilterApplied = 1;
var typesFilterApplied = 2;
var pageSize = 4;
var pageIndex = 1;
var expectedItemsInPage = 2;
var expectedTotalItems = 6;
var catalogContext = new CatalogContext(_dbOptions);
var catalogSettings = new TestCatalogSettings();
var integrationServicesMock = new Mock<ICatalogIntegrationEventService>();
//Act
var orderController = new CatalogController(catalogContext, catalogSettings, integrationServicesMock.Object);
var actionResult = await orderController.ItemsByTypeIdAndBrandIdAsync(typesFilterApplied, brandFilterApplied, pageSize, pageIndex);
//Assert
Assert.IsType<ActionResult<PaginatedItemsViewModel<CatalogItem>>>(actionResult);
var page = Assert.IsAssignableFrom<PaginatedItemsViewModel<CatalogItem>>(actionResult.Value);
Assert.Equal(expectedTotalItems, page.Count);
Assert.Equal(pageIndex, page.PageIndex);
Assert.Equal(pageSize, page.PageSize);
Assert.Equal(expectedItemsInPage, page.Data.Count());
后面还有 68 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。