diff --git a/SimplCommerce.Module.WishList.Tests.Controllers/GlobalUsings.cs b/SimplCommerce.Module.WishList.Tests.Controllers/GlobalUsings.cs new file mode 100644 index 0000000000..9df1d42179 --- /dev/null +++ b/SimplCommerce.Module.WishList.Tests.Controllers/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; diff --git a/SimplCommerce.Module.WishList.Tests.Controllers/SimplCommerce.Module.WishList.Tests.Controllers.csproj b/SimplCommerce.Module.WishList.Tests.Controllers/SimplCommerce.Module.WishList.Tests.Controllers.csproj new file mode 100644 index 0000000000..d6b402a0e3 --- /dev/null +++ b/SimplCommerce.Module.WishList.Tests.Controllers/SimplCommerce.Module.WishList.Tests.Controllers.csproj @@ -0,0 +1,31 @@ + + + + net8.0 + enable + enable + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + diff --git a/src/SimplCommerce.Infrastructure/Helpers/CurrencyHelper.cs b/src/SimplCommerce.Infrastructure/Helpers/CurrencyHelper.cs index 9c82c5a648..66ecfbc800 100644 --- a/src/SimplCommerce.Infrastructure/Helpers/CurrencyHelper.cs +++ b/src/SimplCommerce.Infrastructure/Helpers/CurrencyHelper.cs @@ -7,6 +7,11 @@ public static class CurrencyHelper { private static readonly List _zeroDecimalCurrencies = new List { "BIF", "DJF", "JPY", "KRW", "PYG", "VND", "XAF", "XPF", "CLP", "GNF", "KMF", "MGA", "RWF", "VUV", "XOF" }; + /// + /// Determines whether the currency associated with the specified culture uses decimal places. + /// + /// The culture to check for its associated currency format. + /// true if the currency is a known zero-decimal currency else false public static bool IsZeroDecimalCurrencies(CultureInfo cultureInfo) { var regionInfo = new RegionInfo(cultureInfo.LCID); diff --git a/test/SimplCommerce.Infrastructure.Tests/CurrencyHelperTests.cs b/test/SimplCommerce.Infrastructure.Tests/CurrencyHelperTests.cs new file mode 100644 index 0000000000..e21672bceb --- /dev/null +++ b/test/SimplCommerce.Infrastructure.Tests/CurrencyHelperTests.cs @@ -0,0 +1,42 @@ +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 + { + [Theory] + [InlineData("ja-JP", true)] // Japanese Yen (JPY) + [InlineData("ko-KR", true)] // Korean Won (KRW) + [InlineData("en-US", false)] // US Dollar (USD) + [InlineData("fr-FR", false)] // Euro (EUR) + public void IsZeroDecimalCurrencies_ReturnsExpectedResult(string cultureName, bool expectedResult) + { + // Arrange + var cultureInfo = new CultureInfo(cultureName); + + // Act + var result = CurrencyHelper.IsZeroDecimalCurrencies(cultureInfo); + + // Assert + Assert.Equal(expectedResult, result); + } + + [Fact] + public void IsZeroDecimalCurrencies_InvalidCulture_ThrowsException() + { + // Arrange + var invalidCulture = CultureInfo.InvariantCulture; + + // Act & Assert + Assert.Throws(() => + CurrencyHelper.IsZeroDecimalCurrencies(invalidCulture)); + } + } +} diff --git a/test/SimplCommerce.Infrastructure.Tests/ReflectionHelperTests.cs b/test/SimplCommerce.Infrastructure.Tests/ReflectionHelperTests.cs new file mode 100644 index 0000000000..c126c1755d --- /dev/null +++ b/test/SimplCommerce.Infrastructure.Tests/ReflectionHelperTests.cs @@ -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); + 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 { } + + public interface IGenericInterface { } + + public interface INonGenericInterface { } + } +} diff --git a/test/SimplCommerce.Module.Cms.Tests/Controllers/MenuApiControllerTests.cs b/test/SimplCommerce.Module.Cms.Tests/Controllers/MenuApiControllerTests.cs new file mode 100644 index 0000000000..62dcf906c0 --- /dev/null +++ b/test/SimplCommerce.Module.Cms.Tests/Controllers/MenuApiControllerTests.cs @@ -0,0 +1,44 @@ +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>(); + var menuItemRepositoryMock = new Mock>(); + + 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(result); + var createdMenu = Assert.IsType(okResult.Value); + Assert.Equal("NewMenu", createdMenu.Name); + Assert.True(createdMenu.IsPublished); + } + } +}