Update to 3.1
- Fix test to work on Catalog.API controller, using in-memory database
This commit is contained in:
parent
b5ab54afbc
commit
60b28055ef
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<DebugType>portable</DebugType>
|
<DebugType>portable</DebugType>
|
||||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||||
<AssemblyName>Catalog.API</AssemblyName>
|
<AssemblyName>Catalog.API</AssemblyName>
|
||||||
@ -42,22 +42,22 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="2.2.5" />
|
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="3.0.0" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.AzureStorage" Version="2.2.2" />
|
<PackageReference Include="AspNetCore.HealthChecks.AzureStorage" Version="3.0.1" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="2.2.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="3.0.3" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="2.2.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.0.0" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="2.2.4" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.0.0" />
|
||||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.0-rc1" />
|
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" />
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.10.0-rc1" />
|
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
|
||||||
<PackageReference Include="Grpc.AspNetCore.Server" Version="0.2.23-pre2" />
|
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.25.0" />
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.24.0-pre1" PrivateAssets="All" />
|
<PackageReference Include="Grpc.Tools" Version="2.25.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.0-beta3" />
|
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.11.0-beta2" />
|
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.12.0" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.1" />
|
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.0.0-rc1.19456.10" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="3.0.0-rc1.19456.10" />
|
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="3.1.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="3.0.1-dev-00099" />
|
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
||||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
|
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.1-dev-00209" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.1-dev-00209" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.2-dev-00824" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.2-dev-00824" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -33,9 +33,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0-rc1.19457.4" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0-rc1.19457.4" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-preview-20190828-03" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
@ -1,90 +1,132 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Catalog.API.IntegrationEvents;
|
||||||
using Microsoft.eShopOnContainers.WebMVC.Controllers;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.eShopOnContainers.WebMVC.Services;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
using Microsoft.eShopOnContainers.Services.Catalog.API;
|
||||||
using Microsoft.eShopOnContainers.WebMVC.ViewModels.CatalogViewModels;
|
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 Moq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using CatalogModel = Microsoft.eShopOnContainers.WebMVC.ViewModels.Catalog;
|
|
||||||
|
|
||||||
namespace UnitTest.Catalog.Application
|
namespace UnitTest.Catalog.Application
|
||||||
{
|
{
|
||||||
public class CatalogControllerTest
|
public class CatalogControllerTest
|
||||||
{
|
{
|
||||||
private readonly Mock<ICatalogService> _catalogServiceMock;
|
private readonly DbContextOptions<CatalogContext> _dbOptions;
|
||||||
|
|
||||||
public CatalogControllerTest()
|
public CatalogControllerTest()
|
||||||
{
|
{
|
||||||
_catalogServiceMock = new Mock<ICatalogService>();
|
_dbOptions = new DbContextOptionsBuilder<CatalogContext>()
|
||||||
|
.UseInMemoryDatabase(databaseName: "in-memory")
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
using (var dbContext = new CatalogContext(_dbOptions))
|
||||||
|
{
|
||||||
|
dbContext.AddRange(GetFakeCatalog());
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Get_catalog_items_success()
|
public async Task Get_catalog_items_success()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
var fakeBrandFilterApplied = 1;
|
var brandFilterApplied = 1;
|
||||||
var fakeTypesFilterApplied = 2;
|
var typesFilterApplied = 2;
|
||||||
var fakePage = 2;
|
var pageSize = 4;
|
||||||
var fakeCatalog = GetFakeCatalog();
|
var pageIndex = 1;
|
||||||
|
|
||||||
var expectedNumberOfPages = 5;
|
var expectedItemsInPage = 2;
|
||||||
var expectedTotalPages = 50;
|
var expectedTotalItems = 6;
|
||||||
var expectedCurrentPage = 2;
|
|
||||||
|
|
||||||
_catalogServiceMock.Setup(x => x.GetCatalogItems
|
var catalogContext = new CatalogContext(_dbOptions);
|
||||||
(
|
var catalogSettings = new TestCatalogSettings();
|
||||||
It.Is<int>(y => y == fakePage),
|
|
||||||
It.IsAny<int>(),
|
var integrationServicesMock = new Mock<ICatalogIntegrationEventService>();
|
||||||
It.Is<int?>(y => y == fakeBrandFilterApplied),
|
|
||||||
It.Is<int?>(y => y == fakeTypesFilterApplied)
|
|
||||||
))
|
|
||||||
.Returns(Task.FromResult(fakeCatalog));
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var orderController = new CatalogController(_catalogServiceMock.Object);
|
var orderController = new CatalogController(catalogContext, catalogSettings, integrationServicesMock.Object);
|
||||||
var actionResult = await orderController.Index(fakeBrandFilterApplied, fakeTypesFilterApplied, fakePage, null);
|
var actionResult = await orderController.ItemsByTypeIdAndBrandIdAsync(typesFilterApplied, brandFilterApplied, pageSize, pageIndex);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var viewResult = Assert.IsType<ViewResult>(actionResult);
|
Assert.IsType<ActionResult<PaginatedItemsViewModel<CatalogItem>>>(actionResult);
|
||||||
var model = Assert.IsAssignableFrom<IndexViewModel>(viewResult.ViewData.Model);
|
var page = Assert.IsAssignableFrom<PaginatedItemsViewModel<CatalogItem>>(actionResult.Value);
|
||||||
Assert.Equal(model.PaginationInfo.TotalPages, expectedNumberOfPages);
|
Assert.Equal(expectedTotalItems, page.Count);
|
||||||
Assert.Equal(model.PaginationInfo.TotalItems, expectedTotalPages);
|
Assert.Equal(pageIndex, page.PageIndex);
|
||||||
Assert.Equal(model.PaginationInfo.ActualPage, expectedCurrentPage);
|
Assert.Equal(pageSize, page.PageSize);
|
||||||
Assert.Empty(model.PaginationInfo.Next);
|
Assert.Equal(expectedItemsInPage, page.Data.Count());
|
||||||
Assert.Empty(model.PaginationInfo.Previous);
|
}
|
||||||
}
|
|
||||||
|
private List<CatalogItem> GetFakeCatalog()
|
||||||
private CatalogModel GetFakeCatalog()
|
|
||||||
{
|
{
|
||||||
return new CatalogModel()
|
return new List<CatalogItem>()
|
||||||
{
|
{
|
||||||
PageSize = 10,
|
new CatalogItem()
|
||||||
Count = 50,
|
|
||||||
PageIndex = 2,
|
|
||||||
Data = new List<CatalogItem>()
|
|
||||||
{
|
{
|
||||||
new CatalogItem()
|
Id = 1,
|
||||||
{
|
Name = "fakeItemA",
|
||||||
Id = 1,
|
CatalogTypeId = 2,
|
||||||
Name = "fakeItemA",
|
CatalogBrandId = 1,
|
||||||
CatalogTypeId = 1
|
PictureFileName = "fakeItemA.png"
|
||||||
},
|
},
|
||||||
new CatalogItem()
|
new CatalogItem()
|
||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
Name = "fakeItemB",
|
Name = "fakeItemB",
|
||||||
CatalogTypeId = 1
|
CatalogTypeId = 2,
|
||||||
},
|
CatalogBrandId = 1,
|
||||||
new CatalogItem()
|
PictureFileName = "fakeItemB.png"
|
||||||
{
|
},
|
||||||
Id = 3,
|
new CatalogItem()
|
||||||
Name = "fakeItemC",
|
{
|
||||||
CatalogTypeId = 1
|
Id = 3,
|
||||||
}
|
Name = "fakeItemC",
|
||||||
|
CatalogTypeId = 2,
|
||||||
|
CatalogBrandId = 1,
|
||||||
|
PictureFileName = "fakeItemC.png"
|
||||||
|
},
|
||||||
|
new CatalogItem()
|
||||||
|
{
|
||||||
|
Id = 4,
|
||||||
|
Name = "fakeItemD",
|
||||||
|
CatalogTypeId = 2,
|
||||||
|
CatalogBrandId = 1,
|
||||||
|
PictureFileName = "fakeItemD.png"
|
||||||
|
},
|
||||||
|
new CatalogItem()
|
||||||
|
{
|
||||||
|
Id = 5,
|
||||||
|
Name = "fakeItemE",
|
||||||
|
CatalogTypeId = 2,
|
||||||
|
CatalogBrandId = 1,
|
||||||
|
PictureFileName = "fakeItemE.png"
|
||||||
|
},
|
||||||
|
new CatalogItem()
|
||||||
|
{
|
||||||
|
Id = 6,
|
||||||
|
Name = "fakeItemF",
|
||||||
|
CatalogTypeId = 2,
|
||||||
|
CatalogBrandId = 1,
|
||||||
|
PictureFileName = "fakeItemF.png"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TestCatalogSettings : IOptionsSnapshot<CatalogSettings>
|
||||||
|
{
|
||||||
|
public CatalogSettings Value => new CatalogSettings
|
||||||
|
{
|
||||||
|
PicBaseUrl = "http://image-server.com/",
|
||||||
|
AzureStorageEnabled = true
|
||||||
|
};
|
||||||
|
|
||||||
|
public CatalogSettings Get(string name) => Value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
|
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="3.0.0-preview4-19123-01" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="3.0.0-preview4-19123-01" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-preview-20190828-03" />
|
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.1.0" />
|
||||||
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.0.0-rc1.19456.4" />
|
<PackageReference Include="Moq" Version="4.13.1" />
|
||||||
<PackageReference Include="Moq" Version="4.13.0" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
@ -20,7 +19,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\Web\WebMVC\WebMVC.csproj" />
|
|
||||||
<ProjectReference Include="..\Catalog.API\Catalog.API.csproj" />
|
<ProjectReference Include="..\Catalog.API\Catalog.API.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||||
@ -67,10 +67,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0-preview8.19405.7" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.0" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user