Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions SimplCommerce.sln
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Paymen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Checkouts", "src\Modules\SimplCommerce.Module.Checkouts\SimplCommerce.Module.Checkouts.csproj", "{4473538D-2BFA-4C53-B642-0D0DC4F16863}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.ProductComparison.Tests", "test\SimplCommerce.Module.ProductComparison.Tests\SimplCommerce.Module.ProductComparison.Tests.csproj", "{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.ShippingFree.Tests", "test\SimplCommerce.Module.ShippingFree.Tests\SimplCommerce.Module.ShippingFree.Tests.csproj", "{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -713,30 +710,6 @@ Global
{4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x64.Build.0 = Release|Any CPU
{4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x86.ActiveCfg = Release|Any CPU
{4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x86.Build.0 = Release|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Debug|x64.ActiveCfg = Debug|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Debug|x64.Build.0 = Debug|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Debug|x86.ActiveCfg = Debug|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Debug|x86.Build.0 = Debug|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Release|Any CPU.Build.0 = Release|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Release|x64.ActiveCfg = Release|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Release|x64.Build.0 = Release|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Release|x86.ActiveCfg = Release|Any CPU
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7}.Release|x86.Build.0 = Release|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x64.ActiveCfg = Debug|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x64.Build.0 = Debug|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x86.ActiveCfg = Debug|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x86.Build.0 = Debug|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|Any CPU.Build.0 = Release|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x64.ActiveCfg = Release|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x64.Build.0 = Release|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x86.ActiveCfg = Release|Any CPU
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -792,8 +765,6 @@ Global
{14586564-62CC-4117-AC1B-858ED53C2D6C} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
{E30CF10F-FABF-4917-8BEB-CB81E4CE2C92} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
{4473538D-2BFA-4C53-B642-0D0DC4F16863} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
{EEC02E89-E89A-4871-8C3E-4BABA1E56CA7} = {D9FD9ABA-AE5E-4427-AA6B-6285BE2E212D}
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300} = {D9FD9ABA-AE5E-4427-AA6B-6285BE2E212D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9D0D8F0-1AB9-44DD-839F-ED8CEE7DDB10}
Expand Down
1 change: 1 addition & 0 deletions checkout/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
25 changes: 25 additions & 0 deletions checkout/checkout.csproj
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>
100 changes: 100 additions & 0 deletions test/SimplCommerce.Module.Inventory.Tests/WarehouseProductTest.cs
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
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

var warehouseId = 1;
var smartTableParam = new SmartTableParam();

// Act
var result = await controller.GetProducts(warehouseId, smartTableParam);

// Assert
// Assert.IsType<ActionResult>(result);
Copy link
Member

Choose a reason for hiding this comment

The 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 };

Copy link
Member

Choose a reason for hiding this comment

The 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
);

Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Add more test cases as needed

}
}
126 changes: 126 additions & 0 deletions test/SimplCommerce.Module.Inventory.Tests/WarehouseTests.cs
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>();

Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
}
Loading
Loading