-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
infrastrucutre test cases #1074
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,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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.0", | ||
"version": "8.0.100", | ||
"rollForward": "latestMinor", | ||
"allowPrerelease": false | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"DefaultConnection": "Server=.;Database=SimplCommerce;Trusted_Connection=True;TrustServerCertificate=true;MultipleActiveResultSets=true" | ||
"DefaultConnection": "server=DotNetFSD\\SQLEXPRESS; database=SimplCommerce; user id=sa; password=pass@123;trustservercertificate=true", | ||
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. Revert this change |
||
|
||
}, | ||
"Authentication" : { | ||
"Facebook" : { | ||
|
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; | ||||||||
|
||||||||
|
||||||||
Comment on lines
+8
to
+10
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
|
||||||||
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() | ||||||||
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. You could use |
||||||||
{ | ||||||||
var cultureInfo = new CultureInfo("fr-FR"); | ||||||||
|
||||||||
var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); | ||||||||
|
||||||||
Assert.False(result); | ||||||||
} | ||||||||
[Fact] | ||||||||
public void IsZeroDecimalCurrencies_WithUnknown2Currency_ReturnsFalse() | ||||||||
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 as above |
||||||||
{ | ||||||||
var cultureInfo = new CultureInfo("de-DE_phoneb"); | ||||||||
|
||||||||
var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); | ||||||||
|
||||||||
Assert.False(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. Remove extra whitespace |
||||||||
|
||||||||
|
||||||||
} | ||||||||
} |
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 { } | ||
} | ||
} |
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); | ||
} | ||
|
||
|
||
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. Whitespaces!! |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,16 @@ | |
using Microsoft.AspNetCore.Mvc.ViewComponents; | ||
using Microsoft.EntityFrameworkCore; | ||
using Moq; | ||
using SimplCommerce.Module.Core.Areas.Core.Components; | ||
using SimplCommerce.Module.Core.Areas.Core.ViewModels.Manage; | ||
using SimplCommerce.Module.Core.Data; | ||
using SimplCommerce.Module.Core.Extensions; | ||
using SimplCommerce.Module.Core.Models; | ||
using Xunit; | ||
|
||
namespace SimplCommerce.Module.Core.Tests.Components | ||
/*namespace SimplCommerce.Module.Core.Tests.Components | ||
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. ?? |
||
{ | ||
/* | ||
Maybe we should not maintain these kind of unit test, it doesn't bring much value but waste of time | ||
|
||
|
||
public class DefaultShippingAddressViewComponentTests | ||
{ | ||
|
@@ -124,5 +125,5 @@ private UserAddress MakeShippingAddress() | |
return userAddress; | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
}*/ |
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.
Empty?!!