Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Update LiteDbRepositoryTests
support5c619730c0cf
diff --git a/src/Tests/Grand.Data.Tests/LiteDb/LiteDbRepositoryTests.cs b/src/Tests/Grand.Data.Tests/LiteDb/LiteDbRepositoryTests.csindex 626077b6e..8c0db646c 100644--- a/src/Tests/Grand.Data.Tests/LiteDb/LiteDbRepositoryTests.cs+++ b/src/Tests/Grand.Data.Tests/LiteDb/LiteDbRepositoryTests.cs@@ -6,49 +6,49 @@ namespace Grand.Data.Tests.LiteDb[TestClass()]public class LiteDbRepositoryTests{- private IRepository<SampleCollection> _myRepository;-[TestInitialize()]public void Init(){- _myRepository = new LiteDBRepositoryMock<SampleCollection>();-CommonPath.BaseDirectory = "";}[TestMethod()]public void Insert_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();+//Arrange- var product = new SampleCollection {Id = "1"};+ var product = new SampleCollection { Id = "1" };//Act- _myRepository.Insert(product);+ myRepository.Insert(product);//Assert- Assert.AreEqual(1, _myRepository.Table.Count());- Assert.IsTrue(_myRepository.Table.FirstOrDefault(x=>x.Id == "1")!.CreatedBy == "user");+ Assert.AreEqual(1, myRepository.Table.Count());+ Assert.IsTrue(myRepository.Table.FirstOrDefault(x => x.Id == "1")!.CreatedBy == "user");}[TestMethod()]public async Task InsertAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrange- var product = new SampleCollection { Id = "11"};+ var product = new SampleCollection { Id = "11" };//Act- await _myRepository.InsertAsync(product);- var p = _myRepository.GetById("11");+ await myRepository.InsertAsync(product);+ var p = myRepository.GetById("11");//AssertAssert.IsNotNull(p);- Assert.AreEqual(1, _myRepository.Table.Count());+ Assert.AreEqual(1, myRepository.Table.Count());Assert.IsTrue(p.CreatedBy == "user");}-+[TestMethod()]public async Task GetById_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- var p = _myRepository.GetById("1");+ var p = myRepository.GetById("1");Assert.IsNotNull(p);}@@ -56,10 +56,11 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task GetByIdAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- var p = await _myRepository.GetByIdAsync("1");+ var p = await myRepository.GetByIdAsync("1");Assert.IsNotNull(p);}@@ -67,40 +68,43 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task GetOneAsyncAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- var p = await _myRepository.GetOneAsync(x=>x.Id == "1");+ var p = await myRepository.GetOneAsync(x => x.Id == "1");Assert.IsNotNull(p);}-+[TestMethod()]public async Task ClearAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- await _myRepository.ClearAsync();+ await myRepository.ClearAsync();- Assert.IsTrue(_myRepository.Table.Count() == 0);+ Assert.IsTrue(myRepository.Table.Count() == 0);}[TestMethod()]public async Task AddToSet_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- await _myRepository.AddToSet("1", x => x.UserFields,+ await myRepository.AddToSet("1", x => x.UserFields,new Domain.Common.UserField { Key = "key", Value = "value", StoreId = "" });//Act- await _myRepository.AddToSet("1", x => x.UserFields,+ await myRepository.AddToSet("1", x => x.UserFields,new Domain.Common.UserField { Key = "key2", Value = "value2", StoreId = "" });- var p = _myRepository.GetById("1");-+ var p = myRepository.GetById("1");+//AssertAssert.IsTrue(p.UserFields.Count == 2);Assert.IsTrue(p.UpdatedOnUtc.HasValue);@@ -111,12 +115,13 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task Delete_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- _myRepository.Delete(product);+ myRepository.Delete(product);- var p = _myRepository.GetById("1");+ var p = myRepository.GetById("1");Assert.IsNull(p);}@@ -124,30 +129,34 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task DeleteAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var product = new SampleCollection { Id = "1" };- await _myRepository.InsertAsync(product);+ await myRepository.InsertAsync(product);- await _myRepository.DeleteAsync(product);+ await myRepository.DeleteAsync(product);- var p = _myRepository.GetById("1");+ var p = myRepository.GetById("1");Assert.IsNull(p);}[TestMethod()]public async Task DeleteManyAsync_LiteRepository_Success(){- await _myRepository.InsertAsync(new SampleCollection { Id = "1", Name = "Test" });- await _myRepository.InsertAsync(new SampleCollection { Id = "2", Name = "Test" });- await _myRepository.InsertAsync(new SampleCollection { Id = "3", Name = "Test2" });+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();- await _myRepository.DeleteManyAsync(x => x.Name == "Test");+ await myRepository.InsertAsync(new SampleCollection { Id = "1", Name = "Test" });+ await myRepository.InsertAsync(new SampleCollection { Id = "2", Name = "Test" });+ await myRepository.InsertAsync(new SampleCollection { Id = "3", Name = "Test2" });- Assert.IsTrue(_myRepository.Table.Count() == 1);+ await myRepository.DeleteManyAsync(x => x.Name == "Test");++ Assert.IsTrue(myRepository.Table.Count() == 1);}[TestMethod()]public async Task Pull_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -159,10 +168,10 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.Pull("1", x => x.Phones, "Phone2");- var p = _myRepository.GetById("1");+ await myRepository.Pull("1", x => x.Phones, "Phone2");+ var p = myRepository.GetById("1");//AssertAssert.IsTrue(p.Phones.Count == 2);@@ -172,6 +181,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task Pull_Many_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -183,15 +193,15 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.Pull(String.Empty, x => x.Phones, "Phone2");+ await myRepository.Pull(String.Empty, x => x.Phones, "Phone2");++ var p1 = myRepository.GetById("1");+ var p2 = myRepository.GetById("2");+ var p3 = myRepository.GetById("3");- var p1 = _myRepository.GetById("1");- var p2 = _myRepository.GetById("2");- var p3 = _myRepository.GetById("3");-//AssertAssert.IsTrue(p1.Phones.Count == 2 && p2.Phones.Count == 2 && p3.Phones.Count == 0);Assert.IsTrue(p1.UpdatedOnUtc.HasValue);@@ -202,6 +212,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task PullFilter_1_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -214,11 +225,11 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.PullFilter("1", x => x.UserFields, x => x.Value == "value");+ await myRepository.PullFilter("1", x => x.UserFields, x => x.Value == "value");- var p1 = _myRepository.GetById("1");+ var p1 = myRepository.GetById("1");//AssertAssert.IsTrue(p1.UserFields.Count == 2);@@ -230,6 +241,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task PullFilter_2_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -242,12 +254,12 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.PullFilter("1", x => x.UserFields, x => x.Value, "value");+ await myRepository.PullFilter("1", x => x.UserFields, x => x.Value, "value");- var p1 = _myRepository.GetById("1");+ var p1 = myRepository.GetById("1");//AssertAssert.IsTrue(p1.UserFields.Count == 1);@@ -258,6 +270,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task PullFilter_2_Many_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -276,13 +289,13 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.PullFilter(String.Empty, x => x.UserFields, x => x.Value, "value");+ await myRepository.PullFilter(String.Empty, x => x.UserFields, x => x.Value, "value");- var p1 = _myRepository.GetById("1");- var p2 = _myRepository.GetById("2");+ var p1 = myRepository.GetById("1");+ var p2 = myRepository.GetById("2");//AssertAssert.IsTrue(p1.UserFields.Count == 1 && p2.UserFields.Count == 2);@@ -294,6 +307,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public void Update_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -306,15 +320,15 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));var p1_update = products.FirstOrDefault();p1_update.Name = "update";//Act- _myRepository.Update(p1_update);+ myRepository.Update(p1_update);- var p1 = _myRepository.GetById("1");+ var p1 = myRepository.GetById("1");//AssertAssert.IsTrue(p1.Name == "update");@@ -325,6 +339,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task UpdateAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -337,14 +352,14 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));var p1_update = products.FirstOrDefault();p1_update.Name = "update";//Act- await _myRepository.UpdateAsync(p1_update);+ await myRepository.UpdateAsync(p1_update);- var p1 = _myRepository.GetById("1");+ var p1 = myRepository.GetById("1");//AssertAssert.IsTrue(p1.Name == "update");Assert.IsTrue(p1.UpdatedOnUtc.HasValue);@@ -354,6 +369,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task UpdateField_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -366,11 +382,11 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.UpdateField("1", x => x.Name, "update");+ await myRepository.UpdateField("1", x => x.Name, "update");- var p1 = _myRepository.GetById("1");+ var p1 = myRepository.GetById("1");//AssertAssert.IsTrue(p1.Name == "update");@@ -381,20 +397,22 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task IncField_MongoRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();var sample = new SampleCollection { Id = "1", Name = "Test" };- await _myRepository.InsertAsync(sample);+ await myRepository.InsertAsync(sample);- await _myRepository.IncField("1", x => x.Count, 1);- await _myRepository.IncField("1", x => x.Count, 1);- await _myRepository.IncField("1", x => x.Count, 1);+ await myRepository.IncField("1", x => x.Count, 1);+ await myRepository.IncField("1", x => x.Count, 1);+ await myRepository.IncField("1", x => x.Count, 1);- var p1 = _myRepository.GetById("1");+ var p1 = myRepository.GetById("1");Assert.IsTrue(p1.Count == 3);}[TestMethod()]public async Task UpdateManyAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -407,13 +425,13 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));-+ products.ForEach(x => myRepository.Insert(x));+//Act- await _myRepository.UpdateManyAsync(x => x.Name == "Test",+ await myRepository.UpdateManyAsync(x => x.Name == "Test",UpdateBuilder<SampleCollection>.Create().Set(x => x.Name, "UpdateTest"));- var pUpdated = _myRepository.Table.Where(x=>x.Name == "UpdateTest");+ var pUpdated = myRepository.Table.Where(x => x.Name == "UpdateTest");//AsserAssert.IsTrue(pUpdated.Count() == 2);@@ -425,6 +443,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task UpdateOneAsync_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -437,12 +456,12 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.UpdateOneAsync(x => x.Name == "Test",+ await myRepository.UpdateOneAsync(x => x.Name == "Test",UpdateBuilder<SampleCollection>.Create().Set(x => x.Name, "UpdateTest"));- var pUpdated = _myRepository.Table.Where(x => x.Name == "UpdateTest");+ var pUpdated = myRepository.Table.Where(x => x.Name == "UpdateTest");//AssertAssert.IsTrue(pUpdated.Count() == 1);@@ -453,6 +472,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task UpdateToSet_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -465,14 +485,14 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));-+ products.ForEach(x => myRepository.Insert(x));+//Act- await _myRepository.UpdateToSet("1", x => x.UserFields, z => z.Key, "key", new Domain.Common.UserField { Key = "key", Value = "update", StoreId = "1" });- var p = _myRepository.GetById("1");-+ await myRepository.UpdateToSet("1", x => x.UserFields, z => z.Key, "key", new Domain.Common.UserField { Key = "key", Value = "update", StoreId = "1" });+ var p = myRepository.GetById("1");+//Assert- Assert.IsTrue(p.UserFields!.FirstOrDefault(x=>x.Key=="key")!.Value == "update");+ Assert.IsTrue(p.UserFields!.FirstOrDefault(x => x.Key == "key")!.Value == "update");Assert.IsTrue(p.UpdatedOnUtc.HasValue);Assert.IsTrue(p.UpdatedBy == "user");@@ -481,6 +501,7 @@ namespace Grand.Data.Tests.LiteDb[TestMethod()]public async Task UpdateToSet_2_LiteRepository_Success(){+ var myRepository = new LiteDBRepositoryMock<SampleCollection>();//Arrangevar products = new List<SampleCollection> {new SampleCollection { Id = "1", Name = "Test",@@ -493,11 +514,11 @@ namespace Grand.Data.Tests.LiteDbnew SampleCollection { Id = "3", Name = "Test3" }};- products.ForEach(x=>_myRepository.Insert(x));+ products.ForEach(x => myRepository.Insert(x));//Act- await _myRepository.UpdateToSet("1", x => x.UserFields, z => z.Key == "key", new Domain.Common.UserField { Key = "key", Value = "update", StoreId = "1" });+ await myRepository.UpdateToSet("1", x => x.UserFields, z => z.Key == "key", new Domain.Common.UserField { Key = "key", Value = "update", StoreId = "1" });- var p = _myRepository.GetById("1");+ var p = myRepository.GetById("1");//AssertAssert.IsTrue(p.UserFields!.FirstOrDefault(x => x.Key == "key")!.Value == "update");