-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Samarth.Gupta
committed
Jan 9, 2024
1 parent
a6bf271
commit ea956b9
Showing
11 changed files
with
250 additions
and
12 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
SimplCommerce.Module.WishList.Tests.Controllers/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
32 changes: 32 additions & 0 deletions
32
....Module.WishList.Tests.Controllers/SimplCommerce.Module.WishList.Tests.Controllers.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<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="Intercom.Dotnet.Client" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
<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> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Modules\SimplCommerce.Module.WishList\SimplCommerce.Module.WishList.csproj" /> | ||
<ProjectReference Include="..\src\SimplCommerce.Infrastructure\SimplCommerce.Infrastructure.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
SimplCommerce.Module.WishList.Tests.Controllers/WishListControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.101", | ||
"version": "8.0.100", | ||
"rollForward": "latestMinor", | ||
"allowPrerelease": false | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/SimplCommerce.Infrastructure.Tests/CurrencyHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Globalization; | ||
using Xunit; | ||
using SimplCommerce.Infrastructure.Helpers; | ||
|
||
|
||
namespace SimplCommerce.Infrastructure.Tests | ||
{ | ||
public class CurrencyHelperTests | ||
{ | ||
[Fact] | ||
public void IsZeroDecimalCurrencies_WithZeroDecimalCurrency_ReturnsTrue() | ||
{ | ||
var cultureInfo = new CultureInfo("ja-JP"); | ||
|
||
var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); | ||
|
||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsZeroDecimalCurrencies_WithNonZeroDecimalCurrency_ReturnsFalse() | ||
{ | ||
var cultureInfo = new CultureInfo("en-US"); | ||
|
||
var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); | ||
|
||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void IsZeroDecimalCurrencies_WithUnknownCurrency_ReturnsFalse() | ||
{ | ||
var cultureInfo = new CultureInfo("fr-FR"); | ||
|
||
var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); | ||
|
||
Assert.False(result); | ||
} | ||
[Fact] | ||
public void IsZeroDecimalCurrencies_WithUnknown2Currency_ReturnsFalse() | ||
{ | ||
var cultureInfo = new CultureInfo("de-DE_phoneb"); | ||
|
||
var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); | ||
|
||
Assert.False(result); | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
test/SimplCommerce.Infrastructure.Tests/ReflectionHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using SimplCommerce.Infrastructure.Helpers; | ||
using Xunit; | ||
|
||
namespace SimplCommerce.Infrastructure.Tests | ||
{ | ||
public class ReflectionHelperTests | ||
{ | ||
[Fact] | ||
public void IsAssignableToGenericType_TypeIsAssignable_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var targetType = typeof(List<int>); | ||
var genericType = typeof(IEnumerable<>); | ||
|
||
// Act | ||
var result = ReflectionHelper.IsAssignableToGenericType(targetType, genericType); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsAssignableToGenericType_TypeIsNotAssignable_ReturnsFalse() | ||
{ | ||
// Arrange | ||
var targetType = typeof(string); | ||
var genericType = typeof(IEnumerable<>); | ||
|
||
// Act | ||
var result = ReflectionHelper.IsAssignableToGenericType(targetType, genericType); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsAssignableToGenericType_TypeInheritsGenericInterface_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var targetType = typeof(MyClass); | ||
var genericType = typeof(IGenericInterface<>); | ||
|
||
// Act | ||
var result = ReflectionHelper.IsAssignableToGenericType(targetType, genericType); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsAssignableToGenericType_TypeDoesNotInheritGenericInterface_ReturnsFalse() | ||
{ | ||
// Arrange | ||
var targetType = typeof(MyClass); | ||
var genericType = typeof(INonGenericInterface); | ||
|
||
// Act | ||
var result = ReflectionHelper.IsAssignableToGenericType(targetType, genericType); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
// Example classes/interfaces for testing | ||
public class MyClass : IGenericInterface<int> { } | ||
|
||
public interface IGenericInterface<T> { } | ||
|
||
public interface INonGenericInterface { } | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
test/SimplCommerce.Module.Cms.Tests/Controllers/MenuApiControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Moq; | ||
using SimplCommerce.Infrastructure.Data; | ||
using SimplCommerce.Module.Cms.Areas.Cms.Controllers; | ||
using SimplCommerce.Module.Cms.Areas.Cms.ViewModels; | ||
using SimplCommerce.Module.Cms.Models; | ||
using Xunit; | ||
|
||
namespace SimplCommerce.Module.Cms.Tests.Controllers | ||
{ | ||
public class MenuApiControllerTests | ||
{ | ||
[Fact] | ||
public async Task Post_CreatesMenu() | ||
{ | ||
// Arrange | ||
var menuRepositoryMock = new Mock<IRepository<Menu>>(); | ||
var menuItemRepositoryMock = new Mock<IRepository<MenuItem>>(); | ||
|
||
var controller = new MenuApiController(menuRepositoryMock.Object, menuItemRepositoryMock.Object); | ||
|
||
var menuForm = new MenuForm | ||
{ | ||
Name = "NewMenu", | ||
IsPublished = true | ||
}; | ||
|
||
// Act | ||
var result = await controller.Post(menuForm); | ||
|
||
// Assert | ||
var okResult = Assert.IsType<JsonResult>(result); | ||
var createdMenu = Assert.IsType<Menu>(okResult.Value); | ||
Assert.Equal("NewMenu", createdMenu.Name); | ||
Assert.True(createdMenu.IsPublished); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters