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

support882b8acc4ffe
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Grand.Business.Marketing.Tests.csproj b/src/Tests/Grand.Business.Marketing.Tests/Grand.Business.Marketing.Tests.csproj
index 42980dfd3..902938a5c 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Grand.Business.Marketing.Tests.csproj
+++ b/src/Tests/Grand.Business.Marketing.Tests/Grand.Business.Marketing.Tests.csproj
@@ -4,12 +4,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
- <ItemGroup>
- <Compile Remove="Services\PushNotifications\**" />
- <EmbeddedResource Remove="Services\PushNotifications\**" />
- <None Remove="Services\PushNotifications\**" />
- </ItemGroup>
-
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Moq" Version="4.18.2" />
@@ -24,6 +18,8 @@
<ItemGroup>
<ProjectReference Include="..\..\Business\Grand.Business.Core\Grand.Business.Core.csproj" />
<ProjectReference Include="..\..\Business\Grand.Business.Marketing\Grand.Business.Marketing.csproj" />
+ <ProjectReference Include="..\Grand.Data.Tests\Grand.Data.Tests.csproj" />
+ <ProjectReference Include="..\Grand.Infrastructure.Tests\Grand.Infrastructure.Tests.csproj" />
</ItemGroup>
</Project>
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs
new file mode 100644
index 000000000..678b54d16
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs
@@ -0,0 +1,193 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Business.Core.Interfaces.Marketing.Campaigns;
+using Grand.Business.Core.Interfaces.Messages;
+using Grand.Business.Core.Utilities.Messages.DotLiquidDrops;
+using Grand.Domain;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Domain.Messages;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Extensions;
+using MediatR;
+using Grand.Data.Tests.MongoDb;
+using Moq;
+using Grand.Infrastructure.Events;
+using Grand.Domain.Localization;
+
+namespace Grand.Business.Marketing.Services.Campaigns.Tests
+{
+ [TestClass()]
+ public class CampaignServiceTests
+ {
+ private IRepository<Campaign> _campaignRepository;
+ private IRepository<CampaignHistory> _campaignHistoryRepository;
+ private IRepository<NewsLetterSubscription> _newsLetterSubscriptionRepository;
+ private IRepository<Customer> _customerRepository;
+ private Mock<IEmailSender> _emailSenderMock;
+ private Mock<IQueuedEmailService> _queuedEmailServiceMock;
+ private Mock<IStoreService> _storeServiceMock;
+ private Mock<IMediator> _mediatorMock;
+ private Mock<ILanguageService> _languageServiceMock;
+ private Mock<IWorkContext> _workContextMock;
+ private CampaignService _campaignService;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _campaignRepository = new MongoDBRepositoryTest<Campaign>();
+ _campaignHistoryRepository = new MongoDBRepositoryTest<CampaignHistory>();
+ _newsLetterSubscriptionRepository = new MongoDBRepositoryTest<NewsLetterSubscription>();
+ _customerRepository = new MongoDBRepositoryTest<Customer>();
+ _mediatorMock = new Mock<IMediator>();
+ _emailSenderMock = new Mock<IEmailSender>();
+ _queuedEmailServiceMock = new Mock<IQueuedEmailService>();
+ _storeServiceMock = new Mock<IStoreService>();
+ _languageServiceMock = new Mock<ILanguageService>();
+ _workContextMock = new Mock<IWorkContext>();
+ _campaignService = new CampaignService(_campaignRepository, _campaignHistoryRepository, _newsLetterSubscriptionRepository, _customerRepository,
+ _emailSenderMock.Object, _queuedEmailServiceMock.Object, _storeServiceMock.Object, _mediatorMock.Object, _languageServiceMock.Object, _workContextMock.Object);
+
+ }
+
+ [TestMethod()]
+ public async Task InsertCampaignTest()
+ {
+ //Act
+ await _campaignService.InsertCampaign(new Campaign());
+ //Assert
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<Campaign>>(), default(CancellationToken)), Times.Once);
+ Assert.IsTrue(_campaignRepository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task InsertCampaignHistoryTest()
+ {
+ //Act
+ await _campaignService.InsertCampaignHistory(new CampaignHistory());
+ //Assert
+ Assert.IsTrue(_campaignHistoryRepository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateCampaignTest()
+ {
+ //Arrange
+ var campaign = new Campaign();
+ await _campaignService.InsertCampaign(campaign);
+
+ //Act
+ campaign.Subject = "test";
+ await _campaignService.UpdateCampaign(campaign);
+ //Assert
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityUpdated<Campaign>>(), default(CancellationToken)), Times.Once);
+ Assert.IsTrue(_campaignRepository.Table.FirstOrDefault(x => x.Id == campaign.Id).Subject == "test");
+ }
+
+ [TestMethod()]
+ public async Task DeleteCampaignTest()
+ {
+ //Arrange
+ var campaign = new Campaign();
+ await _campaignService.InsertCampaign(campaign);
+
+ //Act
+ await _campaignService.DeleteCampaign(campaign);
+ //Assert
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<Campaign>>(), default(CancellationToken)), Times.Once);
+ Assert.IsFalse(_campaignRepository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task GetCampaignByIdTest()
+ {
+ //Arrange
+ var campaign = new Campaign() {
+ Name = "test"
+ };
+ await _campaignRepository.InsertAsync(campaign);
+
+ //Act
+ var result = await _campaignService.GetCampaignById(campaign.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task GetAllCampaignsTest()
+ {
+ //Arrange
+ await _campaignRepository.InsertAsync(new Campaign());
+ await _campaignRepository.InsertAsync(new Campaign());
+ await _campaignRepository.InsertAsync(new Campaign());
+
+ //Act
+ var result = await _campaignService.GetAllCampaigns();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetCampaignHistoryTest()
+ {
+ //Arrange
+ var campaign = new Campaign() {
+ Name = "test"
+ };
+ await _campaignRepository.InsertAsync(campaign);
+ await _campaignHistoryRepository.InsertAsync(new CampaignHistory() { CampaignId = campaign.Id });
+ await _campaignHistoryRepository.InsertAsync(new CampaignHistory() { CampaignId = campaign.Id });
+
+ //Act
+ var result = await _campaignService.GetCampaignHistory(campaign);
+
+ //Assert
+ Assert.AreEqual(2, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task CustomerSubscriptionsTest()
+ {
+ //Arrange
+ var campaign = new Campaign() {
+ Name = "test",
+ StoreId = "1"
+ };
+ await _campaignRepository.InsertAsync(campaign);
+ await _newsLetterSubscriptionRepository.InsertAsync(new NewsLetterSubscription() { StoreId = "1", Active = true });
+ //Act
+ var result = await _campaignService.CustomerSubscriptions(campaign);
+
+ //Assert
+ Assert.AreEqual(1, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task SendCampaignTest()
+ {
+ //Arrange
+ var campaign = new Campaign() {
+ Name = "test",
+ StoreId = "1"
+ };
+ await _campaignRepository.InsertAsync(campaign);
+ await _newsLetterSubscriptionRepository.InsertAsync(new NewsLetterSubscription() { StoreId = "1", Active = true, Email = "[email protected]" });
+
+ _languageServiceMock.Setup(x => x.GetLanguageById(It.IsAny<string>()))
+ .Returns(Task.FromResult(new Language()));
+ _storeServiceMock.Setup(x => x.GetStoreById(It.IsAny<string>()))
+ .Returns(Task.FromResult(new Domain.Stores.Store()));
+
+ //Act
+ await _campaignService.SendCampaign(campaign, new EmailAccount() { Host = "host.com" }, "[email protected]");
+
+ //Assert
+ _emailSenderMock.Verify(c => c.SendEmail(It.IsAny<EmailAccount>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), null,null, null, null, null, null, null), Times.Once);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs
new file mode 100644
index 000000000..97ed36079
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs
@@ -0,0 +1,124 @@
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Marketing.Contacts;
+using Grand.Domain.Common;
+using Grand.Domain.Customers;
+using Grand.Domain.Messages;
+using Grand.Infrastructure;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Contacts.Tests
+{
+ [TestClass()]
+ public class ContactAttributeParserTests
+ {
+ private Mock<IContactAttributeService> _contactAttributeServiceMock;
+ private Mock<IWorkContext> _workContextMock;
+ private ContactAttributeParser _parser;
+ private List<CustomAttribute> customAtr;
+ private List<ContactAttribute> _contactAtr;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _contactAttributeServiceMock = new Mock<IContactAttributeService>();
+ _workContextMock = new Mock<IWorkContext>();
+ var _translationServiceMock = new Mock<ITranslationService>();
+ {
+ _translationServiceMock.Setup(x => x.GetResource(It.IsAny<string>())).Returns("Warning{0}");
+ }
+
+ _parser = new ContactAttributeParser(_contactAttributeServiceMock.Object, _workContextMock.Object);
+ customAtr = new List<CustomAttribute>()
+ {
+ new CustomAttribute(){Key="key1",Value="value1" },
+ new CustomAttribute(){Key="key2",Value="value2" },
+ new CustomAttribute(){Key="key3",Value="value3" },
+ new CustomAttribute(){Key="key4",Value="value4" },
+ };
+
+ _contactAtr = new List<ContactAttribute>()
+ {
+ new ContactAttribute(){Id="key1", Name="name1", AttributeControlType = Domain.Catalog.AttributeControlType.TextBox},
+ new ContactAttribute(){Id="key2", Name="name2"},
+ new ContactAttribute(){Id="key3", Name="name3"},
+ new ContactAttribute(){Id="key4", Name="name4"},
+ new ContactAttribute(){Id="key5", Name="name5"},
+ };
+ _contactAtr.ForEach(c => c.ContactAttributeValues.Add(new ContactAttributeValue() { Id = "value" + c.Id.Last() }));
+ }
+
+ [TestMethod()]
+ public async Task ParseContactAttributes_ReturnExpectedValues()
+ {
+ _contactAttributeServiceMock.Setup(c => c.GetContactAttributeById(It.IsAny<string>())).Returns((string w) => Task.FromResult(_contactAtr.FirstOrDefault(a => a.Id.Equals(w))));
+ var result = await _parser.ParseContactAttributes(customAtr);
+ Assert.IsTrue(result.Count == 4);
+ Assert.IsTrue(result.Any(c => c.Id.Equals("key1")));
+ Assert.IsTrue(result.Any(c => c.Id.Equals("key2")));
+ Assert.IsTrue(result.Any(c => c.Id.Equals("key3")));
+ Assert.IsTrue(result.Any(c => c.Id.Equals("key4")));
+ Assert.IsFalse(result.Any(c => c.Id.Equals("key5")));
+ }
+
+ [TestMethod()]
+ public async Task ParseCustomer0AttributeValues_ReturnExpectedValues()
+ {
+ _contactAttributeServiceMock.Setup(c => c.GetContactAttributeById(It.IsAny<string>())).Returns((string w) => Task.FromResult(_contactAtr.FirstOrDefault(a => a.Id.Equals(w))));
+ var result = await _parser.ParseContactAttributeValues(customAtr);
+ Assert.IsTrue(result.Count == 3);
+ Assert.IsTrue(result.Any(c => c.Id.Equals("value2")));
+ Assert.IsTrue(result.Any(c => c.Id.Equals("value3")));
+ Assert.IsTrue(result.Any(c => c.Id.Equals("value4")));
+ Assert.IsFalse(result.Any(c => c.Id.Equals("value5")));
+ }
+
+ [TestMethod()]
+ public void AddContactAttributeTest()
+ {
+ var result = _parser.AddContactAttribute(customAtr, new ContactAttribute() { Id = "key7" }, "value7");
+ Assert.IsTrue(result.Count == 5);
+ Assert.IsTrue(result.Any(c => c.Key.Equals("key7")));
+ }
+
+ [TestMethod()]
+ public async Task IsConditionMetTest_IsConditionMet_True()
+ {
+ _contactAttributeServiceMock.Setup(c => c.GetContactAttributeById(It.IsAny<string>())).Returns((string w) => Task.FromResult(_contactAtr.FirstOrDefault(a => a.Id.Equals(w))));
+ var contactAttribute = new ContactAttribute() { };
+ contactAttribute.ConditionAttribute.Add(new CustomAttribute() { Key = "key2", Value = "2" });
+ var result = await _parser.IsConditionMet(contactAttribute, new List<CustomAttribute>() { new CustomAttribute() { Key = "key2", Value = "2" } });
+ Assert.IsTrue(result);
+ }
+
+ [TestMethod()]
+ public async Task IsConditionMetTest_IsConditionMet_False()
+ {
+ _contactAttributeServiceMock.Setup(c => c.GetContactAttributeById(It.IsAny<string>())).Returns((string w) => Task.FromResult(_contactAtr.FirstOrDefault(a => a.Id.Equals(w))));
+ var contactAttribute = new ContactAttribute() { };
+ contactAttribute.ConditionAttribute.Add(new CustomAttribute() { Key = "key2", Value = "2" });
+ var result = await _parser.IsConditionMet(contactAttribute, new List<CustomAttribute>() { new CustomAttribute() { Key = "key3", Value = "2" } });
+ Assert.IsFalse(result);
+ }
+
+ [TestMethod()]
+ public void RemoveContactAttributeTest()
+ {
+ var result = _parser.RemoveContactAttribute(customAtr, new ContactAttribute() { Id = "key1" });
+ Assert.IsTrue(result.Count == 3);
+ Assert.IsFalse(result.Any(c => c.Key.Equals("key1")));
+ }
+
+ [TestMethod()]
+ public async Task FormatAttributesTest()
+ {
+ _contactAttributeServiceMock.Setup(c => c.GetAllContactAttributes("", false)).Returns(() => Task.FromResult((IList<ContactAttribute>)_contactAtr));
+ _contactAttributeServiceMock.Setup(c => c.GetContactAttributeById(It.IsAny<string>())).Returns((string w) => Task.FromResult(_contactAtr.FirstOrDefault(a => a.Id.Equals(w))));
+ var result = await _parser.FormatAttributes(new Domain.Localization.Language(),
+ new List<CustomAttribute>() {
+ new CustomAttribute(){Key="key1",Value="value1" }
+ }, new Customer());
+ Assert.IsTrue(result == "name1: value1");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs
new file mode 100644
index 000000000..7b51b2eac
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs
@@ -0,0 +1,115 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Domain.Messages;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Contacts.Tests
+{
+ [TestClass()]
+ public class ContactAttributeServiceTests
+ {
+ private ContactAttributeService _contactAttributeService;
+ private IRepository<ContactAttribute> _repository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+ private Mock<IWorkContext> _workContextMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<ContactAttribute>();
+ _mediatorMock = new Mock<IMediator>();
+ _workContextMock = new Mock<IWorkContext>();
+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
+
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _contactAttributeService = new ContactAttributeService(_cacheBase, _repository, _mediatorMock.Object, _workContextMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task DeleteContactAttributeTest()
+ {
+ //Arrange
+ var contactAttribute = new ContactAttribute() {
+ Name = "test"
+ };
+ await _contactAttributeService.InsertContactAttribute(contactAttribute);
+
+ //Act
+ await _contactAttributeService.DeleteContactAttribute(contactAttribute);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test"));
+ Assert.AreEqual(0, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetAllContactAttributesTest()
+ {
+ //Arrange
+ await _contactAttributeService.InsertContactAttribute(new ContactAttribute());
+ await _contactAttributeService.InsertContactAttribute(new ContactAttribute());
+ await _contactAttributeService.InsertContactAttribute(new ContactAttribute());
+
+ //Act
+ var result = await _contactAttributeService.GetAllContactAttributes();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetContactAttributeByIdTest()
+ {
+ //Arrange
+ var contactAttribute = new ContactAttribute() {
+ Name = "test"
+ };
+ await _contactAttributeService.InsertContactAttribute(contactAttribute);
+
+ //Act
+ var result = await _contactAttributeService.GetContactAttributeById(contactAttribute.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertContactAttributeTest()
+ {
+ //Act
+ var contactAttribute = new ContactAttribute() {
+ Name = "test"
+ };
+ await _contactAttributeService.InsertContactAttribute(contactAttribute);
+
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateContactAttributeTest()
+ {
+ //Arrange
+ var contactAttribute = new ContactAttribute() {
+ Name = "test"
+ };
+ await _contactAttributeService.InsertContactAttribute(contactAttribute);
+ contactAttribute.Name = "test2";
+
+ //Act
+ await _contactAttributeService.UpdateContactAttribute(contactAttribute);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactUsServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactUsServiceTests.cs
new file mode 100644
index 000000000..c7a0250dc
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactUsServiceTests.cs
@@ -0,0 +1,103 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Data;
+using Grand.Domain.Messages;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+
+namespace Grand.Business.Marketing.Services.Contacts.Tests
+{
+ [TestClass()]
+ public class ContactUsServiceTests
+ {
+ private ContactUsService _contactUsService;
+ private IRepository<ContactUs> _repository;
+ private Mock<IMediator> _mediatorMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<ContactUs>();
+ _mediatorMock = new Mock<IMediator>();
+ _contactUsService = new ContactUsService(_repository, _mediatorMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task DeleteContactUsTest()
+ {
+ //Arrange
+ var contactUs = new ContactUs() {
+ FullName = "test"
+ };
+ await _contactUsService.InsertContactUs(contactUs);
+
+ //Act
+ await _contactUsService.DeleteContactUs(contactUs);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.FullName == "test"));
+ Assert.AreEqual(0, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task ClearTableTest()
+ {
+ //Arrange
+ await _contactUsService.InsertContactUs(new ContactUs());
+ await _contactUsService.InsertContactUs(new ContactUs());
+ await _contactUsService.InsertContactUs(new ContactUs());
+
+ //Act
+ await _contactUsService.ClearTable();
+
+ //Assert
+ Assert.AreEqual(0, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetAllContactUsTest()
+ {
+ //Arrange
+ await _contactUsService.InsertContactUs(new ContactUs());
+ await _contactUsService.InsertContactUs(new ContactUs());
+ await _contactUsService.InsertContactUs(new ContactUs());
+
+ //Act
+ var result = await _contactUsService.GetAllContactUs();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetContactUsByIdTest()
+ {
+ //Arrange
+ var contactUs = new ContactUs() {
+ FullName = "test"
+ };
+ await _contactUsService.InsertContactUs(contactUs);
+
+ //Act
+ var result = await _contactUsService.GetContactUsById(contactUs.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.FullName);
+ }
+
+ [TestMethod()]
+ public async Task InsertContactUsTest()
+ {
+ //Act
+ var contactUs = new ContactUs() {
+ FullName = "test"
+ };
+ await _contactUsService.InsertContactUs(contactUs);
+
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseLessonServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseLessonServiceTests.cs
new file mode 100644
index 000000000..adb3a593d
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseLessonServiceTests.cs
@@ -0,0 +1,108 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Courses;
+using Grand.Domain.Data;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+
+namespace Grand.Business.Marketing.Services.Courses.Tests
+{
+ [TestClass()]
+ public class CourseLessonServiceTests
+ {
+ private CourseLessonService _courseLessonService;
+ private IRepository<CourseLesson> _repository;
+ private Mock<IMediator> _mediatorMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<CourseLesson>();
+ _mediatorMock = new Mock<IMediator>();
+ _courseLessonService = new CourseLessonService(_repository, _mediatorMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task DeleteTest()
+ {
+ //Arrange
+ var courseLesson = new CourseLesson() {
+ Name = "test"
+ };
+ await _courseLessonService.Insert(courseLesson);
+
+ //Act
+ await _courseLessonService.Delete(courseLesson);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test"));
+ Assert.AreEqual(0, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetByCourseIdTest()
+ {
+ //Arrange
+ var courseLesson = new CourseLesson() {
+ Name = "test",
+ CourseId = "1"
+ };
+ await _courseLessonService.Insert(courseLesson);
+
+ //Act
+ var result = await _courseLessonService.GetByCourseId(courseLesson.CourseId);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetByIdTest()
+ {
+ //Arrange
+ var courseLesson = new CourseLesson() {
+ Name = "test",
+ };
+ await _courseLessonService.Insert(courseLesson);
+
+ //Act
+ var result = await _courseLessonService.GetById(courseLesson.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertTest()
+ {
+ //Act
+ var courseLesson = new CourseLesson() {
+ Name = "test",
+ };
+ await _courseLessonService.Insert(courseLesson);
+
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateTest()
+ {
+ //Arrange
+ var courseLesson = new CourseLesson() {
+ Name = "test",
+ };
+ await _courseLessonService.Insert(courseLesson);
+ courseLesson.Name = "test2";
+
+ //Act
+ await _courseLessonService.Update(courseLesson);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseLevelServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseLevelServiceTests.cs
new file mode 100644
index 000000000..9ece60845
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseLevelServiceTests.cs
@@ -0,0 +1,104 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Courses;
+using Grand.Domain.Data;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Courses.Tests
+{
+ [TestClass()]
+ public class CourseLevelServiceTests
+ {
+ private CourseLevelService _courseLevelService;
+ private IRepository<CourseLevel> _repository;
+ private Mock<IMediator> _mediatorMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<CourseLevel>();
+ _mediatorMock = new Mock<IMediator>();
+ _courseLevelService = new CourseLevelService(_repository, _mediatorMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task DeleteTest()
+ {
+ //Arrange
+ var courseLevel = new CourseLevel() {
+ Name = "test"
+ };
+ await _courseLevelService.Insert(courseLevel);
+
+ //Act
+ await _courseLevelService.Delete(courseLevel);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test"));
+ Assert.AreEqual(0, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetAllTest()
+ {
+ //Arrange
+ await _courseLevelService.Insert(new CourseLevel());
+ await _courseLevelService.Insert(new CourseLevel());
+ await _courseLevelService.Insert(new CourseLevel());
+
+ //Act
+ var result = await _courseLevelService.GetAll();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetByIdTest()
+ {
+ //Arrange
+ var courseLevel = new CourseLevel() {
+ Name = "test"
+ };
+ await _courseLevelService.Insert(courseLevel);
+
+ //Act
+ var result = await _courseLevelService.GetById(courseLevel.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertTest()
+ {
+ //Act
+ var courseLevel = new CourseLevel() {
+ Name = "test"
+ };
+ await _courseLevelService.Insert(courseLevel);
+
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateTest()
+ {
+ //Arrange
+ var courseLevel = new CourseLevel() {
+ Name = "test"
+ };
+ await _courseLevelService.Insert(courseLevel);
+ courseLevel.Name = "test2";
+
+ //Act
+ await _courseLevelService.Update(courseLevel);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseSubjectServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseSubjectServiceTests.cs
new file mode 100644
index 000000000..7787057b2
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Courses/CourseSubjectServiceTests.cs
@@ -0,0 +1,107 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Courses;
+using Grand.Domain.Data;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Courses.Tests
+{
+ [TestClass()]
+ public class CourseSubjectServiceTests
+ {
+
+ private CourseSubjectService _courseSubjectService;
+ private IRepository<CourseSubject> _repository;
+ private Mock<IMediator> _mediatorMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<CourseSubject>();
+ _mediatorMock = new Mock<IMediator>();
+ _courseSubjectService = new CourseSubjectService(_repository, _mediatorMock.Object);
+ }
+ [TestMethod()]
+ public async Task DeleteTest()
+ {
+ //Arrange
+ var courseSubject = new CourseSubject() {
+ Name = "test"
+ };
+ await _courseSubjectService.Insert(courseSubject);
+
+ //Act
+ await _courseSubjectService.Delete(courseSubject);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test"));
+ Assert.AreEqual(0, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetByCourseIdTest()
+ {
+ //Arrange
+ var courseSubject = new CourseSubject() {
+ Name = "test",
+ CourseId = "1"
+ };
+ await _courseSubjectService.Insert(courseSubject);
+
+ //Act
+ var result = await _courseSubjectService.GetByCourseId(courseSubject.CourseId);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetByIdTest()
+ {
+ //Arrange
+ var courseSubject = new CourseSubject() {
+ Name = "test"
+ };
+ await _courseSubjectService.Insert(courseSubject);
+
+ //Act
+ var result = await _courseSubjectService.GetById(courseSubject.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertTest()
+ {
+ //Act
+ var courseSubject = new CourseSubject() {
+ Name = "test"
+ };
+ await _courseSubjectService.Insert(courseSubject);
+
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateTest()
+ {
+ //Arrange
+ var courseSubject = new CourseSubject() {
+ Name = "test"
+ };
+ await _courseSubjectService.Insert(courseSubject);
+ courseSubject.Name = "test2";
+
+ //Act
+ await _courseSubjectService.Update(courseSubject);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs
new file mode 100644
index 000000000..b031d45ba
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs
@@ -0,0 +1,84 @@
+using Grand.Business.Core.Events.Marketing;
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Infrastructure;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Customers.Tests
+{
+ [TestClass()]
+ public class CustomerCoordinatesServiceTests
+ {
+ CustomerCoordinatesService _customerCoordinatesService;
+ private Mock<IWorkContext> _workContextMock;
+ private IRepository<Customer> _repository;
+ private Mock<IMediator> _mediatorMock;
+ private Customer _customer;
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<Customer>();
+ _mediatorMock = new Mock<IMediator>();
+ _workContextMock = new Mock<IWorkContext>();
+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
+ _customer = new Customer();
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => _customer);
+
+ _customerCoordinatesService = new CustomerCoordinatesService(_repository, _workContextMock.Object, _mediatorMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task GetGeoCoordinateTest_WorkContext()
+ {
+ //Arrange
+ await _customerCoordinatesService.SaveGeoCoordinate(1, 2);
+ //Act
+ var result = await _customerCoordinatesService.GetGeoCoordinate();
+ //Assert
+ Assert.AreEqual(1, result.longitude);
+ Assert.AreEqual(2, result.latitude);
+ }
+
+ [TestMethod()]
+ public async Task GetGeoCoordinateTest_Customer()
+ {
+ //Arrange
+ var customer = new Customer();
+ await _repository.InsertAsync(customer);
+ await _customerCoordinatesService.SaveGeoCoordinate(customer, 1, 2);
+ //Act
+ var result = await _customerCoordinatesService.GetGeoCoordinate(customer);
+ //Assert
+ Assert.AreEqual(1, result.longitude);
+ Assert.AreEqual(2, result.latitude);
+ }
+
+ [TestMethod()]
+ public async Task SaveGeoCoordinateTest_Customer()
+ {
+ //Arrange
+ var customer = new Customer();
+ await _repository.InsertAsync(customer);
+ //Act
+ await _customerCoordinatesService.SaveGeoCoordinate(customer, 1, 2);
+ //Assert
+ Assert.AreEqual(1, _repository.Table.FirstOrDefault(x => x.Id == customer.Id).Coordinates.X);
+ Assert.AreEqual(2, _repository.Table.FirstOrDefault(x => x.Id == customer.Id).Coordinates.Y);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<CustomerCoordinatesEvent>(), default(CancellationToken)), Times.Once);
+ }
+
+ [TestMethod()]
+ public async Task SaveGeoCoordinateTest_WorkContext()
+ {
+ //Act
+ await _customerCoordinatesService.SaveGeoCoordinate(1, 2);
+ //Assert
+ Assert.AreEqual(1, _workContextMock.Object.CurrentCustomer.Coordinates.X);
+ Assert.AreEqual(2, _workContextMock.Object.CurrentCustomer.Coordinates.Y);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<CustomerCoordinatesEvent>(), default(CancellationToken)), Times.Once);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerProductServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerProductServiceTests.cs
new file mode 100644
index 000000000..586e0ea3d
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerProductServiceTests.cs
@@ -0,0 +1,216 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Customers.Tests
+{
+ [TestClass()]
+ public class CustomerProductServiceTests
+ {
+ private CustomerProductService _customerProductService;
+ private IRepository<CustomerProductPrice> _repositoryCustomerProductPrice;
+ private IRepository<CustomerProduct> _repositoryCustomerProduct;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repositoryCustomerProductPrice = new MongoDBRepositoryTest<CustomerProductPrice>();
+ _repositoryCustomerProduct = new MongoDBRepositoryTest<CustomerProduct>();
+ _mediatorMock = new Mock<IMediator>();
+
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _customerProductService = new CustomerProductService(_repositoryCustomerProductPrice, _repositoryCustomerProduct, _cacheBase, _mediatorMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerProductPriceByIdTest()
+ {
+ //Arrange
+ var customerProductPrice = new CustomerProductPrice() { Price = 10 };
+
+ await _repositoryCustomerProductPrice.InsertAsync(customerProductPrice);
+
+ //Act
+ var result = await _customerProductService.GetCustomerProductPriceById(customerProductPrice.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(10, result.Price);
+ }
+
+ [TestMethod()]
+ public async Task GetPriceByCustomerProductTest()
+ {
+ //Arrange
+ var customerProductPrice = new CustomerProductPrice() { Price = 10, CustomerId = "1", ProductId = "1" };
+
+ await _repositoryCustomerProductPrice.InsertAsync(customerProductPrice);
+
+ //Act
+ var result = await _customerProductService.GetPriceByCustomerProduct("1", "1");
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(10, result);
+ }
+
+ [TestMethod()]
+ public async Task InsertCustomerProductPriceTest()
+ {
+ //Act
+ var customerProductPrice = new CustomerProductPrice() { Price = 10, CustomerId = "1", ProductId = "1" };
+ await _customerProductService.InsertCustomerProductPrice(customerProductPrice);
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomerProductPrice.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateCustomerProductPriceTest()
+ {
+ //Arrange
+ var customerProductPrice = new CustomerProductPrice() { Price = 10, CustomerId = "1", ProductId = "1" };
+
+ await _repositoryCustomerProductPrice.InsertAsync(customerProductPrice);
+
+ //Act
+ customerProductPrice.Price = 20;
+ await _customerProductService.UpdateCustomerProductPrice(customerProductPrice);
+ var result = await _customerProductService.GetCustomerProductPriceById(customerProductPrice.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(20, result.Price);
+ }
+
+ [TestMethod()]
+ public async Task DeleteCustomerProductPriceTest()
+ {
+ //Arrange
+ var customerProductPrice = new CustomerProductPrice() { Price = 10, CustomerId = "1", ProductId = "1" };
+
+ await _repositoryCustomerProductPrice.InsertAsync(customerProductPrice);
+
+ //Act
+ await _customerProductService.DeleteCustomerProductPrice(customerProductPrice);
+ var result = await _customerProductService.GetCustomerProductPriceById(customerProductPrice.Id);
+
+ //Assert
+ Assert.IsNull(result);
+ }
+
+ [TestMethod()]
+ public async Task GetProductsPriceByCustomerTest()
+ {
+ //Arrange
+ await _repositoryCustomerProductPrice.InsertAsync(new CustomerProductPrice() { CustomerId = "1" });
+ await _repositoryCustomerProductPrice.InsertAsync(new CustomerProductPrice() { CustomerId = "1" });
+ await _repositoryCustomerProductPrice.InsertAsync(new CustomerProductPrice() { CustomerId = "1" });
+
+ //Act
+ var result = await _customerProductService.GetProductsPriceByCustomer("1");
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerProductTest()
+ {
+ //Arrange
+ var customerProduct = new CustomerProduct() { CustomerId = "1" };
+
+ await _repositoryCustomerProduct.InsertAsync(customerProduct);
+
+ //Act
+ var result = await _customerProductService.GetCustomerProduct(customerProduct.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("1", result.CustomerId);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerProductTest_Customer_Product()
+ {
+ //Arrange
+ var customerProduct = new CustomerProduct() { CustomerId = "1", ProductId = "1" };
+
+ await _repositoryCustomerProduct.InsertAsync(customerProduct);
+
+ //Act
+ var result = await _customerProductService.GetCustomerProduct("1", "1");
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("1", result.CustomerId);
+ }
+
+ [TestMethod()]
+ public async Task InsertCustomerProductTest()
+ {
+ //Act
+ var customerProduct = new CustomerProduct() { CustomerId = "1", ProductId = "1" };
+ await _customerProductService.InsertCustomerProduct(customerProduct);
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomerProduct.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateCustomerProductTest()
+ {
+ //Arrange
+ var customerProduct = new CustomerProduct() { CustomerId = "1", ProductId = "1", DisplayOrder = 1 };
+
+ await _repositoryCustomerProduct.InsertAsync(customerProduct);
+
+ //Act
+ customerProduct.DisplayOrder = 20;
+ await _customerProductService.UpdateCustomerProduct(customerProduct);
+ var result = await _customerProductService.GetCustomerProduct(customerProduct.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(20, result.DisplayOrder);
+ }
+
+ [TestMethod()]
+ public async Task DeleteCustomerProductTest()
+ {
+ //Arrange
+ var customerProduct = new CustomerProduct() { CustomerId = "1", ProductId = "1" };
+
+ await _repositoryCustomerProduct.InsertAsync(customerProduct);
+
+ //Act
+ await _customerProductService.DeleteCustomerProduct(customerProduct);
+ var result = await _customerProductService.GetCustomerProduct(customerProduct.Id);
+
+ //Assert
+ Assert.IsNull(result);
+ }
+
+ [TestMethod()]
+ public async Task GetProductsByCustomerTest()
+ {
+ //Arrange
+ await _repositoryCustomerProduct.InsertAsync(new CustomerProduct() { CustomerId = "1" });
+ await _repositoryCustomerProduct.InsertAsync(new CustomerProduct() { CustomerId = "1" });
+ await _repositoryCustomerProduct.InsertAsync(new CustomerProduct() { CustomerId = "1" });
+
+ //Act
+ var result = await _customerProductService.GetProductsByCustomer("1");
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerTagServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerTagServiceTests.cs
new file mode 100644
index 000000000..7b1463d4c
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerTagServiceTests.cs
@@ -0,0 +1,322 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Marketing.Services.Customers.Tests
+{
+ [TestClass()]
+ public class CustomerTagServiceTests
+ {
+ private CustomerTagService _customerTagService;
+ private IRepository<CustomerTag> _repositoryCustomerTag;
+ private IRepository<CustomerTagProduct> _repositoryCustomerTagProduct;
+ private IRepository<Customer> _repositoryCustomer;
+
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repositoryCustomerTag = new MongoDBRepositoryTest<CustomerTag>();
+ _repositoryCustomerTagProduct = new MongoDBRepositoryTest<CustomerTagProduct>();
+ _repositoryCustomer = new MongoDBRepositoryTest<Customer>();
+ _mediatorMock = new Mock<IMediator>();
+
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _customerTagService = new CustomerTagService(_repositoryCustomerTag, _repositoryCustomerTagProduct, _repositoryCustomer, _mediatorMock.Object, _cacheBase);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomersByTagTest()
+ {
+ //Arrange
+ var customer1 = new Customer();
+ customer1.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer1);
+ var customer2 = new Customer();
+ customer2.CustomerTags.Add("2");
+ await _repositoryCustomer.InsertAsync(customer2);
+ var customer3 = new Customer();
+ customer3.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer3);
+
+ //Act
+ var result = await _customerTagService.GetCustomersByTag("1");
+
+ //Assert
+ Assert.IsTrue(result.Any());
+ Assert.AreEqual(2, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task DeleteCustomerTagTest()
+ {
+ //Arrange
+ var customer1 = new Customer();
+ customer1.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer1);
+ var customer2 = new Customer();
+ customer2.CustomerTags.Add("2");
+ await _repositoryCustomer.InsertAsync(customer2);
+ var customer3 = new Customer();
+ customer3.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer3);
+
+ var customerTag = new CustomerTag() { Id = "1" };
+ await _repositoryCustomerTag.InsertAsync(customerTag);
+
+ //Act
+ await _customerTagService.DeleteCustomerTag(customerTag);
+ var result = await _customerTagService.GetCustomersByTag("1");
+
+ //Assert
+ Assert.IsFalse(result.Any());
+ Assert.AreEqual(0, result.Count);
+ Assert.AreEqual(0, _repositoryCustomerTag.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetAllCustomerTagsTest()
+ {
+ //Assert
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+
+ //Act
+ var result = await _customerTagService.GetAllCustomerTags();
+
+ //Assert
+ Assert.IsTrue(result.Any());
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerTagByIdTest()
+ {
+ //Assert
+ var customerTag = new CustomerTag() { Id = "1", Name = "test" };
+ await _repositoryCustomerTag.InsertAsync(customerTag);
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+
+ //Act
+ var result = await _customerTagService.GetCustomerTagById(customerTag.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerTagByNameTest()
+ {
+ //Assert
+ var customerTag = new CustomerTag() { Id = "1", Name = "test" };
+ await _repositoryCustomerTag.InsertAsync(customerTag);
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+
+ //Act
+ var result = await _customerTagService.GetCustomerTagByName("test");
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerTagsByNameTest()
+ {
+ //Assert
+ var customerTag = new CustomerTag() { Id = "1", Name = "test" };
+ await _repositoryCustomerTag.InsertAsync(customerTag);
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag() { Name = "test" });
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+ await _repositoryCustomerTag.InsertAsync(new CustomerTag());
+
+ //Act
+ var result = await _customerTagService.GetCustomerTagsByName("test");
+
+ //Assert
+ Assert.AreEqual(2, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task InsertCustomerTagTest()
+ {
+ //Assert
+ var customerTag = new CustomerTag() { Id = "1", Name = "test" };
+
+ //Act
+ await _customerTagService.InsertCustomerTag(customerTag);
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomerTag.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task InsertTagToCustomerTest()
+ {
+ //Arrange
+ var customer = new Customer() {Id = "1" };
+ await _repositoryCustomer.InsertAsync(customer);
+
+ var customerTag = new CustomerTag() { Id = "1" };
+ await _repositoryCustomerTag.InsertAsync(customerTag);
+
+ //Act
+ await _customerTagService.InsertTagToCustomer(customerTag.Id, customer.Id);
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomer.Table.FirstOrDefault(x=>x.Id == customer.Id).CustomerTags.Contains(customerTag.Id));
+ }
+
+ [TestMethod()]
+ public async Task DeleteTagFromCustomerTest()
+ {
+ //Arrange
+ var customer = new Customer() { Id = "1" };
+ customer.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer);
+
+ var customerTag = new CustomerTag() { Id = "1" };
+ await _repositoryCustomerTag.InsertAsync(customerTag);
+
+ //Act
+ await _customerTagService.DeleteTagFromCustomer(customerTag.Id, customer.Id);
+
+ //Assert
+ Assert.IsFalse(_repositoryCustomer.Table.FirstOrDefault(x => x.Id == customer.Id).CustomerTags.Contains(customerTag.Id));
+ }
+
+ [TestMethod()]
+ public async Task UpdateCustomerTagTest()
+ {
+ //Assert
+ var customerTag = new CustomerTag() { Id = "1", Name = "test" };
+ await _customerTagService.InsertCustomerTag(customerTag);
+
+ //Act
+ customerTag.Name = "test2";
+ await _customerTagService.UpdateCustomerTag(customerTag);
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomerTag.Table.FirstOrDefault(x=>x.Id == customerTag.Id).Name == "test2");
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerCountTest()
+ {
+ //Arrange
+ var customer1 = new Customer();
+ customer1.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer1);
+ var customer2 = new Customer();
+ customer2.CustomerTags.Add("2");
+ await _repositoryCustomer.InsertAsync(customer2);
+ var customer3 = new Customer();
+ customer3.CustomerTags.Add("1");
+ await _repositoryCustomer.InsertAsync(customer3);
+
+ //Act
+ var result = await _customerTagService.GetCustomerCount("1");
+
+ //Assert
+ Assert.AreEqual(2, result);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerTagProductsTest()
+ {
+ //Assert
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "1" });
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "1" });
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "2" });
+
+ //Act
+ var result = await _customerTagService.GetCustomerTagProducts("1");
+
+ //Assert
+ Assert.AreEqual(2, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerTagProductTest()
+ {
+ //Assert
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "1", ProductId = "1" });
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "1" });
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "2" });
+
+ //Act
+ var result = await _customerTagService.GetCustomerTagProduct("1", "1");
+
+ //Assert
+ Assert.IsNotNull(result);
+ }
+
+ [TestMethod()]
+ public async Task GetCustomerTagProductByIdTest()
+ {
+ //Assert
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "1", ProductId = "1" });
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { Id = "1", CustomerTagId = "1" });
+ await _repositoryCustomerTagProduct.InsertAsync(new CustomerTagProduct() { CustomerTagId = "2" });
+
+ //Act
+ var result = await _customerTagService.GetCustomerTagProductById("1");
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("1", result.CustomerTagId);
+ }
+
+ [TestMethod()]
+ public async Task InsertCustomerTagProductTest()
+ {
+ //Act
+ await _customerTagService.InsertCustomerTagProduct(new CustomerTagProduct());
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomerTagProduct.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateCustomerTagProductTest()
+ {
+ //Assert
+ var customerTagProduct = new CustomerTagProduct();
+ await _repositoryCustomerTagProduct.InsertAsync(customerTagProduct);
+
+ //Act
+ customerTagProduct.DisplayOrder = 10;
+ await _customerTagService.UpdateCustomerTagProduct(customerTagProduct);
+
+ //Assert
+ Assert.IsTrue(_repositoryCustomerTagProduct.Table.FirstOrDefault(x=>x.Id == customerTagProduct.Id).DisplayOrder == 10);
+ }
+
+ [TestMethod()]
+ public async Task DeleteCustomerTagProductTest()
+ {
+ //Assert
+ var customerTagProduct = new CustomerTagProduct();
+ await _repositoryCustomerTagProduct.InsertAsync(customerTagProduct);
+
+ //Act
+ await _customerTagService.DeleteCustomerTagProduct(customerTagProduct);
+
+ //Assert
+ Assert.IsFalse(_repositoryCustomerTag.Table.Any());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs
new file mode 100644
index 000000000..e59579428
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs
@@ -0,0 +1,218 @@
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Logging;
+using Grand.Business.Marketing.Utilities;
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Data;
+using Grand.Domain.PushNotifications;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using Moq.Protected;
+using Newtonsoft.Json;
+using System.Net;
+using System.Net.Http;
+
+namespace Grand.Business.Marketing.Services.PushNotifications.Tests
+{
+ [TestClass()]
+ public class PushNotificationsServiceTests
+ {
+ private PushNotificationsService _pushNotificationsService;
+ private IRepository<PushRegistration> _repositoryPushRegistration;
+ private IRepository<PushMessage> _repositoryPushMessage;
+ private Mock<IMediator> _mediatorMock;
+ private Mock<ITranslationService> _translationServiceMock;
+ private Mock<ILogger> _loggerMock;
+
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repositoryPushRegistration = new MongoDBRepositoryTest<PushRegistration>();
+ _repositoryPushMessage = new MongoDBRepositoryTest<PushMessage>();
+ _mediatorMock = new Mock<IMediator>();
+ _translationServiceMock = new Mock<ITranslationService>();
+ _translationServiceMock.Setup(x => x.GetResource(It.IsAny<string>())).Returns("translate");
+ _loggerMock = new Mock<ILogger>();
+
+ var mockMessageHandler = new Mock<HttpMessageHandler>();
+
+ string output = JsonConvert.SerializeObject(new JsonResponse() { success = 1, failure = 0, canonical_ids = 1 });
+
+ mockMessageHandler.Protected()
+ .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
+ .ReturnsAsync(new HttpResponseMessage {
+ StatusCode = HttpStatusCode.OK,
+ Content = new StringContent(output)
+ });
+ var httpClient = new HttpClient(mockMessageHandler.Object);
+
+ _pushNotificationsService = new PushNotificationsService(_repositoryPushRegistration, _repositoryPushMessage, _mediatorMock.Object, new PushNotificationsSettings(), _translationServiceMock.Object,
+ _loggerMock.Object, httpClient);
+ }
+
+ [TestMethod()]
+ public async Task InsertPushReceiverTest()
+ {
+ //Act
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration());
+ //Assert
+ Assert.IsTrue(_repositoryPushRegistration.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task DeletePushReceiverTest()
+ {
+ //Arrange
+ var pushRegistration = new PushRegistration();
+ await _pushNotificationsService.InsertPushReceiver(pushRegistration);
+
+ //Act
+ await _pushNotificationsService.DeletePushReceiver(pushRegistration);
+
+ //Assert
+ Assert.IsFalse(_repositoryPushRegistration.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task GetPushReceiverByCustomerIdTest()
+ {
+ //Arrange
+ var pushRegistration = new PushRegistration() { CustomerId = "1" };
+ await _pushNotificationsService.InsertPushReceiver(pushRegistration);
+
+ //Act
+ var result = await _pushNotificationsService.GetPushReceiverByCustomerId(pushRegistration.CustomerId);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("1", result.CustomerId);
+ }
+
+ [TestMethod()]
+ public async Task UpdatePushReceiverTest()
+ {
+ //Arrange
+ var pushRegistration = new PushRegistration() { CustomerId = "1" };
+ await _pushNotificationsService.InsertPushReceiver(pushRegistration);
+
+ //Act
+ pushRegistration.Allowed = true;
+ await _pushNotificationsService.UpdatePushReceiver(pushRegistration);
+
+ //Assert
+ Assert.IsTrue(_repositoryPushRegistration.Table.FirstOrDefault(x => x.Id == pushRegistration.Id).Allowed);
+ }
+
+ [TestMethod()]
+ public async Task GetPushReceiversTest()
+ {
+ //Arrange
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration() { Allowed = true });
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration() { Allowed = true });
+
+ //Act
+ var result = await _pushNotificationsService.GetPushReceivers();
+
+ //Assert
+ Assert.AreEqual(2, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetAllowedReceiversTest()
+ {
+ //Arrange
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration());
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration() { Allowed = true });
+
+ //Act
+ var result = await _pushNotificationsService.GetAllowedReceivers();
+
+ //Assert
+ Assert.AreEqual(1, result);
+ }
+
+ [TestMethod()]
+ public async Task GetDeniedReceiversTest()
+ {
+ //Arrange
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration());
+ await _pushNotificationsService.InsertPushReceiver(new PushRegistration() { Allowed = true });
+
+ //Act
+ var result = await _pushNotificationsService.GetDeniedReceivers();
+
+ //Assert
+ Assert.AreEqual(1, result);
+ }
+
+ [TestMethod()]
+ public async Task InsertPushMessageTest()
+ {
+ //Act
+ await _pushNotificationsService.InsertPushMessage(new PushMessage());
+ //Assert
+ Assert.IsFalse(_repositoryPushRegistration.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task GetPushMessagesTest()
+ {
+ //Arrange
+ await _pushNotificationsService.InsertPushMessage(new PushMessage());
+ await _pushNotificationsService.InsertPushMessage(new PushMessage());
+ await _pushNotificationsService.InsertPushMessage(new PushMessage());
+
+ //Act
+ var result = await _pushNotificationsService.GetPushMessages();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetPushReceiversTest1()
+ {
+ //Arrange
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+
+ //Act
+ var result = await _pushNotificationsService.GetPushReceivers();
+
+ //Assert
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod()]
+ public async Task SendPushNotificationTest()
+ {
+ //Arrange
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+ //Act
+ var result = await _pushNotificationsService.SendPushNotification("my title", "sample text", "", "");
+ //Assert
+ Assert.IsTrue(result.Item1);
+ }
+
+
+ [TestMethod()]
+ public async Task GetPushReceiverTest()
+ {
+ //Arrange
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Id = "1", Allowed = true });
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+ await _repositoryPushRegistration.InsertAsync(new PushRegistration() { Allowed = true });
+
+ //Act
+ var result = await _pushNotificationsService.GetPushReceiver("1");
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.IsTrue(result.Allowed);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Startup/StartupApplicationTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Startup/StartupApplicationTests.cs
new file mode 100644
index 000000000..e85c34406
--- /dev/null
+++ b/src/Tests/Grand.Business.Marketing.Tests/Startup/StartupApplicationTests.cs
@@ -0,0 +1,31 @@
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Business.Marketing.Startup.Tests
+{
+ [TestClass()]
+ public class StartupApplicationTests
+ {
+ StartupApplication _application;
+ ServiceCollection _serviceCollection;
+ IConfiguration _configuration;
+
+ [TestInitialize]
+ public void Init()
+ {
+ _serviceCollection = new ServiceCollection();
+ _configuration = new ConfigurationBuilder().Build();
+ _application = new StartupApplication();
+
+ }
+ [TestMethod()]
+ public void ConfigureServicesTest()
+ {
+ //Act
+ _application.ConfigureServices(_serviceCollection, _configuration);
+ //Assert
+ Assert.IsTrue(_serviceCollection.Count > 0);
+ }
+ }
+}
\ No newline at end of file