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.

Mongo 3.0 (#524)

Krzysztof Pajak47d12abf63b6
diff --git a/src/Core/Grand.Data/Grand.Data.csproj b/src/Core/Grand.Data/Grand.Data.csproj
index 4f315f041..96593db2c 100644
--- a/src/Core/Grand.Data/Grand.Data.csproj
+++ b/src/Core/Grand.Data/Grand.Data.csproj
@@ -2,10 +2,8 @@
<Import Project="..\..\Build\Grand.Common.props" />
<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.17" />
- <PackageReference Include="MongoDB.Bson" Version="2.30.0" />
- <PackageReference Include="MongoDB.Driver" Version="2.30.0" />
- <PackageReference Include="MongoDB.Driver.Core" Version="2.30.0" />
- <PackageReference Include="MongoDB.Driver.GridFS" Version="2.30.0" />
+ <PackageReference Include="MongoDB.Bson" Version="3.0.0" />
+ <PackageReference Include="MongoDB.Driver" Version="3.0.0" />
<PackageReference Include="DotLiquid" Version="2.2.692" />
</ItemGroup>
diff --git a/src/Core/Grand.Data/Mongo/BsonUtcDateTimeSerializer.cs b/src/Core/Grand.Data/Mongo/BsonUtcDateTimeSerializer.cs
deleted file mode 100644
index 1e8787d2d..000000000
--- a/src/Core/Grand.Data/Mongo/BsonUtcDateTimeSerializer.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
-
-namespace Grand.Data.Mongo;
-
-public class BsonUtcDateTimeSerializer : DateTimeSerializer
-{
- public override DateTime Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
- {
- return new DateTime(base.Deserialize(context, args).Ticks, DateTimeKind.Utc);
- }
-
- public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, DateTime value)
- {
- var utcValue = new DateTime(value.Ticks, DateTimeKind.Utc);
- base.Serialize(context, args, utcValue);
- }
-}
\ No newline at end of file
diff --git a/src/Core/Grand.Data/Mongo/MongoDBStartupBase.cs b/src/Core/Grand.Data/Mongo/MongoDBStartupBase.cs
index 792463f7f..aa85d9a77 100644
--- a/src/Core/Grand.Data/Mongo/MongoDBStartupBase.cs
+++ b/src/Core/Grand.Data/Mongo/MongoDBStartupBase.cs
@@ -1,5 +1,7 @@
-using Grand.Domain.Media;
+using Grand.Domain;
+using Grand.Domain.Media;
using Grand.SharedKernel;
+using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.Options;
@@ -16,14 +18,13 @@ public class MongoDBStartupBase : IStartupBase
/// </summary>
public void Execute()
{
- BsonSerializer.RegisterSerializer(typeof(DateTime), new BsonUtcDateTimeSerializer());
-
+ BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
BsonSerializer.RegisterSerializer(typeof(Dictionary<int, int>),
new DictionaryInterfaceImplementerSerializer<Dictionary<int, int>>(DictionaryRepresentation.ArrayOfArrays));
//global set an equivalent of [BsonIgnoreExtraElements] for every Domain Model
var cp = new ConventionPack {
- new IgnoreExtraElementsConvention(true)
+ new IgnoreExtraElementsConvention(true),
};
ConventionRegistry.Register("ApplicationConventions", cp, t => true);
diff --git a/src/Core/Grand.Domain/Grand.Domain.csproj b/src/Core/Grand.Domain/Grand.Domain.csproj
index b5b322f57..1ba095480 100644
--- a/src/Core/Grand.Domain/Grand.Domain.csproj
+++ b/src/Core/Grand.Domain/Grand.Domain.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\Build\Grand.Common.props" />
<ItemGroup>
- <PackageReference Include="MongoDB.Bson" Version="2.30.0" />
+ <PackageReference Include="MongoDB.Bson" Version="3.0.0" />
<PackageReference Include="DotLiquid" Version="2.2.692" />
</ItemGroup>
diff --git a/src/Core/Grand.Domain/ParentEntity.cs b/src/Core/Grand.Domain/ParentEntity.cs
index 11bf167a6..16edb93b8 100644
--- a/src/Core/Grand.Domain/ParentEntity.cs
+++ b/src/Core/Grand.Domain/ParentEntity.cs
@@ -15,5 +15,5 @@ public abstract class ParentEntity
public string Id {
get => _id;
set => _id = string.IsNullOrEmpty(value) ? UniqueIdentifier.New : value;
- }
+ }
}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs
index 84a215c35..e090ae42c 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs
@@ -138,7 +138,7 @@ public class ProductImportDataObjectTests
_languageServiceMock.Setup(c => c.GetAllLanguages(It.IsAny<bool>(), It.IsAny<string>()))
.Returns(Task.FromResult<IList<Language>>(new List<Language>()));
_slugServiceMock.Setup(c => c.GetBySlug(It.IsAny<string>()))
- .Returns(Task.FromResult(new EntityUrl { Slug = "slug" }));
+ .Returns(Task.FromResult(new EntityUrl { Slug = "slug", EntityName = "Product" }));
//Act
await _productImportDataObject.Execute(products);
@@ -199,7 +199,7 @@ public class ProductImportDataObjectTests
.Returns(Task.FromResult<IList<MeasureUnit>>(new List<MeasureUnit> { new() }));
_slugServiceMock.Setup(c => c.GetBySlug(It.IsAny<string>()))
- .Returns(Task.FromResult(new EntityUrl { Slug = "slug" }));
+ .Returns(Task.FromResult(new EntityUrl { Slug = "slug", EntityName = "Product" }));
//Act
await _productImportDataObject.Execute(products);
@@ -253,7 +253,7 @@ public class ProductImportDataObjectTests
.Returns(Task.FromResult<IList<MeasureUnit>>(new List<MeasureUnit> { new() }));
_slugServiceMock.Setup(c => c.GetBySlug(It.IsAny<string>()))
- .Returns(Task.FromResult(new EntityUrl { Slug = "slug" }));
+ .Returns(Task.FromResult(new EntityUrl { Slug = "slug", EntityName = "Product" }));
//Act
await _productImportDataObject.Execute(products);
diff --git a/src/Tests/Grand.Data.Tests/MongoDb/MongoDBRepositoryTest.cs b/src/Tests/Grand.Data.Tests/MongoDb/MongoDBRepositoryTest.cs
index 18ecbc289..84aee7d7f 100644
--- a/src/Tests/Grand.Data.Tests/MongoDb/MongoDBRepositoryTest.cs
+++ b/src/Tests/Grand.Data.Tests/MongoDb/MongoDBRepositoryTest.cs
@@ -1,6 +1,9 @@
using Grand.Data.Mongo;
using Grand.Domain;
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
+using MongoDB.Bson.Serialization.Serializers;
namespace Grand.Data.Tests.MongoDb;
@@ -10,6 +13,7 @@ public class MongoDBRepositoryTest<T> : MongoRepository<T>, IRepository<T> where
DriverTestConfiguration.Client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName),
new AuditInfoProvider())
{
+ BsonSerializer.TryRegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
var cp = new ConventionPack {
new IgnoreExtraElementsConvention(true)
};