Skip to content

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.

Add tests

support384f09e84aa3
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/BrandDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/BrandDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..861e72007
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/BrandDeletedEventHandlerTests.cs
@@ -0,0 +1,43 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class BrandDeletedEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private BrandDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Product>();
+ _handler = new BrandDeletedEventHandler(_repository);
+ }
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var brand = new Brand();
+ var product = new Product();
+ product.BrandId = brand.Id;
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.BrandId = brand.Id;
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.BrandId = "1";
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Brand>(brand), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.BrandId == brand.Id).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.BrandId == "1").Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/CategoryDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/CategoryDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..dc37a628e
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/CategoryDeletedEventHandlerTests.cs
@@ -0,0 +1,57 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Seo;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class CategoryDeletedEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private IRepository<EntityUrl> _entityUrlRepository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+
+ private CategoryDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _mediatorMock = new Mock<IMediator>();
+ _repository = new MongoDBRepositoryTest<Product>();
+ _entityUrlRepository = new MongoDBRepositoryTest<EntityUrl>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+
+ _handler = new CategoryDeletedEventHandler(_entityUrlRepository, _repository, _cacheBase);
+ }
+
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var category = new Category();
+ var product = new Product();
+ product.ProductCategories.Add(new ProductCategory() { CategoryId = category.Id });
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.ProductCategories.Add(new ProductCategory() { CategoryId = category.Id });
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.ProductCategories.Add(new ProductCategory() { CategoryId = "1" });
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Category>(category), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.ProductCategories.Any(y => y.CategoryId == category.Id)).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.ProductCategories.Any(y => y.CategoryId == "1")).Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/CollectionDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/CollectionDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..d082664e5
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/CollectionDeletedEventHandlerTests.cs
@@ -0,0 +1,57 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Seo;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class CollectionDeletedEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private IRepository<EntityUrl> _entityUrlRepository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+
+ private CollectionDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _mediatorMock = new Mock<IMediator>();
+ _repository = new MongoDBRepositoryTest<Product>();
+ _entityUrlRepository = new MongoDBRepositoryTest<EntityUrl>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+
+ _handler = new CollectionDeletedEventHandler(_entityUrlRepository, _repository, _cacheBase);
+ }
+
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var collection = new Collection();
+ var product = new Product();
+ product.ProductCollections.Add(new ProductCollection() { CollectionId = collection.Id });
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.ProductCollections.Add(new ProductCollection() { CollectionId = collection.Id });
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.ProductCollections.Add(new ProductCollection() { CollectionId = "1" });
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Collection>(collection), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.ProductCollections.Any(y => y.CollectionId == collection.Id)).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.ProductCollections.Any(y => y.CollectionId == "1")).Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DeleteMeasureUnitOnProductEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DeleteMeasureUnitOnProductEventHandlerTests.cs
new file mode 100644
index 000000000..27ffd30ed
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DeleteMeasureUnitOnProductEventHandlerTests.cs
@@ -0,0 +1,45 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Directory;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class DeleteMeasureUnitOnProductEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private DeleteMeasureUnitOnProductEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Product>();
+ _handler = new DeleteMeasureUnitOnProductEventHandler(_repository);
+ }
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var measureUnit = new MeasureUnit();
+ var product = new Product();
+ product.UnitId = measureUnit.Id;
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.UnitId = measureUnit.Id;
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.UnitId = "1";
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<MeasureUnit>(measureUnit), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.UnitId == measureUnit.Id).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.UnitId == "1").Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DeliveryDateDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DeliveryDateDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..69aba5b3f
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DeliveryDateDeletedEventHandlerTests.cs
@@ -0,0 +1,45 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Shipping;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class DeliveryDateDeletedEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private DeliveryDateDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Product>();
+ _handler = new DeliveryDateDeletedEventHandler(_repository);
+ }
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var deliveryDate = new DeliveryDate();
+ var product = new Product();
+ product.DeliveryDateId = deliveryDate.Id;
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.DeliveryDateId = deliveryDate.Id;
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.DeliveryDateId = "1";
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<DeliveryDate>(deliveryDate), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.DeliveryDateId == deliveryDate.Id).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.DeliveryDateId == "1").Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DiscountDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DiscountDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..6d720e182
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/DiscountDeletedEventHandlerTests.cs
@@ -0,0 +1,119 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Discounts;
+using Grand.Domain.Seo;
+using Grand.Domain.Vendors;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class DiscountDeletedEventHandlerTests
+ {
+ private IRepository<Product> _productRepository;
+ private IRepository<Category> _categoryRepository;
+ private IRepository<Brand> _brandRepository;
+ private IRepository<Collection> _collectionRepository;
+ private IRepository<Vendor> _vendorRepository;
+ private IRepository<DiscountCoupon> _discountCouponRepository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+
+ private DiscountDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _mediatorMock = new Mock<IMediator>();
+ _productRepository = new MongoDBRepositoryTest<Product>();
+ _categoryRepository = new MongoDBRepositoryTest<Category>();
+ _brandRepository = new MongoDBRepositoryTest<Brand>();
+ _collectionRepository = new MongoDBRepositoryTest<Collection>();
+ _vendorRepository = new MongoDBRepositoryTest<Vendor>();
+ _discountCouponRepository = new MongoDBRepositoryTest<DiscountCoupon>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+
+ _handler = new DiscountDeletedEventHandler(_productRepository, _categoryRepository,
+ _brandRepository, _collectionRepository, _vendorRepository, _discountCouponRepository, _cacheBase);
+ }
+
+ [TestMethod()]
+ public async Task Handle_Product_Test()
+ {
+ //Arrange
+ var discount = new Discount() { DiscountTypeId = DiscountType.AssignedToSkus };
+ var product = new Product();
+ product.AppliedDiscounts.Add(discount.Id);
+ await _productRepository.InsertAsync(product);
+ var product3 = new Product();
+ product3.AppliedDiscounts.Add("1");
+ await _productRepository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Discount>(discount), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _productRepository.Table.Where(x => x.AppliedDiscounts.Contains(discount.Id)).Count());
+ Assert.AreEqual(1, _productRepository.Table.Where(x => x.AppliedDiscounts.Contains("1")).Count());
+ }
+ [TestMethod()]
+ public async Task Handle_Category_Test()
+ {
+ //Arrange
+ var discount = new Discount() { DiscountTypeId = DiscountType.AssignedToCategories };
+ var category = new Category();
+ category.AppliedDiscounts.Add(discount.Id);
+ await _categoryRepository.InsertAsync(category);
+ var category3 = new Category();
+ category3.AppliedDiscounts.Add("1");
+ await _categoryRepository.InsertAsync(category3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Discount>(discount), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0,_categoryRepository.Table.Where(x => x.AppliedDiscounts.Contains(discount.Id)).Count());
+ Assert.AreEqual(1, _categoryRepository.Table.Where(x => x.AppliedDiscounts.Contains("1")).Count());
+ }
+
+ [TestMethod()]
+ public async Task Handle_Collection_Test()
+ {
+ //Arrange
+ var discount = new Discount() { DiscountTypeId = DiscountType.AssignedToCollections };
+ var collection = new Collection();
+ collection.AppliedDiscounts.Add(discount.Id);
+ await _collectionRepository.InsertAsync(collection);
+ var collection3 = new Category();
+ collection3.AppliedDiscounts.Add("1");
+ await _categoryRepository.InsertAsync(collection3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Discount>(discount), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _collectionRepository.Table.Where(x => x.AppliedDiscounts.Contains(discount.Id)).Count());
+ Assert.AreEqual(1, _collectionRepository.Table.Where(x => x.AppliedDiscounts.Contains("1")).Count());
+ }
+ [TestMethod()]
+ public async Task Handle_Vendor_Test()
+ {
+ //Arrange
+ var discount = new Discount() { DiscountTypeId = DiscountType.AssignedToVendors };
+ var vendor = new Vendor();
+ vendor.AppliedDiscounts.Add(discount.Id);
+ await _vendorRepository.InsertAsync(vendor);
+ var vendor3 = new Vendor();
+ vendor3.AppliedDiscounts.Add("1");
+ await _vendorRepository.InsertAsync(vendor3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Discount>(discount), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _vendorRepository.Table.Where(x => x.AppliedDiscounts.Contains(discount.Id)).Count());
+ Assert.AreEqual(1, _vendorRepository.Table.Where(x => x.AppliedDiscounts.Contains("1")).Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/ProductPublishEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/ProductPublishEventHandlerTests.cs
new file mode 100644
index 000000000..fbb4511f4
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/ProductPublishEventHandlerTests.cs
@@ -0,0 +1,39 @@
+using Grand.Infrastructure.Caching;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class ProductPublishEventHandlerTests
+ {
+
+ ProductPublishEventHandler handlerPublish;
+ ProductUnPublishEventHandler handlerUnPublish;
+ private Mock<ICacheBase> _casheManagerMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _casheManagerMock = new Mock<ICacheBase>();
+ handlerPublish = new ProductPublishEventHandler(_casheManagerMock.Object);
+ handlerUnPublish = new ProductUnPublishEventHandler(_casheManagerMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task Handle_Publish()
+ {
+ //Act
+ await handlerPublish.Handle(new Core.Events.Catalog.ProductPublishEvent(new Domain.Catalog.Product() { ShowOnHomePage = true }), CancellationToken.None);
+ _casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(1));
+
+ }
+ [TestMethod()]
+ public async Task Handle_UnPublish()
+ {
+ //Act
+ await handlerUnPublish.Handle(new Core.Events.Catalog.ProductUnPublishEvent(new Domain.Catalog.Product() { ShowOnHomePage = true }), CancellationToken.None);
+ _casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(1));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/TaxCategoryDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/TaxCategoryDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..1c346e8f6
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/TaxCategoryDeletedEventHandlerTests.cs
@@ -0,0 +1,44 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Tax;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class TaxCategoryDeletedEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private TaxCategoryDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Product>();
+ _handler = new TaxCategoryDeletedEventHandler(_repository);
+ }
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var taxCategory = new TaxCategory();
+ var product = new Product();
+ product.TaxCategoryId = taxCategory.Id;
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.TaxCategoryId = taxCategory.Id;
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.TaxCategoryId = "1";
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<TaxCategory>(taxCategory), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.TaxCategoryId == taxCategory.Id).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.TaxCategoryId == "1").Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/UpdateProductOnCartEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/UpdateProductOnCartEventHandlerTests.cs
new file mode 100644
index 000000000..5a0a7be2f
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/UpdateProductOnCartEventHandlerTests.cs
@@ -0,0 +1,55 @@
+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.Customers;
+using Grand.Domain.Data;
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class UpdateProductOnCartEventHandlerTests
+ {
+ private IRepository<Customer> _repository;
+ private UpdateProductOnCartEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Customer>();
+ _handler = new UpdateProductOnCartEventHandler(_repository);
+ }
+
+
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var product = new Product();
+ var customer = new Customer();
+ customer.ShoppingCartItems.Add(new Domain.Orders.ShoppingCartItem()
+ {
+ ProductId = product.Id,
+ IsFreeShipping = !product.IsFreeShipping,
+ IsShipEnabled = !product.IsShipEnabled,
+ IsTaxExempt = !product.IsTaxExempt,
+ IsGiftVoucher = !product.IsGiftVoucher,
+ });
+ //Act
+ await _handler.Handle(new Core.Events.Catalog.UpdateProductOnCartEvent(product), CancellationToken.None);
+
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.ShoppingCartItems.Any(y => y.IsTaxExempt == product.IsTaxExempt)).Count());
+ Assert.AreEqual(0, _repository.Table.Where(x => x.ShoppingCartItems.Any(y => y.IsFreeShipping == product.IsFreeShipping)).Count());
+ Assert.AreEqual(0, _repository.Table.Where(x => x.ShoppingCartItems.Any(y => y.IsFreeShipping == product.IsFreeShipping)).Count());
+ Assert.AreEqual(0, _repository.Table.Where(x => x.ShoppingCartItems.Any(y => y.IsGiftVoucher == product.IsGiftVoucher)).Count());
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/WarehouseDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/WarehouseDeletedEventHandlerTests.cs
new file mode 100644
index 000000000..4174e1d77
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Events/Handlers/WarehouseDeletedEventHandlerTests.cs
@@ -0,0 +1,45 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Domain.Shipping;
+using Grand.Domain.Tax;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Business.Catalog.Events.Handlers.Tests
+{
+ [TestClass()]
+ public class WarehouseDeletedEventHandlerTests
+ {
+ private IRepository<Product> _repository;
+ private WarehouseDeletedEventHandler _handler;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Product>();
+ _handler = new WarehouseDeletedEventHandler(_repository);
+ }
+
+ [TestMethod()]
+ public async Task HandleTest()
+ {
+ //Arrange
+ var warehouse = new Warehouse();
+ var product = new Product();
+ product.WarehouseId = warehouse.Id;
+ await _repository.InsertAsync(product);
+ var product2 = new Product();
+ product2.WarehouseId = warehouse.Id;
+ await _repository.InsertAsync(product2);
+ var product3 = new Product();
+ product3.WarehouseId = "1";
+ await _repository.InsertAsync(product3);
+
+ //Act
+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Warehouse>(warehouse), CancellationToken.None);
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Where(x => x.WarehouseId == warehouse.Id).Count());
+ Assert.AreEqual(1, _repository.Table.Where(x => x.WarehouseId == "1").Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs
index 871322ec7..f63a06d02 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs
@@ -78,7 +78,6 @@ namespace Grand.Business.Catalog.Tests.Services.Categories
//Assert
Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test1"));
Assert.AreEqual(1, _repository.Table.Count());
-
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxCategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxCategoryServiceTests.cs
new file mode 100644
index 000000000..171b899cb
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxCategoryServiceTests.cs
@@ -0,0 +1,111 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Data;
+using Grand.Domain.Tax;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Tax.Tests
+{
+ [TestClass()]
+ public class TaxCategoryServiceTests
+ {
+ private IRepository<TaxCategory> _repository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+ private TaxCategoryService _taxCategoryService;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<TaxCategory>();
+ _mediatorMock = new Mock<IMediator>();
+
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _taxCategoryService = new TaxCategoryService(_cacheBase, _repository, _mediatorMock.Object);
+ }
+
+
+ [TestMethod()]
+ public async Task GetAllTaxCategoriesTest()
+ {
+ //Arrange
+ await _taxCategoryService.InsertTaxCategory(new TaxCategory());
+ await _taxCategoryService.InsertTaxCategory(new TaxCategory());
+ await _taxCategoryService.InsertTaxCategory(new TaxCategory());
+
+ //Act
+ var result = await _taxCategoryService.GetAllTaxCategories();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+
+ }
+
+ [TestMethod()]
+ public async Task GetTaxCategoryByIdTest()
+ {
+ //Arrange
+ var taxCategory = new TaxCategory() {
+ Name = "test1"
+ };
+ await _repository.InsertAsync(taxCategory);
+ //Assert
+ var result = await _taxCategoryService.GetTaxCategoryById(taxCategory.Id);
+
+ //Act
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test1", result.Name);
+
+ }
+
+ [TestMethod()]
+ public async Task InsertTaxCategoryTest()
+ {
+ //Act
+ await _taxCategoryService.InsertTaxCategory(new TaxCategory());
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+
+ }
+
+ [TestMethod()]
+ public async Task UpdateTaxCategoryTest()
+ {
+ //Arrange
+ var tax = new TaxCategory() {
+ Name = "test"
+ };
+ await _taxCategoryService.InsertTaxCategory(tax);
+ tax.Name = "test2";
+
+ //Act
+ await _taxCategoryService.UpdateTaxCategory(tax);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+
+ }
+
+ [TestMethod()]
+ public async Task DeleteTaxCategoryTest()
+ {
+ //Arrange
+ var tax = new TaxCategory() {
+ Name = "test"
+ };
+ await _taxCategoryService.InsertTaxCategory(tax);
+ await _taxCategoryService.InsertTaxCategory(new TaxCategory());
+ //Act
+ await _taxCategoryService.DeleteTaxCategory(tax);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test"));
+ Assert.AreEqual(1, _repository.Table.Count());
+
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/VatServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/VatServiceTests.cs
new file mode 100644
index 000000000..e8ea7e506
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/VatServiceTests.cs
@@ -0,0 +1,63 @@
+using Grand.Domain.Tax;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Business.Catalog.Services.Tax.Tests
+{
+ [TestClass()]
+ public class VatServiceTests
+ {
+ private VatService _vatService;
+ private TaxSettings _taxSettings;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _taxSettings = new TaxSettings() { EuVatAssumeValid = true, EuVatUseWebService = false };
+ _vatService = new VatService(_taxSettings);
+ }
+
+ [DataRow("PL1111111111")]
+ [DataRow("1111111111")]
+ [TestMethod()]
+ public async Task GetVatNumberStatusTest(string vat)
+ {
+ //Act
+ var result = await _vatService.GetVatNumberStatus(vat);
+ //Assert
+ Assert.AreEqual(VatNumberStatus.Valid, result.status);
+ }
+ [TestMethod()]
+ public async Task GetVatNumberStatusTest_Valid()
+ {
+ //Act
+ var result = await _vatService.GetVatNumberStatus("PL", "1111111111");
+ //Assert
+ Assert.AreEqual(VatNumberStatus.Valid, result.status);
+ }
+ [TestMethod()]
+ public async Task GetVatNumberStatusTest_InValid()
+ {
+ //Act
+ var result = await _vatService.GetVatNumberStatus("PL", "");
+ //Assert
+ Assert.AreEqual(VatNumberStatus.Empty, result.status);
+ }
+ [TestMethod()]
+ public async Task DoVatCheckTest()
+ {
+ //Act
+ var result = await _vatService.DoVatCheck("PL", "1111111111");
+ //Assert
+ Assert.AreEqual(VatNumberStatus.Invalid, result.status);
+ }
+
+ [TestMethod()]
+ public async Task CheckVatRequestTest()
+ {
+ //Act
+ var result = await _vatService.CheckVatRequest(new Core.Utilities.Catalog.VatRequest());
+ //Assert
+ Assert.IsNotNull(result);
+ }
+ }
+}
\ No newline at end of file