generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extended ObjectSerializer uses default GuidSerializer GuidRepresentat…
…ion (#100)
- Loading branch information
Showing
12 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Context.GuidSerializer.Tests/Context.GuidSerializers.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$(CCTestProjectProps)" Condition="Exists('$(CCTestProjectProps)')" /> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>MongoDB.Extensions.Context.GuidSerializers.Tests</AssemblyName> | ||
<RootNamespace>MongoDB.Extensions.Context.GuidSerializers.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Context\Context.csproj" /> | ||
<ProjectReference Include="..\Prime.Extensions\Prime.Extensions.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Xunit.Priority" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using MongoDB.Driver; | ||
using Squadron; | ||
using Xunit; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Snapshooter.Xunit; | ||
using MongoDB.Prime.Extensions; | ||
|
||
namespace MongoDB.Extensions.Context.GuidSerializers.Tests; | ||
|
||
public class GuidSerializerTests : IClassFixture<MongoResource> | ||
{ | ||
private readonly MongoOptions _mongoOptions; | ||
private readonly IMongoDatabase _mongoDatabase; | ||
|
||
public GuidSerializerTests(MongoResource mongoResource) | ||
{ | ||
_mongoDatabase = mongoResource.CreateDatabase(); | ||
_mongoOptions = new MongoOptions | ||
{ | ||
ConnectionString = mongoResource.ConnectionString, | ||
DatabaseName = _mongoDatabase.DatabaseNamespace.DatabaseName | ||
}; | ||
} | ||
|
||
[Fact] | ||
public async Task Serialize_GuidPropertyGuidSerialized_Successfully() | ||
{ | ||
// Arrange | ||
var foobarMongoDbContext = new FooBarMongoDbContext(_mongoOptions); | ||
|
||
IMongoCollection<Foo> collection = | ||
_mongoDatabase.GetCollection<Foo>("foos"); | ||
|
||
Foo foo = new Foo | ||
( | ||
fooId: Guid.Parse("b1eba0d6-a1f9-4e31-bd70-0feed19f4492"), | ||
name: "test", | ||
additionalId: Guid.Parse("b58ec857-c874-457e-8662-133a055282f6") | ||
); | ||
|
||
// Act | ||
await collection.InsertOneAsync(foo); | ||
|
||
// Assert | ||
Snapshot.Match(collection.Dump()); | ||
} | ||
|
||
[Fact] | ||
public async Task Serialize_ObjectPropertyGuidSerialized_Successfully() | ||
{ | ||
// Arrange | ||
var foobarMongoDbContext = new FooBarMongoDbContext(_mongoOptions); | ||
|
||
IMongoCollection<Bar> collection = | ||
_mongoDatabase.GetCollection<Bar>("bars"); | ||
|
||
Bar bar = new Bar | ||
( | ||
fooId: Guid.Parse("b1eba0d6-a1f9-4e31-bd70-0feed19f4492"), | ||
name: "test", | ||
additionalId: Guid.Parse("b58ec857-c874-457e-8662-133a055282f6") | ||
); | ||
|
||
// Act | ||
await collection.InsertOneAsync(bar); | ||
|
||
// Assert | ||
Snapshot.Match(collection.Dump()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace MongoDB.Extensions.Context.GuidSerializers.Tests; | ||
|
||
public class Bar | ||
{ | ||
public Bar(Guid fooId, string name, Guid additionalId) | ||
{ | ||
Id = fooId; | ||
Name = name; | ||
AdditionalId = additionalId; | ||
} | ||
|
||
public Guid Id { get; private set; } | ||
|
||
public string Name { get; private set;} | ||
|
||
public object AdditionalId { get; private set;} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace MongoDB.Extensions.Context.GuidSerializers.Tests; | ||
|
||
public class Foo | ||
{ | ||
public Foo(Guid fooId, string name, Guid additionalId) | ||
{ | ||
Id = fooId; | ||
Name = name; | ||
AdditionalId = additionalId; | ||
} | ||
|
||
public Guid Id { get; private set; } | ||
|
||
public string Name { get; private set;} | ||
|
||
public Guid AdditionalId { get; private set;} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Context.GuidSerializer.Tests/Helpers/FooBarMongoDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using MongoDB.Bson; | ||
using MongoDB.Bson.Serialization.Serializers; | ||
|
||
namespace MongoDB.Extensions.Context.GuidSerializers.Tests; | ||
|
||
public class FooBarMongoDbContext : MongoDbContext | ||
{ | ||
public FooBarMongoDbContext(MongoOptions mongoOptions) | ||
: base(mongoOptions) | ||
{ | ||
} | ||
|
||
protected override void OnConfiguring( | ||
IMongoDatabaseBuilder databaseBuilder) | ||
{ | ||
databaseBuilder.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../__snapshots__/GuidSerializerTests.Serialize_GuidPropertyGuidSerialized_Successfully.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"Id": "b1eba0d6-a1f9-4e31-bd70-0feed19f4492", | ||
"Name": "test", | ||
"AdditionalId": "b58ec857-c874-457e-8662-133a055282f6" | ||
} | ||
] |
7 changes: 7 additions & 0 deletions
7
..._snapshots__/GuidSerializerTests.Serialize_ObjectPropertyGuidSerialized_Successfully.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"Id": "b1eba0d6-a1f9-4e31-bd70-0feed19f4492", | ||
"Name": "test", | ||
"AdditionalId": "b58ec857-c874-457e-8662-133a055282f6" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters