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.

Minor changes - test (remove unused using)

KrzysztofPajakb5712ab2f2fe
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
index 48fa41749..7487e6bce 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
@@ -1,19 +1,14 @@
using Grand.Business.Catalog.Commands.Handlers;
using Grand.Business.Catalog.Commands.Models;
using Grand.Domain.Catalog;
-using Grand.Domain.Data;
using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Events;
using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs
index 0581f2fd5..dcb72e079 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs
@@ -1,92 +1,86 @@
-using Grand.Business.Catalog.Commands.Handlers;
-using Grand.Business.Catalog.Commands.Models;
-using Grand.Business.Catalog.Interfaces.Products;
-using Grand.Domain;
-using Grand.Domain.Catalog;
-using Grand.Domain.Data;
-using Grand.Domain.Data.Mongo;
-using Grand.Infrastructure.Caching;
-using Grand.SharedKernel.Extensions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
-using Moq;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+//using Grand.Business.Catalog.Commands.Handlers;
+//using Grand.Business.Catalog.Interfaces.Products;
+//using Grand.Domain;
+//using Grand.Domain.Catalog;
+//using Grand.Domain.Data.Mongo;
+//using Grand.Infrastructure.Caching;
+//using Grand.SharedKernel.Extensions;
+//using Microsoft.VisualStudio.TestTools.UnitTesting;
+//using Moq;
+//using System.Collections.Generic;
+//using System.Threading.Tasks;
-namespace Grand.Business.Catalog.Tests.Handlers
-{
- [TestClass()]
- public class UpdateProductReviewTotalsCommandHandlerTest
- {
- private Mock<MongoRepository<Product>> _productRepositoryMock;
- private Mock<ICacheBase> _cacheBaseMock;
- private UpdateProductReviewTotalsCommandHandler _updateProductReviewTotalsCommandHandler;
- private Mock<IMongoCollection<Product>> _mongoCollectionMock;
- private Mock<IProductReviewService> _productReviewServiceMock;
+//namespace Grand.Business.Catalog.Tests.Handlers
+//{
+// [TestClass()]
+// public class UpdateProductReviewTotalsCommandHandlerTest
+// {
+// private Mock<MongoRepository<Product>> _productRepositoryMock;
+// private Mock<ICacheBase> _cacheBaseMock;
+// private UpdateProductReviewTotalsCommandHandler _updateProductReviewTotalsCommandHandler;
+// private Mock<IMongoCollection<Product>> _mongoCollectionMock;
+// private Mock<IProductReviewService> _productReviewServiceMock;
- [TestInitialize()]
- public void Init()
- {
- CommonPath.BaseDirectory = "";
+// [TestInitialize()]
+// public void Init()
+// {
+// CommonPath.BaseDirectory = "";
- var reviews = new List<ProductReview> {
- new ProductReview { Id = "1", ReplyText = "text1"},
- new ProductReview { Id = "2", ReplyText = "text2"}};
+// var reviews = new List<ProductReview> {
+// new ProductReview { Id = "1", ReplyText = "text1"},
+// new ProductReview { Id = "2", ReplyText = "text2"}};
- _mongoCollectionMock = new Mock<IMongoCollection<Product>>();
- _mongoCollectionMock.SetupAllProperties();
- _mongoCollectionMock.Setup(x => x.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(),
- It.IsAny<UpdateDefinition<Product>>(),
- It.IsAny<UpdateOptions>(),
- default));
+// _mongoCollectionMock = new Mock<IMongoCollection<Product>>();
+// _mongoCollectionMock.SetupAllProperties();
+// _mongoCollectionMock.Setup(x => x.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(),
+// It.IsAny<UpdateDefinition<Product>>(),
+// It.IsAny<UpdateOptions>(),
+// default));
- _productRepositoryMock = new Mock<MongoRepository<Product>>();
- _productRepositoryMock.Setup(x => x.Collection).Returns(_mongoCollectionMock.Object);
+// _productRepositoryMock = new Mock<MongoRepository<Product>>();
+// _productRepositoryMock.Setup(x => x.Collection).Returns(_mongoCollectionMock.Object);
- _cacheBaseMock = new Mock<ICacheBase>();
+// _cacheBaseMock = new Mock<ICacheBase>();
- _productReviewServiceMock = new Mock<IProductReviewService>();
- IPagedList<ProductReview> pagedListReviews = new PagedList<ProductReview>(reviews, 0, 234567);
- _productReviewServiceMock.Setup(x => x.GetAllProductReviews(null,
- null,
- null,
- null,
- null,
- null,
- It.IsAny<string>(), 0, It.IsAny<int>())).Returns(Task.FromResult(pagedListReviews));
+// _productReviewServiceMock = new Mock<IProductReviewService>();
+// IPagedList<ProductReview> pagedListReviews = new PagedList<ProductReview>(reviews, 0, 234567);
+// _productReviewServiceMock.Setup(x => x.GetAllProductReviews(null,
+// null,
+// null,
+// null,
+// null,
+// null,
+// It.IsAny<string>(), 0, It.IsAny<int>())).Returns(Task.FromResult(pagedListReviews));
- _updateProductReviewTotalsCommandHandler = new UpdateProductReviewTotalsCommandHandler(
- _productRepositoryMock.Object,
- _productReviewServiceMock.Object,
- _cacheBaseMock.Object);
- }
+// _updateProductReviewTotalsCommandHandler = new UpdateProductReviewTotalsCommandHandler(
+// _productRepositoryMock.Object,
+// _productReviewServiceMock.Object,
+// _cacheBaseMock.Object);
+// }
- //[TestMethod()]
- //public async Task InsertProduct_NullArgument_ThrowException()
- //{
- // var request = new UpdateProductReviewTotalsCommand();
+// //[TestMethod()]
+// //public async Task InsertProduct_NullArgument_ThrowException()
+// //{
+// // var request = new UpdateProductReviewTotalsCommand();
- // await Assert.ThrowsExceptionAsync<ArgumentNullException>(
- // async () => await _updateProductReviewTotalsCommandHandler.Handle(request, default));
- //}
+// // await Assert.ThrowsExceptionAsync<ArgumentNullException>(
+// // async () => await _updateProductReviewTotalsCommandHandler.Handle(request, default));
+// //}
- //[TestMethod()]
- //public async Task UpdateProductReviews_ValidArgument_InvokeRepositoryAndCache()
- //{
- // var request = new UpdateProductReviewTotalsCommand { Product = new Product() };
- // await _updateProductReviewTotalsCommandHandler.Handle(request, default);
+// //[TestMethod()]
+// //public async Task UpdateProductReviews_ValidArgument_InvokeRepositoryAndCache()
+// //{
+// // var request = new UpdateProductReviewTotalsCommand { Product = new Product() };
+// // await _updateProductReviewTotalsCommandHandler.Handle(request, default);
- // //_productReviewServiceMock.Verify(x => x.GetAllProductReviews(null, null, null, null, null,
- // // null, It.IsAny<string>(), 0, It.IsAny<int>()), Times.Once);
- // //TODO
- // //_productRepositoryMock.Verify(x => x.Collection.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(),
- // // It.IsAny<UpdateDefinition<Product>>(),
- // // It.IsAny<UpdateOptions>(),
- // // default), Times.Once);
- //}
- }
-}
+// // //_productReviewServiceMock.Verify(x => x.GetAllProductReviews(null, null, null, null, null,
+// // // null, It.IsAny<string>(), 0, It.IsAny<int>()), Times.Once);
+// // //TODO
+// // //_productRepositoryMock.Verify(x => x.Collection.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(),
+// // // It.IsAny<UpdateDefinition<Product>>(),
+// // // It.IsAny<UpdateOptions>(),
+// // // default), Times.Once);
+// //}
+// }
+//}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
index c62cb611b..0bc8eb53c 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
@@ -10,7 +10,6 @@ using Grand.Infrastructure.Events;
using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
using System;
using System.Collections.Generic;
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceFormatterTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceFormatterTests.cs
index 6d96efe25..863a45f75 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceFormatterTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceFormatterTests.cs
@@ -2,27 +2,22 @@
using Grand.Business.Catalog.Services.Prices;
using Grand.Business.Common.Interfaces.Directory;
using Grand.Business.Common.Interfaces.Localization;
-using Grand.Business.Common.Interfaces.Providers;
using Grand.Business.Common.Interfaces.Security;
-using Grand.Business.Common.Interfaces.Stores;
using Grand.Business.Common.Services.Directory;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Domain.Directory;
using Grand.Domain.Localization;
using Grand.Domain.Tax;
using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
+using Grand.SharedKernel.Extensions;
using MediatR;
-using Microsoft.Extensions.Caching.Memory;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading;
-using System.Threading.Tasks;
namespace Grand.Business.Catalog.Tests.Service.Prices
{
@@ -34,7 +29,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
private CurrencySettings _currencySettings;
private IWorkContext _workContext;
private Mock<IWorkContext> tempWorkContext;
-
+
private TaxSettings _taxSettings;
private IPriceFormatter _priceFormatter;
private IAclService _aclService;
@@ -45,6 +40,8 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
[TestInitialize()]
public void TestInitialize()
{
+ CommonPath.BaseDirectory = "";
+
var eventPublisher = new Mock<IMediator>();
_eventPublisher = eventPublisher.Object;
@@ -54,8 +51,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
_workContext = tempWorkContext.Object;
}
_currencySettings = new CurrencySettings();
- var currency01 = new Currency
- {
+ var currency01 = new Currency {
Id = "1",
Name = "Euro",
CurrencyCode = "EUR",
@@ -67,8 +63,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
UpdatedOnUtc = DateTime.UtcNow
};
- var currency02 = new Currency
- {
+ var currency02 = new Currency {
Id = "1",
Name = "US Dollar",
CurrencyCode = "USD",
@@ -82,10 +77,10 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
var tempCurrencyRepo = new Mock<IRepository<Currency>>();
{
- var tempIMongoCollection = new Mock<IMongoCollection<Currency>>().Object;
- tempIMongoCollection.InsertOne(currency01);
- tempIMongoCollection.InsertOne(currency02);
- tempCurrencyRepo.Setup(x => x.Table).Returns(tempIMongoCollection.AsQueryable());
+ var tempIMongoCollection = new Mock<MongoRepository<Currency>>().Object;
+ tempIMongoCollection.Insert(currency01);
+ tempIMongoCollection.Insert(currency02);
+ tempCurrencyRepo.Setup(x => x.Table).Returns(tempIMongoCollection.Table);
}
_aclService = new Mock<IAclService>().Object;
@@ -93,7 +88,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
_currencyRepo = new Mock<IRepository<Currency>>().Object;
-
+
_currencyService = new CurrencyService(
cacheManager.Object,
_currencyRepo,
@@ -105,8 +100,8 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
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.InclTaxSuffix", "1", "", false)).Returns("{0} incl tax");
+ tempLocalizationService.Setup(x => x.GetResource("Products.ExclTaxSuffix", "1", "", false)).Returns("{0} excl tax");
_translationService = tempLocalizationService.Object;
}
@@ -118,8 +113,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
- var currency0111 = new Currency
- {
+ var currency0111 = new Currency {
Id = "1",
Name = "Euro",
CurrencyCode = "EUR",
@@ -133,8 +127,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
MidpointRoundId = MidpointRounding.AwayFromZero
};
- var language0111 = new Language
- {
+ var language0111 = new Language {
Id = "1",
Name = "English",
LanguageCulture = "en-US"
@@ -147,8 +140,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
public void Can_formatPrice_with_distinct_currencyDisplayLocale()
{
- var usd_currency = new Currency
- {
+ var usd_currency = new Currency {
Id = "1",
Name = "US Dollar",
CurrencyCode = "USD",
@@ -156,24 +148,21 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
MidpointRoundId = MidpointRounding.AwayFromZero,
};
- var gbp_currency = new Currency
- {
+ var gbp_currency = new Currency {
Id = "2",
Name = "great british pound",
CurrencyCode = "GBP",
DisplayLocale = "en-GB",
MidpointRoundId = MidpointRounding.AwayFromZero,
};
- var euro_currency = new Currency
- {
+ var euro_currency = new Currency {
Id = "3",
Name = "Euro",
CurrencyCode = "EUR",
DisplayLocale = "en_150",
MidpointRoundId = MidpointRounding.AwayFromZero,
};
- var language = new Language
- {
+ var language = new Language {
Id = "1",
Name = "English",
LanguageCulture = "en-US"
@@ -189,16 +178,14 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
//$18,888.10 incl tax priceIncludestax=true || showTax=true
//$18,888.10 excl tax priceIncludestax=false || showTax=true
- var currency = new Currency
- {
+ var currency = new Currency {
Id = "1",
Name = "US Dollar",
CurrencyCode = "USD",
DisplayLocale = "en-US",
MidpointRoundId = MidpointRounding.AwayFromZero,
};
- var language = new Language
- {
+ var language = new Language {
Id = "1",
Name = "English",
LanguageCulture = "en-US"
@@ -218,15 +205,13 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
//DisplayCurrecyLabel = true $123.00 (USD)
//DisplayCurrecyLabel = false $123.00
- var currency = new Currency
- {
+ var currency = new Currency {
Id = "1",
Name = "US Dollar",
CurrencyCode = "USD",
DisplayLocale = "en-US",
};
- var language = new Language
- {
+ var language = new Language {
Id = "1",
Name = "English",
LanguageCulture = "en-US"
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceServiceTests.cs
index 8d1c30d1a..d6e18b534 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceServiceTests.cs
@@ -1,18 +1,18 @@
-using Grand.Business.Catalog.Interfaces.Categories;
-using Grand.Business.Catalog.Interfaces.Discounts;
+using Grand.Business.Catalog.Interfaces.Brands;
+using Grand.Business.Catalog.Interfaces.Categories;
using Grand.Business.Catalog.Interfaces.Collections;
+using Grand.Business.Catalog.Interfaces.Discounts;
using Grand.Business.Catalog.Interfaces.Prices;
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Catalog.Services.Prices;
using Grand.Business.Catalog.Utilities;
using Grand.Business.Common.Interfaces.Directory;
-using Grand.Business.Common.Interfaces.Providers;
using Grand.Business.Common.Interfaces.Security;
-using Grand.Business.Common.Interfaces.Stores;
using Grand.Business.Common.Services.Directory;
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Domain.Directory;
using Grand.Domain.Discounts;
using Grand.Domain.Orders;
@@ -21,14 +21,11 @@ using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
-using Grand.Business.Catalog.Interfaces.Brands;
namespace Grand.Business.Catalog.Tests.Service.Prices
{
@@ -65,7 +62,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
tempWorkContext.Setup(c => c.CurrentStore).Returns(_store);
_workContext = tempWorkContext.Object;
}
-
+
tempDiscountServiceMock = new Mock<IDiscountService>();
{
_discountService = tempDiscountServiceMock.Object;
@@ -101,11 +98,11 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
IRepository<Currency> _currencyRepository;
var tempCurrencyRepository = new Mock<IRepository<Currency>>();
{
- var IMongoCollection = new Mock<IMongoCollection<Currency>>().Object;
- IMongoCollection.InsertOne(_currency);
+ var IMongoCollection = new Mock<MongoRepository<Currency>>().Object;
+ IMongoCollection.Insert(_currency);
- tempCurrencyRepository.Setup(x => x.Table).Returns(IMongoCollection.AsQueryable());
+ tempCurrencyRepository.Setup(x => x.Table).Returns(IMongoCollection.Table);
tempCurrencyRepository.Setup(x => x.GetByIdAsync(_currency.Id)).ReturnsAsync(_currency);
_currencyRepository = tempCurrencyRepository.Object;
}
@@ -135,8 +132,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
[TestMethod()]
public async Task Can_get_final_product_price()
{
- var product = new Product
- {
+ var product = new Product {
Id = "1",
Name = "product name 01",
Price = 49.99M,
@@ -144,7 +140,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
Published = true,
};
product.ProductPrices.Add(new ProductPrice() { CurrencyCode = "USD", Price = 49.99M });
-
+
var currency = new Currency { Id = "1", CurrencyCode = "USD", Rate = 1, Published = true, MidpointRoundId = System.MidpointRounding.ToEven, RoundingTypeId = RoundingType.Rounding001 };
var customer = new Customer();
var pr = (await _pricingService.GetFinalPrice(product, customer, currency, 0, false, 1));
@@ -156,8 +152,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
[TestMethod()]
public async Task Can_get_final_product_price_with_tier_prices()
{
- var product = new Product
- {
+ var product = new Product {
Id = "1",
Name = "product name 01",
Price = 49.99M,
@@ -166,7 +161,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
};
product.ProductPrices.Add(new ProductPrice() { CurrencyCode = "USD", Price = 49.99M });
//TierPrice is simply "the more you buy, the less you pay"
- product.TierPrices.Add(new TierPrice { Price = 10M, Quantity = 10, CurrencyCode = "USD"});
+ product.TierPrices.Add(new TierPrice { Price = 10M, Quantity = 10, CurrencyCode = "USD" });
product.TierPrices.Add(new TierPrice { Price = 2M, Quantity = 200, CurrencyCode = "USD" });
Customer customer = new Customer();
@@ -192,13 +187,12 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
Assert.AreEqual(2M, (await _pricingService.GetFinalPrice(product, customer, _currency, 0, false, 22201)).finalPrice);
}
-
+
[TestMethod()]
public async Task Can_get_final_product_price_with_additionalFee()
{
//tests if price is valid for additional charge (additional fee)
- var product = new Product
- {
+ var product = new Product {
Id = "1",
Name = "product name 01",
Price = 49.99M,
@@ -216,8 +210,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
[TestMethod()]
public async Task Can_get_final_product_price_with_discount()
{
- var product = new Product
- {
+ var product = new Product {
Id = "1",
Name = "product name 01",
Price = 49.99M,
@@ -227,8 +220,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
product.ProductPrices.Add(new ProductPrice() { CurrencyCode = "USD", Price = 49.99M });
var customer = new Customer();
- var discount001 = new Discount
- {
+ var discount001 = new Discount {
Id = "1",
Name = "Discount 001",
DiscountTypeId = DiscountType.AssignedToSkus,
@@ -242,7 +234,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
product.AppliedDiscounts.Add(discount001.Id);
tempDiscountServiceMock.Setup(x => x.ValidateDiscount(discount001, customer, _currency)).ReturnsAsync(new DiscountValidationResult() { IsValid = true });
- tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToCategories, "1", _currency.CurrencyCode,"", "", false)).ReturnsAsync(new List<Discount>());
+ tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToCategories, "1", _currency.CurrencyCode, "", "", false)).ReturnsAsync(new List<Discount>());
tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToCollections, "1", _currency.CurrencyCode, "", "", false)).ReturnsAsync(new List<Discount>());
tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToAllProducts, "1", _currency.CurrencyCode, "", "", false)).ReturnsAsync(new List<Discount>());
tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToSkus, "1", _currency.CurrencyCode, "", "", false)).ReturnsAsync(new List<Discount>() { discount001 });
@@ -263,8 +255,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
var customer001 = new Customer { Id = "98767" };
tempWorkContext.Setup(x => x.CurrentCustomer).Returns(customer001);
tempWorkContext.Setup(x => x.WorkingCurrency).Returns(_currency);
- var product001 = new Product
- {
+ var product001 = new Product {
Id = "242422",
Name = "product name 01",
Price = 49.99M,
@@ -275,8 +266,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
tempProductService.Setup(x => x.GetProductById("242422", false)).ReturnsAsync(product001);
- var shoppingCartItem = new ShoppingCartItem
- {
+ var shoppingCartItem = new ShoppingCartItem {
ProductId = product001.Id,
Quantity = 2
};
@@ -293,8 +283,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
[TestMethod()]
public async Task Can_get_shopping_cart_item_subTotal()
{
- var product001 = new Product
- {
+ var product001 = new Product {
Id = "242422",
Name = "product name 01",
Price = 55.11M,
@@ -307,8 +296,7 @@ namespace Grand.Business.Catalog.Tests.Service.Prices
var customer001 = new Customer { Id = "98767" };
tempWorkContext.Setup(x => x.CurrentCustomer).Returns(customer001);
tempWorkContext.Setup(x => x.WorkingCurrency).Returns(_currency);
- var shoppingCartItem = new ShoppingCartItem
- {
+ var shoppingCartItem = new ShoppingCartItem {
ProductId = product001.Id, //222
Quantity = 2
};
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs
index c8fcfdc31..42cbb2679 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs
@@ -3,19 +3,17 @@ using Grand.Business.Checkout.Services.CheckoutAttributes;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Domain.Localization;
using Grand.Domain.Orders;
using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
+using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
-using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
{
@@ -35,9 +33,10 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
[TestInitialize()]
public void TestInitialize()
{
+ CommonPath.BaseDirectory = "";
+
//color choosing via DropDownList
- ca1 = new CheckoutAttribute
- {
+ ca1 = new CheckoutAttribute {
Id = "1",
Name = "Color",
TextPrompt = "Select color:",
@@ -45,16 +44,14 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
AttributeControlTypeId = AttributeControlType.DropdownList,
DisplayOrder = 1,
};
- cav1_1 = new CheckoutAttributeValue
- {
+ cav1_1 = new CheckoutAttributeValue {
Id = "11",
Name = "Green",
DisplayOrder = 1,
//CheckoutAttribute = ca1,
CheckoutAttributeId = ca1.Id,
};
- cav1_2 = new CheckoutAttributeValue
- {
+ cav1_2 = new CheckoutAttributeValue {
Id = "12",
Name = "Red",
DisplayOrder = 2,
@@ -65,8 +62,7 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
ca1.CheckoutAttributeValues.Add(cav1_2);
//choosing via CheckBox'es
- ca2 = new CheckoutAttribute
- {
+ ca2 = new CheckoutAttribute {
Id = "2",
Name = "Custom option",
TextPrompt = "Select custom option:",
@@ -76,16 +72,14 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
//CheckoutAttributeValues
};
- cav2_1 = new CheckoutAttributeValue
- {
+ cav2_1 = new CheckoutAttributeValue {
Id = "21",
Name = "Option 1",
DisplayOrder = 1,
//CheckoutAttribute = ca2,
CheckoutAttributeId = ca2.Id,
};
- cav2_2 = new CheckoutAttributeValue
- {
+ cav2_2 = new CheckoutAttributeValue {
Id = "22",
Name = "Option 2",
DisplayOrder = 2,
@@ -96,8 +90,7 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
ca2.CheckoutAttributeValues.Add(cav2_2);
//via MultiTextBoxes
- ca3 = new CheckoutAttribute
- {
+ ca3 = new CheckoutAttribute {
Id = "3",
Name = "Custom text",
TextPrompt = "Enter custom text:",
@@ -114,11 +107,11 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
var tempCheckoutAttributeRepo = new Mock<IRepository<CheckoutAttribute>>();
{
- var IMongoCollection = new Mock<IMongoCollection<CheckoutAttribute>>().Object;
- IMongoCollection.InsertOne(ca1);
- IMongoCollection.InsertOne(ca2);
- IMongoCollection.InsertOne(ca3);
- tempCheckoutAttributeRepo.Setup(x => x.Table).Returns(IMongoCollection.AsQueryable());
+ var IMongoCollection = new Mock<MongoRepository<CheckoutAttribute>>().Object;
+ IMongoCollection.Insert(ca1);
+ IMongoCollection.Insert(ca2);
+ IMongoCollection.Insert(ca3);
+ tempCheckoutAttributeRepo.Setup(x => x.Table).Returns(IMongoCollection.Table);
tempCheckoutAttributeRepo.Setup(x => x.GetByIdAsync(ca1.Id)).ReturnsAsync(ca1);
tempCheckoutAttributeRepo.Setup(x => x.GetByIdAsync(ca2.Id)).ReturnsAsync(ca2);
tempCheckoutAttributeRepo.Setup(x => x.GetByIdAsync(ca3.Id)).ReturnsAsync(ca3);
@@ -129,7 +122,7 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
_workContextMock = new Mock<IWorkContext>();
_checkoutAttributeService = new CheckoutAttributeService(cacheManager.Object, _checkoutAttributeRepo,
- _eventPublisher,_workContextMock.Object);
+ _eventPublisher, _workContextMock.Object);
_checkoutAttributeParser = new CheckoutAttributeParser(_checkoutAttributeService);
@@ -158,7 +151,7 @@ namespace Grand.Business.Checkout.Tests.Services.CheckoutAttributes
Assert.IsTrue(attributes.Any(c => c.Key.Equals(ca1.Id)));
Assert.IsTrue(attributes.Any(c => c.Key.Equals(ca2.Id)));
Assert.IsTrue(attributes.Any(c => c.Key.Equals(ca3.Id)));
- attributes=_checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca1);
+ attributes = _checkoutAttributeParser.RemoveCheckoutAttribute(attributes, ca1);
Assert.IsTrue(attributes.Count == 3);
Assert.IsFalse(attributes.Any(c => c.Key.Equals(ca1.Id)));
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs
index d43b03fab..c39df58d3 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs
@@ -1,18 +1,12 @@
using Grand.Business.Common.Services.Addresses;
using Grand.Domain.Common;
-using Grand.Domain.Data;
using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Events;
using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Grand.Business.Common.Tests.Services.Addresses
@@ -32,7 +26,7 @@ namespace Grand.Business.Common.Tests.Services.Addresses
_cacheMock = new Mock<ICacheBase>();
_repositoryMock = new Mock<MongoRepository<AddressAttribute>>();
_mediatorMock = new Mock<IMediator>();
- _service = new AddressAttributeService(_cacheMock.Object,_repositoryMock.Object,_mediatorMock.Object);
+ _service = new AddressAttributeService(_cacheMock.Object, _repositoryMock.Object, _mediatorMock.Object);
}
[TestMethod()]
@@ -65,7 +59,7 @@ namespace Grand.Business.Common.Tests.Services.Addresses
[TestMethod()]
public async Task InsertAddressAttributeValue_ValidArgument_InvokeExpectedMethod()
{
- await _service.InsertAddressAttributeValue(new AddressAttributeValue() { AddressAttributeId="id"});
+ await _service.InsertAddressAttributeValue(new AddressAttributeValue() { AddressAttributeId = "id" });
_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<AddressAttributeValue>>(), default), Times.Once);
_cacheMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), It.IsAny<bool>()));
}
@@ -73,7 +67,7 @@ namespace Grand.Business.Common.Tests.Services.Addresses
[TestMethod()]
public async Task DeleteAddressAttributeValue_ValidArgument_InvokeExpectedMethod()
{
- await _service.DeleteAddressAttributeValue(new AddressAttributeValue() { AddressAttributeId="id"});
+ await _service.DeleteAddressAttributeValue(new AddressAttributeValue() { AddressAttributeId = "id" });
_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<AddressAttributeValue>>(), default), Times.Once);
_cacheMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), It.IsAny<bool>()));
}
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Directory/CurrencyServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Directory/CurrencyServiceTests.cs
index 013d592c2..a5373eb6e 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Directory/CurrencyServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Directory/CurrencyServiceTests.cs
@@ -2,6 +2,7 @@
using Grand.Business.Common.Interfaces.Security;
using Grand.Business.Common.Services.Directory;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Domain.Directory;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Events;
@@ -9,12 +10,9 @@ using Grand.SharedKernel;
using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
using Moq;
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Grand.Business.Common.Tests.Services.Directory
@@ -40,8 +38,7 @@ namespace Grand.Business.Common.Tests.Services.Directory
CommonHelper.CacheTimeMinutes = 10;
- currencyUSD = new Currency
- {
+ currencyUSD = new Currency {
Id = "1",
Name = "US Dollar",
CurrencyCode = "USD",
@@ -53,8 +50,7 @@ namespace Grand.Business.Common.Tests.Services.Directory
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
};
- currencyEUR = new Currency
- {
+ currencyEUR = new Currency {
Id = "2",
Name = "Euro",
CurrencyCode = "EUR",
@@ -66,8 +62,7 @@ namespace Grand.Business.Common.Tests.Services.Directory
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
};
- currencyRUR = new Currency
- {
+ currencyRUR = new Currency {
Id = "3",
Name = "Russian Rouble",
CurrencyCode = "RUB",
@@ -82,12 +77,12 @@ namespace Grand.Business.Common.Tests.Services.Directory
tempCurrencyRepository = new Mock<IRepository<Currency>>();
{
- var IMongoCollection = new Mock<IMongoCollection<Currency>>().Object;
- IMongoCollection.InsertOne(currencyUSD);
- IMongoCollection.InsertOne(currencyEUR);
- IMongoCollection.InsertOne(currencyRUR);
+ var IMongoCollection = new Mock<MongoRepository<Currency>>().Object;
+ IMongoCollection.Insert(currencyUSD);
+ IMongoCollection.Insert(currencyEUR);
+ IMongoCollection.Insert(currencyRUR);
- tempCurrencyRepository.Setup(x => x.Table).Returns(IMongoCollection.AsQueryable());
+ tempCurrencyRepository.Setup(x => x.Table).Returns(IMongoCollection.Table);
tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyUSD.Id)).ReturnsAsync(currencyUSD);
tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyEUR.Id)).ReturnsAsync(currencyEUR);
tempCurrencyRepository.Setup(x => x.GetByIdAsync(currencyRUR.Id)).ReturnsAsync(currencyRUR);
@@ -113,11 +108,11 @@ namespace Grand.Business.Common.Tests.Services.Directory
_currencyService = new CurrencyService(
_cacheManager.Object, _currencyRepository, _aclService.Object,
- _currencySettings, _eventPublisher);
+ _currencySettings, _eventPublisher);
//tempDiscountServiceMock.Setup(x => x.GetAllDiscounts(DiscountType.AssignedToCategories, "", "", false)).ReturnsAsync(new List<Discount>());
}
-
+
[TestMethod()]
public void Can_convert_currency_1()
{
@@ -153,7 +148,7 @@ namespace Grand.Business.Common.Tests.Services.Directory
}
[TestMethod()]
- public void ConvertToPrimaryExchangeRateCurrency_ZeroExchangeRate_ThrowException()
+ public void ConvertToPrimaryExchangeRateCurrency_ZeroExchangeRate_ThrowException()
{
_cacheManager.Setup(c => c.GetAsync<Currency>(It.IsAny<string>(), It.IsAny<Func<Task<Currency>>>())).Returns(Task.FromResult(currencyUSD));
currencyEUR.Rate = 0;
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/PopupServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/PopupServiceTests.cs
index 4f62c882e..c8f93c7c0 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/PopupServiceTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/PopupServiceTests.cs
@@ -2,14 +2,11 @@
using Grand.Domain.Data;
using Grand.Domain.Messages;
using Grand.Infrastructure.Events;
+using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver.Linq;
using Moq;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Grand.Business.Marketing.Tests.Services.Contacts
@@ -25,10 +22,12 @@ namespace Grand.Business.Marketing.Tests.Services.Contacts
[TestInitialize()]
public void Init()
{
+ CommonPath.BaseDirectory = "";
+
_repoMock = new Mock<IRepository<PopupActive>>();
_repositoryArchiveMock = new Mock<IRepository<PopupArchive>>();
_mediatorMock = new Mock<IMediator>();
- _popupService = new PopupService(_repoMock.Object,_repositoryArchiveMock.Object,_mediatorMock.Object);
+ _popupService = new PopupService(_repoMock.Object, _repositoryArchiveMock.Object, _mediatorMock.Object);
}
[TestMethod()]
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Documents/DocumentTypeServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Documents/DocumentTypeServiceTests.cs
index f115985b0..29921d09d 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/Documents/DocumentTypeServiceTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Documents/DocumentTypeServiceTests.cs
@@ -1,15 +1,14 @@
using Grand.Business.Marketing.Services.Documents;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Domain.Documents;
using Grand.Infrastructure.Events;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver.Linq;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Grand.Business.Marketing.Tests.Services.Documents
@@ -20,7 +19,6 @@ namespace Grand.Business.Marketing.Tests.Services.Documents
private Mock<IRepository<DocumentType>> _documentTypeRepositoryMock;
private DocumentTypeService _documentTypeService;
private Mock<IMediator> _mediatorMock;
- private Mock<IMongoQueryable<DocumentType>> _mongoQueryableMock;
private List<DocumentType> _expected;
private IQueryable<DocumentType> _expectedQueryable;
@@ -29,19 +27,19 @@ namespace Grand.Business.Marketing.Tests.Services.Documents
{
_mediatorMock = new Mock<IMediator>();
_documentTypeRepositoryMock = new Mock<IRepository<DocumentType>>();
- _mongoQueryableMock = new Mock<IMongoQueryable<DocumentType>>();
+ var _mongoQueryableMock = new Mock<MongoRepository<DocumentType>>();
_expected = new List<DocumentType>
{
new DocumentType() {Name = "name1", Description = "t1", DisplayOrder = 0},
new DocumentType() {Name = "name2", Description = "t2", DisplayOrder = 1}
};
_expectedQueryable = _expected.AsQueryable();
- _mongoQueryableMock.Setup(x => x.ElementType).Returns(_expectedQueryable.ElementType);
- _mongoQueryableMock.Setup(x => x.Expression).Returns(_expectedQueryable.Expression);
- _mongoQueryableMock.Setup(x => x.Provider).Returns(_expectedQueryable.Provider);
- _mongoQueryableMock.Setup(x => x.GetEnumerator()).Returns(_expectedQueryable.GetEnumerator());
+ //_mongoQueryableMock.Setup(x => x.ElementType).Returns(_expectedQueryable.ElementType);
+ //_mongoQueryableMock.Setup(x => x.Expression).Returns(_expectedQueryable.Expression);
+ //_mongoQueryableMock.Setup(x => x.Provider).Returns(_expectedQueryable.Provider);
+ //_mongoQueryableMock.Setup(x => x.GetEnumerator()).Returns(_expectedQueryable.GetEnumerator());
- _documentTypeRepositoryMock.Setup(x => x.Table).Returns(_mongoQueryableMock.Object);
+ _documentTypeRepositoryMock.Setup(x => x.Table).Returns(_mongoQueryableMock.Object.Table);
_documentTypeService = new DocumentTypeService(_documentTypeRepositoryMock.Object, _mediatorMock.Object);
}
diff --git a/src/Tests/Grand.Business.System.Tests/Services/Admin/AdminSiteMapServiceTests.cs b/src/Tests/Grand.Business.System.Tests/Services/Admin/AdminSiteMapServiceTests.cs
index b6f524cb6..beffe1ba9 100644
--- a/src/Tests/Grand.Business.System.Tests/Services/Admin/AdminSiteMapServiceTests.cs
+++ b/src/Tests/Grand.Business.System.Tests/Services/Admin/AdminSiteMapServiceTests.cs
@@ -3,13 +3,9 @@ using Grand.Domain.Admin;
using Grand.Domain.Data;
using Grand.Infrastructure.Caching;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using Moq;
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Grand.Business.System.Tests.Services.Admin