Skip to content

Commit

Permalink
Mongo 3.0 (#524)
Browse files Browse the repository at this point in the history
* Update nuget package (MongoDb)
  • Loading branch information
KrzysztofPajak authored Nov 20, 2024
1 parent 875c74c commit 47d12ab
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/Core/Grand.Data/Grand.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
18 changes: 0 additions & 18 deletions src/Core/Grand.Data/Mongo/BsonUtcDateTimeSerializer.cs

This file was deleted.

9 changes: 5 additions & 4 deletions src/Core/Grand.Data/Mongo/MongoDBStartupBase.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Grand.Domain/Grand.Domain.csproj
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Grand.Domain/ParentEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ protected ParentEntity()
public string Id {
get => _id;
set => _id = string.IsNullOrEmpty(value) ? UniqueIdentifier.New : value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task ExecuteTest_Import_Insert()
_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);
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task ExecuteTest_Import_Update()
.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);

Expand Down Expand Up @@ -253,7 +253,7 @@ public async Task ExecuteTest_Import_Insert_Update()
.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);

Expand Down
4 changes: 4 additions & 0 deletions src/Tests/Grand.Data.Tests/MongoDb/MongoDBRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -10,6 +13,7 @@ public MongoDBRepositoryTest() : base(
DriverTestConfiguration.Client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName),
new AuditInfoProvider())
{
BsonSerializer.TryRegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
var cp = new ConventionPack {
new IgnoreExtraElementsConvention(true)
};
Expand Down

0 comments on commit 47d12ab

Please sign in to comment.