Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
using Grand.Business.Common.Services.Addresses;
using Grand.Business.Core.Interfaces.Common.Addresses;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Grand.Business.Common.Tests.Services.Addresses;
[TestClass]
public class AddressAttributeParserTests
{
private Mock<IAddressAttributeService> _atrService;
private AddressAttributeParser _parser;
private Mock<ITranslationService> _translationService;
private List<CustomAttribute> customAtr;
[TestInitialize]
public void Init()
{
_atrService = new Mock<IAddressAttributeService>();
_translationService = new Mock<ITranslationService>();
_parser = new AddressAttributeParser(_atrService.Object);
customAtr = [
new CustomAttribute { Key = "key1", Value = "value1" },
new CustomAttribute { Key = "key2", Value = "value2" },
new CustomAttribute { Key = "key3", Value = "value3" },
new CustomAttribute { Key = "key4", Value = "value4" }
];
}
[TestMethod]
public async Task ParseAddressAttributes_ReturnExpectedValues()
{
_atrService.Setup(c => c.GetAddressAttributeById("key1"))
.Returns(Task.FromResult(new AddressAttribute { Id = "key1" }));
_atrService.Setup(c => c.GetAddressAttributeById("key2"))
.Returns(Task.FromResult(new AddressAttribute { Id = "key2" }));
var result = await _parser.ParseAddressAttributes(customAtr);
Assert.HasCount(2, result);
Assert.AreEqual("key1", result.First().Id);
}
[TestMethod]
public void AddAddressAttribute_ReturnExpectedValues()
{
var atr = new AddressAttribute { Id = "added" };
var result = _parser.AddAddressAttribute(customAtr, atr, "new-added-value");
Assert.HasCount(5, result);
Assert.IsTrue(result.Any(c => c.Key.Equals("added")));
}
}