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
Add tests
support6d6a9479c9b0
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/ProductDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/ProductDeletedEventHandlerTests.csnew file mode 100644index 000000000..9baced549--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/ProductDeletedEventHandlerTests.cs@@ -0,0 +1,70 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Catalog.Events.Handlers;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Domain.Data;+using Grand.Domain.Catalog;+using Grand.Data.Tests.MongoDb;+using Grand.Business.Core.Interfaces.Catalog.Products;+using Moq;+using Grand.Domain.Customers;+using Grand.Domain.Seo;++namespace Grand.Business.Catalog.Events.Handlers.Tests+{+ [TestClass()]+ public class ProductDeletedEventHandlerTests+ {+ private IRepository<Product> _repository;+ private IRepository<CustomerGroupProduct> _customerGroupProductRepository;+ private IRepository<Customer> _customerRepository;+ private IRepository<EntityUrl> _entityUrlRepository;+ private IRepository<ProductTag> _productTagRepository;+ private IRepository<ProductReview> _productReviewRepository;+ private IRepository<ProductDeleted> _productDeletedRepository;+ private Mock<IProductTagService> _productTagService;+ private ProductDeletedEventHandler _handler;++ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<Product>();+ _customerGroupProductRepository = new MongoDBRepositoryTest<CustomerGroupProduct>();+ _customerRepository = new MongoDBRepositoryTest<Customer>();+ _entityUrlRepository = new MongoDBRepositoryTest<EntityUrl>();+ _productTagRepository = new MongoDBRepositoryTest<ProductTag>();+ _productReviewRepository = new MongoDBRepositoryTest<ProductReview>();+ _productDeletedRepository = new MongoDBRepositoryTest<ProductDeleted>();+ _productTagService = new Mock<IProductTagService>();+ _handler = new ProductDeletedEventHandler(_repository, _customerGroupProductRepository,+ _customerRepository, _entityUrlRepository, _productTagRepository, _productReviewRepository,+ _productDeletedRepository, _productTagService.Object);+ }+++ [TestMethod()]+ public async Task HandleTest()+ {+ //Arrange+ var product = new Product();+ product.RecommendedProduct.Add("1");+ product.RelatedProducts.Add(new RelatedProduct() { ProductId2 = "1" });+ product.CrossSellProduct.Add("1");+ product.SimilarProducts.Add(new SimilarProduct() { ProductId2 = "1" });+ await _repository.InsertAsync(product);+ //Act+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Product>(new Product() { Id = "1" }), CancellationToken.None);++ //Assert+ var result = _repository.Table.FirstOrDefault(x => x.Id == product.Id);+ Assert.IsNotNull(result);+ Assert.IsTrue(result.RelatedProducts.Count == 0);+ Assert.IsTrue(result.RecommendedProduct.Count == 0);+ Assert.IsTrue(result.CrossSellProduct.Count == 0);+ Assert.IsTrue(result.SimilarProducts.Count == 0);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetPersonalizedProductsQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetPersonalizedProductsQueryHandlerTests.csnew file mode 100644index 000000000..75bc2c0ad--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetPersonalizedProductsQueryHandlerTests.cs@@ -0,0 +1,36 @@+using Grand.Business.Core.Interfaces.Catalog.Products;+using Grand.Domain.Catalog;+using Grand.Domain.Customers;+using Grand.Domain.Data;+using Grand.Infrastructure.Caching;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetPersonalizedProductsQueryHandlerTests+ {+ private Mock<ICacheBase> _casheManagerMock;+ private Mock<IProductService> _productServiceMock;+ private Mock<IRepository<CustomerProduct>> _customerProductRepositoryMock;++ private GetPersonalizedProductsQueryHandler handler;+ [TestInitialize()]+ public void Init()+ {+ _casheManagerMock = new Mock<ICacheBase>();+ _productServiceMock = new Mock<IProductService>();+ _customerProductRepositoryMock = new Mock<IRepository<CustomerProduct>>();++ handler = new GetPersonalizedProductsQueryHandler(_productServiceMock.Object, _casheManagerMock.Object, _customerProductRepositoryMock.Object);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ await handler.Handle(new Core.Queries.Catalog.GetPersonalizedProductsQuery(), CancellationToken.None);+ _casheManagerMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Product>>>>()), Times.Once);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetPriceByCustomerProductQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetPriceByCustomerProductQueryHandlerTests.csnew file mode 100644index 000000000..f32c168bf--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetPriceByCustomerProductQueryHandlerTests.cs@@ -0,0 +1,36 @@+using Grand.Business.Core.Interfaces.Catalog.Products;+using Grand.Domain.Catalog;+using Grand.Domain.Customers;+using Grand.Domain.Data;+using Grand.Infrastructure.Caching;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;+using System;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetPriceByCustomerProductQueryHandlerTests+ {+ private Mock<ICacheBase> _casheManagerMock;+ private Mock<IRepository<CustomerProductPrice>> _customerProductPriceRepositoryMock;++ private GetPriceByCustomerProductQueryHandler handler;++ [TestInitialize()]+ public void Init()+ {+ _casheManagerMock = new Mock<ICacheBase>();+ _customerProductPriceRepositoryMock = new Mock<IRepository<CustomerProductPrice>>();++ handler = new GetPriceByCustomerProductQueryHandler(_casheManagerMock.Object, _customerProductPriceRepositoryMock.Object);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ await handler.Handle(new Core.Queries.Catalog.GetPriceByCustomerProductQuery(), CancellationToken.None);+ _casheManagerMock.Verify(c => c.Get(It.IsAny<string>(), It.IsAny<Func<(CustomerProductPrice, bool)>>()), Times.Once);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetProductArchByIdQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetProductArchByIdQueryHandlerTests.csnew file mode 100644index 000000000..f608cb794--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetProductArchByIdQueryHandlerTests.cs@@ -0,0 +1,36 @@+using Grand.Business.Core.Interfaces.Catalog.Products;+using Grand.Domain.Catalog;+using Grand.Domain.Customers;+using Grand.Domain.Data;+using Grand.Infrastructure.Caching;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;+using System;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetProductArchByIdQueryHandlerTests+ {+ private Mock<IRepository<ProductDeleted>> _productDeletedRepository;++ private GetProductArchByIdQueryHandler handler;++ [TestInitialize()]+ public void Init()+ {+ _productDeletedRepository = new Mock<IRepository<ProductDeleted>>();++ handler = new GetProductArchByIdQueryHandler(_productDeletedRepository.Object);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ //Act+ var result = await handler.Handle(new Core.Queries.Catalog.GetProductArchByIdQuery(), CancellationToken.None);+ //Assert+ Assert.IsNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.csnew file mode 100644index 000000000..fce34c55a--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.cs@@ -0,0 +1,26 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Catalog.Queries.Handlers;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetRecommendedProductsQueryHandlerTests+ {+ [TestMethod()]+ public void GetRecommendedProductsQueryHandlerTest()+ {+ Assert.Fail();+ }++ [TestMethod()]+ public void HandleTest()+ {+ Assert.Fail();+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.csnew file mode 100644index 000000000..c693284af--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.cs@@ -0,0 +1,105 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Catalog.Services.Products;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Infrastructure;+using Moq;+using MediatR;+using Grand.Business.Core.Interfaces.Common.Security;+using Grand.SharedKernel.Extensions;+using Grand.Business.Common.Services.Security;+using Grand.Domain.Customers;+using Grand.Business.Core.Interfaces.Catalog.Products;+using Grand.Business.Core.Interfaces.Common.Localization;+using Grand.Business.Core.Interfaces.Catalog.Tax;+using Grand.Business.Core.Interfaces.Catalog.Prices;+using Grand.Domain.Catalog;+using Grand.Domain.Common;++namespace Grand.Business.Catalog.Services.Products.Tests+{+ [TestClass()]+ public class ProductAttributeFormatterTests+ {+ private ProductAttributeFormatter _productAttributeFormatter;+ private Mock<IWorkContext> _workContextMock;+ private Mock<IMediator> _mediatorMock;+ private IAclService _aclServiceMock;+ private Mock<IProductAttributeService> _productAttributeServiceMock;+ private Mock<ITranslationService> _translationServiceMock;+ private Mock<ITaxService> _taxServiceMock;+ private Mock<IPriceFormatter> _priceFormatterMock;+ private Mock<IPricingService> _pricingServiceMock;+ private Mock<IProductService> _productServiceMock;+ [TestInitialize()]+ public void InitializeTests()+ {+ CommonPath.BaseDirectory = "";++ _workContextMock = new Mock<IWorkContext>();+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());+ _productAttributeServiceMock = new Mock<IProductAttributeService>();+ _productAttributeServiceMock.Setup(x => x.GetProductAttributeById(It.IsAny<string>())).Returns(Task.FromResult(new ProductAttribute() { Name = "test" }));+ _translationServiceMock = new Mock<ITranslationService>();+ _translationServiceMock.Setup(x => x.GetResource("GiftVoucherAttribute.From.Virtual")).Returns("Name {0}, Email {1}");+ _translationServiceMock.Setup(x => x.GetResource("GiftVoucherAttribute.For.Virtual")).Returns("RecName {0}, RecEmail {1}");+ _taxServiceMock = new Mock<ITaxService>();+ _priceFormatterMock = new Mock<IPriceFormatter>();+ _pricingServiceMock = new Mock<IPricingService>();+ _productServiceMock = new Mock<IProductService>();+ _mediatorMock = new Mock<IMediator>();+ _aclServiceMock = new AclService();+ _productAttributeFormatter = new ProductAttributeFormatter(_workContextMock.Object, _productAttributeServiceMock.Object,+ _translationServiceMock.Object, _taxServiceMock.Object, _priceFormatterMock.Object, _pricingServiceMock.Object,+ _productServiceMock.Object);+ }++ [TestMethod()]+ public async Task FormatAttributesTest_EmptyCustomAttribute()+ {+ //Arrange+ var product = new Product();+ //Act+ var result = await _productAttributeFormatter.FormatAttributes(product, new List<CustomAttribute>());+ //Assert+ Assert.AreEqual("", result);+ }+ [TestMethod()]+ public async Task FormatAttributesTest_GiftVoucher()+ {+ //Arrange+ var product = new Product() { GiftVoucherTypeId = GiftVoucherType.Virtual, IsGiftVoucher = true };+ //Act+ var result = await _productAttributeFormatter.FormatAttributes(product, new List<CustomAttribute>()+ {+ new CustomAttribute() { Key = "RecipientName", Value = "John" },+ new CustomAttribute() { Key = "RecipientEmail", Value = "[email protected]" },+ new CustomAttribute() { Key = "SenderName", Value = "Will" },+ new CustomAttribute() { Key = "SenderEmail", Value = "[email protected]" },+ new CustomAttribute() { Key = "Message", Value = "" },+ });+ //Assert+ Assert.AreEqual("Name Will, Email [email protected]<br />RecName John, RecEmail [email protected]", result);+ }+ [TestMethod()]+ public async Task FormatAttributesTest_CustomAttribute()+ {+ //Arrange+ var product = new Product();+ var productAttributeMapping = new ProductAttributeMapping() { Id = "1", AttributeControlTypeId = AttributeControlType.Checkboxes };+ productAttributeMapping.ProductAttributeValues.Add(new ProductAttributeValue() { Id = "1", Name = "aa" });+ product.ProductAttributeMappings.Add(productAttributeMapping);+ //Act+ var result = await _productAttributeFormatter.FormatAttributes(product, new List<CustomAttribute>()+ {+ new CustomAttribute() { Key = "1", Value = "1" },+ });+ //Assert+ Assert.AreEqual("test: aa", result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductCourseServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductCourseServiceTests.csnew file mode 100644index 000000000..2ad65008f--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductCourseServiceTests.cs@@ -0,0 +1,68 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Catalog;+using Grand.Domain.Courses;+using Grand.Domain.Data;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Catalog.Services.Products.Tests+{+ [TestClass()]+ public class ProductCourseServiceTests+ {+ private IRepository<Product> _repository;+ private IRepository<Course> _courseRepository;+ private ProductCourseService _courseService;+ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<Product>();+ _courseRepository = new MongoDBRepositoryTest<Course>();+ _courseService = new ProductCourseService(_repository, _courseRepository);++ }+++ [TestMethod()]+ public async Task GetCourseByProductIdTest()+ {+ //Arrange+ var course1 = new Course() { ProductId = "1" };+ await _courseRepository.InsertAsync(course1);+ //Act+ var result = await _courseService.GetCourseByProductId("1");++ //Arrange+ Assert.IsNotNull(result);+ }++ [TestMethod()]+ public async Task GetProductByCourseIdTest()+ {+ //Arrange+ var product = new Product() { CourseId = "1", Id = "1"};+ await _repository.InsertAsync(product);+ //Act+ var result = await _courseService.GetProductByCourseId("1");++ //Arrange+ Assert.IsNotNull(result);+ Assert.AreEqual("1", result.Id);++ }++ [TestMethod()]+ public async Task UpdateCourseOnProductTest()+ {+ //Arrange+ var product = new Product() { CourseId = "1", Id = "1" };+ await _repository.InsertAsync(product);++ //Act+ await _courseService.UpdateCourseOnProduct("1", "2");++ //Arrange+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x=>x.Id == "1"));+ Assert.AreEqual("2", _repository.Table.FirstOrDefault(x => x.Id== "1").CourseId);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductTagServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductTagServiceTests.csnew file mode 100644index 000000000..4206dd36c--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductTagServiceTests.cs@@ -0,0 +1,199 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Catalog;+using Grand.Domain.Data;+using Grand.Infrastructure.Caching;+using Grand.Infrastructure.Tests.Caching;+using Grand.SharedKernel.Extensions;+using MediatR;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;+++namespace Grand.Business.Catalog.Services.Products.Tests+{+ [TestClass()]+ public class ProductTagServiceTests+ {+ private IRepository<ProductTag> _repositoryProductTag;+ private IRepository<Product> _productRepository;+ private Mock<IMediator> _mediatorMock;+ private MemoryCacheBase _cacheBase;+ private ProductTagService _productTagService;++ [TestInitialize()]+ public void InitializeTests()+ {+ CommonPath.BaseDirectory = "";++ _repositoryProductTag = new MongoDBRepositoryTest<ProductTag>();+ _productRepository = new MongoDBRepositoryTest<Product>();+ _mediatorMock = new Mock<IMediator>();+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);+ _productTagService = new ProductTagService(_repositoryProductTag, _productRepository, _cacheBase, _mediatorMock.Object);+ }++ [TestMethod()]+ public async Task GetAllProductTagsTest()+ {+ //Arrange+ await _repositoryProductTag.InsertAsync(new ProductTag());+ await _repositoryProductTag.InsertAsync(new ProductTag());+ await _repositoryProductTag.InsertAsync(new ProductTag());++ //Act+ var result = await _productTagService.GetAllProductTags();++ //Assert+ Assert.AreEqual(3, result.Count);++ }++ [TestMethod()]+ public async Task GetProductTagByIdTest()+ {+ //Arrange+ await _repositoryProductTag.InsertAsync(new ProductTag());+ await _repositoryProductTag.InsertAsync(new ProductTag() { Id = "1", Name = "test" });+ await _repositoryProductTag.InsertAsync(new ProductTag());++ //Act+ var result = await _productTagService.GetProductTagById("1");++ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("test", result.Name);+ }++ [TestMethod()]+ public async Task GetProductTagByNameTest()+ {+ //Arrange+ await _repositoryProductTag.InsertAsync(new ProductTag());+ await _repositoryProductTag.InsertAsync(new ProductTag() { Id = "1", Name = "test" });+ await _repositoryProductTag.InsertAsync(new ProductTag());++ //Act+ var result = await _productTagService.GetProductTagByName("test");++ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("1", result.Id);+ }++ [TestMethod()]+ public async Task GetProductTagBySeNameTest()+ {+ //Arrange+ await _repositoryProductTag.InsertAsync(new ProductTag());+ await _repositoryProductTag.InsertAsync(new ProductTag() { Id = "1", Name = "test", SeName = "test" });+ await _repositoryProductTag.InsertAsync(new ProductTag());++ //Act+ var result = await _productTagService.GetProductTagBySeName("test");++ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("1", result.Id);+ }++ [TestMethod()]+ public async Task InsertProductTagTest()+ {+ //Arrange+ var productTag = new ProductTag();+ productTag.Name = "test";+ //Act+ await _productTagService.InsertProductTag(productTag);+ var result = await _productTagService.GetProductTagById(productTag.Id);+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("test", result.Name);+ }++ [TestMethod()]+ public async Task UpdateProductTagTest()+ {+ //Arrange+ var productTag = new ProductTag();+ productTag.Name = "test";+ await _productTagService.InsertProductTag(productTag);+ //Act+ productTag.Name = "test2";+ await _productTagService.UpdateProductTag(productTag);+ var result = await _productTagService.GetProductTagById(productTag.Id);+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("test2", result.Name);+ }++ [TestMethod()]+ public async Task DeleteProductTagTest()+ {+ //Arrange+ var productTag = new ProductTag();+ productTag.Name = "test";+ await _productTagService.InsertProductTag(productTag);++ //Act+ await _productTagService.DeleteProductTag(productTag);+ var result = await _productTagService.GetProductTagById(productTag.Id);++ //Assert+ Assert.IsNull(result);+ }++ [TestMethod()]+ public async Task AttachProductTagTest()+ {+ //Arrange+ var productTag = new ProductTag();+ productTag.Name = "test";+ await _productTagService.InsertProductTag(productTag);+ var product = new Product();+ await _productRepository.InsertAsync(product);++ //Act+ await _productTagService.AttachProductTag(productTag, product.Id);+ var result = _productRepository.Table.FirstOrDefault(x => x.Id == product.Id);++ //Assert+ Assert.IsTrue(result.ProductTags.Any());+ Assert.IsNotNull(result.ProductTags.FirstOrDefault(x => x == "test"));+ }++ [TestMethod()]+ public async Task DetachProductTagTest()+ {+ //Arrange+ var productTag = new ProductTag();+ productTag.Name = "test";+ await _productTagService.InsertProductTag(productTag);+ var product = new Product();+ await _productRepository.InsertAsync(product);+ await _productTagService.AttachProductTag(productTag, product.Id);++ //Act+ await _productTagService.DetachProductTag(productTag, product.Id);+ var result = _productRepository.Table.FirstOrDefault(x => x.Id == product.Id);++ //Assert+ Assert.IsFalse(result.ProductTags.Any());+ Assert.IsNull(result.ProductTags.FirstOrDefault(x => x == "test"));+ }++ [TestMethod()]+ public async Task GetProductCountTest()+ {+ //Arrange+ var productTag = new ProductTag();+ productTag.Name = "test";+ productTag.Count = 10;+ await _productTagService.InsertProductTag(productTag);+ //Act+ var result = await _productTagService.GetProductCount(productTag.Id, "");++ //Assert+ Assert.AreEqual(10, result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/StockQuantityServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/StockQuantityServiceTests.csindex 8e834497d..d8049d7ff 100644--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/StockQuantityServiceTests.cs+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/StockQuantityServiceTests.cs@@ -4,9 +4,11 @@ using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Domain.Catalog;using Microsoft.VisualStudio.TestTools.UnitTesting;using Moq;+using Grand.Domain.Common;namespace Grand.Business.Catalog.Tests.Service.Products{+ [TestClass()]public class StockQuantityServiceTests{private IStockQuantityService _stockQuantityService;@@ -17,8 +19,8 @@ namespace Grand.Business.Catalog.Tests.Service.Products{var tempLocalizationService = new Mock<ITranslationService>();{- //tempLocalizationService.Setup(x => x.GetResource("Products.InclTaxSuffix", "1", "", false)).Returns("{0} incl tax");- //tempLocalizationService.Setup(x => x.GetResource("Products.ExclTaxSuffix", "1", "", false)).Returns("{0} excl tax");+ tempLocalizationService.Setup(x => x.GetResource("Products.Availability.InStockWithQuantity")).Returns("{0}");+ tempLocalizationService.Setup(x => x.GetResource("Products.ExclTaxSuffix")).Returns("InStock");_translationService = tempLocalizationService.Object;}_stockQuantityService = new StockQuantityService(@@ -110,7 +112,53 @@ namespace Grand.Business.Catalog.Tests.Service.Products//-1 = 1500-1501Assert.AreEqual(-1, stock);}+ [TestMethod()]+ public void GetTotalStockQuantityTest()+ {+ //Arrange+ var product = new Product {+ ManageInventoryMethodId = ManageInventoryMethod.ManageStock,+ StockAvailability = true,+ StockQuantity = 10,+ ReservedQuantity = 7,+ DisplayStockQuantity = true+ };+ //Act+ var result = _stockQuantityService.GetTotalStockQuantity(product);+ //Assert+ Assert.AreEqual(3, result);+ }++ [TestMethod()]+ public void GetTotalStockQuantityForCombinationTest()+ {+ //Arrange+ var product = new Product {+ ManageInventoryMethodId = ManageInventoryMethod.ManageStockByAttributes,+ StockAvailability = true,+ DisplayStockQuantity = true+ };+ //Act+ var result = _stockQuantityService.GetTotalStockQuantityForCombination(product, new ProductAttributeCombination() { StockQuantity = 10 });+ //Assert+ Assert.AreEqual(10, result);+ }+ [TestMethod()]+ public void FormatStockMessageTest()+ {+ //Arrange+ var product = new Product {+ ManageInventoryMethodId = ManageInventoryMethod.ManageStock,+ StockQuantity = 8765,+ StockAvailability = true,+ DisplayStockQuantity = true+ };+ //Act+ var result = _stockQuantityService.FormatStockMessage(product, "", new List<CustomAttribute>());+ //Assert+ Assert.AreEqual("8765", result);+ }}}