-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test: added warehouseProduct and warehouse tests #1129
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,100 @@ | ||||||
using System.Collections.Generic; | ||||||
using System.Threading.Tasks; | ||||||
using Microsoft.AspNetCore.Mvc; | ||||||
using Moq; | ||||||
using SimplCommerce.Infrastructure.Data; | ||||||
using SimplCommerce.Infrastructure.Web.SmartTable; | ||||||
using SimplCommerce.Module.Catalog.Models; | ||||||
using SimplCommerce.Module.Core.Extensions; | ||||||
using SimplCommerce.Module.Inventory.Areas.Inventory.Controllers; | ||||||
using SimplCommerce.Module.Inventory.Models; | ||||||
using SimplCommerce.Module.Inventory.Services; | ||||||
using Xunit; | ||||||
|
||||||
namespace SimplCommerce.Module.Inventory.Tests | ||||||
{ | ||||||
public class WarehouseProductApiControllerTests | ||||||
{ | ||||||
private readonly Mock<IRepository<Warehouse>> _warehouseRepositoryMock; | ||||||
private readonly Mock<IWorkContext> _workContextMock; | ||||||
private readonly Mock<IRepository<Product>> _productRepositoryMock; | ||||||
private readonly Mock<IRepository<Stock>> _stockRepositoryMock; | ||||||
private readonly Mock<IStockService> _stockServiceMock; | ||||||
|
||||||
public WarehouseProductApiControllerTests() | ||||||
{ | ||||||
_warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||||
_workContextMock = new Mock<IWorkContext>(); | ||||||
_productRepositoryMock = new Mock<IRepository<Product>>(); | ||||||
_stockRepositoryMock = new Mock<IRepository<Stock>>(); | ||||||
_stockServiceMock = new Mock<IStockService>(); | ||||||
} | ||||||
|
||||||
[Fact] | ||||||
public async Task GetProducts_ReturnsOkResult() | ||||||
{ | ||||||
// Arrange | ||||||
var controller = new WarehouseProductApiController( | ||||||
_warehouseRepositoryMock.Object, | ||||||
_workContextMock.Object, | ||||||
_productRepositoryMock.Object, | ||||||
_stockRepositoryMock.Object, | ||||||
_stockServiceMock.Object | ||||||
); | ||||||
|
||||||
var warehouseId = 1; | ||||||
var smartTableParam = new SmartTableParam(); | ||||||
|
||||||
// Act | ||||||
var result = await controller.GetProducts(warehouseId, smartTableParam); | ||||||
|
||||||
// Assert | ||||||
// Assert.IsType<ActionResult>(result); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the assertion is disabled? |
||||||
} | ||||||
|
||||||
[Fact] | ||||||
public async Task AddProducts_ReturnsAcceptedResult() | ||||||
{ | ||||||
// Arrange | ||||||
var controller = new WarehouseProductApiController( | ||||||
_warehouseRepositoryMock.Object, | ||||||
_workContextMock.Object, | ||||||
_productRepositoryMock.Object, | ||||||
_stockRepositoryMock.Object, | ||||||
_stockServiceMock.Object | ||||||
); | ||||||
|
||||||
var warehouseId = 1; | ||||||
var productIds = new List<long> { 1, 2, 3 }; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Act | ||||||
var result = await controller.AddProducts(warehouseId, productIds); | ||||||
|
||||||
// Assert | ||||||
Assert.IsType<NotFoundResult>(result); | ||||||
} | ||||||
|
||||||
[Fact] | ||||||
public async Task AddAllProducts_ReturnsAcceptedResult() | ||||||
{ | ||||||
// Arrange | ||||||
var controller = new WarehouseProductApiController( | ||||||
_warehouseRepositoryMock.Object, | ||||||
_workContextMock.Object, | ||||||
_productRepositoryMock.Object, | ||||||
_stockRepositoryMock.Object, | ||||||
_stockServiceMock.Object | ||||||
); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
var warehouseId = 1; | ||||||
|
||||||
// Act | ||||||
var result = await controller.AddAllProducts(warehouseId); | ||||||
|
||||||
// Assert | ||||||
Assert.IsType<NotFoundResult>(result); | ||||||
} | ||||||
|
||||||
// Add more test cases as needed | ||||||
Comment on lines
+97
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,126 @@ | ||||
using System.Threading.Tasks; | ||||
using Microsoft.AspNetCore.Mvc; | ||||
using Moq; | ||||
using SimplCommerce.Infrastructure.Data; | ||||
using SimplCommerce.Infrastructure.Web.SmartTable; | ||||
using SimplCommerce.Module.Core.Extensions; | ||||
using SimplCommerce.Module.Core.Models; | ||||
using SimplCommerce.Module.Inventory.Areas.Inventory.Controllers; | ||||
using SimplCommerce.Module.Inventory.Areas.Inventory.ViewModels; | ||||
using SimplCommerce.Module.Inventory.Models; | ||||
using Xunit; | ||||
|
||||
namespace SimplCommerce.Module.Inventory.Tests.Controllers | ||||
{ | ||||
public class WarehouseApiControllerTests | ||||
{ | ||||
[Fact] | ||||
public async Task Get_ReturnsOkResult() | ||||
{ | ||||
// Arrange | ||||
var warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||
var addressRepositoryMock = new Mock<IRepository<Address>>(); | ||||
var workContextMock = new Mock<IWorkContext>(); | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
var controller = new WarehouseApiController(warehouseRepositoryMock.Object, workContextMock.Object, addressRepositoryMock.Object); | ||||
|
||||
// Act | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please complete the test |
||||
// var result = await controller.Get(); | ||||
|
||||
// Assert | ||||
// var actionResult = Assert.IsType< ActionResult>(result); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task List_ReturnsJsonResult() | ||||
{ | ||||
// Arrange | ||||
var warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||
var addressRepositoryMock = new Mock<IRepository<Address>>(); | ||||
var workContextMock = new Mock<IWorkContext>(); | ||||
|
||||
var controller = new WarehouseApiController(warehouseRepositoryMock.Object, workContextMock.Object, addressRepositoryMock.Object); | ||||
var param = new SmartTableParam(); | ||||
|
||||
// Act | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||
// var result = await controller.List(param); | ||||
|
||||
// Assert | ||||
// Assert.IsType<JsonResult>(result); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task GetById_ReturnsJsonResult() | ||||
{ | ||||
// Arrange | ||||
var warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||
var addressRepositoryMock = new Mock<IRepository<Address>>(); | ||||
var workContextMock = new Mock<IWorkContext>(); | ||||
|
||||
var controller = new WarehouseApiController(warehouseRepositoryMock.Object, workContextMock.Object, addressRepositoryMock.Object); | ||||
var warehouseId = 1; | ||||
|
||||
// Act | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here .. |
||||
// var result = await controller.Get(warehouseId); | ||||
|
||||
// Assert | ||||
// Assert.IsType<JsonResult>(result); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task Post_ReturnsCreatedAtActionResult() | ||||
{ | ||||
// Arrange | ||||
var warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||
var addressRepositoryMock = new Mock<IRepository<Address>>(); | ||||
var workContextMock = new Mock<IWorkContext>(); | ||||
|
||||
var controller = new WarehouseApiController(warehouseRepositoryMock.Object, workContextMock.Object, addressRepositoryMock.Object); | ||||
var warehouseVm = new WarehouseVm(); | ||||
|
||||
// Act | ||||
//var result = await controller.Post(warehouseVm); | ||||
|
||||
// Assert | ||||
// Assert.IsType<CreatedAtActionResult>(result); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task Put_ReturnsAcceptedResult() | ||||
{ | ||||
// Arrange | ||||
var warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||
var addressRepositoryMock = new Mock<IRepository<Address>>(); | ||||
var workContextMock = new Mock<IWorkContext>(); | ||||
|
||||
var controller = new WarehouseApiController(warehouseRepositoryMock.Object, workContextMock.Object, addressRepositoryMock.Object); | ||||
var warehouseId = 1; | ||||
var warehouseVm = new WarehouseVm(); | ||||
|
||||
// Act | ||||
|
||||
//var result = await controller.Put(warehouseId, warehouseVm); | ||||
|
||||
// Assert | ||||
//Assert.IsType<AcceptedResult>(result); | ||||
} | ||||
|
||||
[Fact] | ||||
public async Task Delete_ReturnsNoContentResult() | ||||
{ | ||||
// Arrange | ||||
var warehouseRepositoryMock = new Mock<IRepository<Warehouse>>(); | ||||
var addressRepositoryMock = new Mock<IRepository<Address>>(); | ||||
var workContextMock = new Mock<IWorkContext>(); | ||||
|
||||
var controller = new WarehouseApiController(warehouseRepositoryMock.Object, workContextMock.Object, addressRepositoryMock.Object); | ||||
var warehouseId = 1; | ||||
|
||||
// Act | ||||
//var result = await controller.Delete(warehouseId); | ||||
|
||||
// Assert | ||||
//Assert.IsType<NoContentResult>(result); | ||||
} | ||||
} | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.