Skip to content

Commit

Permalink
React to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Nov 19, 2024
1 parent 477519f commit 6d16d80
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 243 deletions.
1 change: 1 addition & 0 deletions samples/MongoDBSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

Console.WriteLine("Hello World!");

Expand Down
12 changes: 10 additions & 2 deletions src/Tingle.Extensions.MongoDB/Extensions/BuildersExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ private static StringFieldDefinition<T> CreateFieldDefinition<T, TChild>(Express
{
var collection = new ExpressionFieldDefinition<T>(collectionExpression);
var child = new ExpressionFieldDefinition<TChild>(memberExpression);
var collectionDefinition = collection.Render(BsonSerializer.LookupSerializer<T>(), BsonSerializer.SerializerRegistry);
var childDefinition = child.Render(BsonSerializer.LookupSerializer<TChild>(), BsonSerializer.SerializerRegistry);
var collectionDefinition = collection.Render(new RenderArgs<T>
{
DocumentSerializer = BsonSerializer.LookupSerializer<T>(),
SerializerRegistry = BsonSerializer.SerializerRegistry,
});
var childDefinition = child.Render(new RenderArgs<TChild>
{
DocumentSerializer = BsonSerializer.LookupSerializer<TChild>(),
SerializerRegistry = BsonSerializer.SerializerRegistry,
});

var fieldDefinition = new StringFieldDefinition<T>(collectionDefinition.FieldName + "." + childDefinition.FieldName);
return fieldDefinition;
Expand Down
229 changes: 0 additions & 229 deletions src/Tingle.Extensions.MongoDB/Extensions/IMongoQueryableExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ internal class JsonElementBsonSerializer : StructSerializerBase<JsonElement>
/// Without this, ObjectIDs, Dates, and Integers are output as {"_id": ObjectId(ds8f7s9d87f89sd9f8d9f7sd9f9s8d)},
/// {"date": ISODate("2020-04-14 14:30:00:000")}, {"int": NumberInt(130)} and respectively, which is not valid JSON
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
internal static readonly JsonWriterSettings settings = new() { OutputMode = JsonOutputMode.Strict, };
#pragma warning restore CS0618 // Type or member is obsolete
internal static readonly JsonWriterSettings settings = new() { OutputMode = JsonOutputMode.CanonicalExtendedJson, };

/// <inheritdoc/>
public override JsonElement Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DateTimeOffsetRepresentationConventionTests
[InlineData(BsonType.Document)]
[InlineData(BsonType.DateTime)]
[InlineData(BsonType.String)]
public void Convention_Is_Used_When_Memeber_Is_A_DateTimeOffset(BsonType representation)
public void Convention_Is_Used_When_Member_Is_A_DateTimeOffset(BsonType representation)
{
var subject = new DateTimeOffsetRepresentationConvention(representation);
var classMap = new BsonClassMap<Bookshop>();
Expand All @@ -29,7 +29,7 @@ public void Convention_Is_Used_When_Memeber_Is_A_DateTimeOffset(BsonType represe
[InlineData(BsonType.Document)]
[InlineData(BsonType.DateTime)]
[InlineData(BsonType.String)]
public void Convention_Is_Used_When_Memeber_Is_A_Nullable_DateTimeOffset(BsonType representation)
public void Convention_Is_Used_When_Member_Is_A_Nullable_DateTimeOffset(BsonType representation)
{
var subject = new DateTimeOffsetRepresentationConvention(representation);
var classMap = new BsonClassMap<Bookshop>();
Expand All @@ -43,9 +43,9 @@ public void Convention_Is_Used_When_Memeber_Is_A_Nullable_DateTimeOffset(BsonTyp
}

[Fact]
public void Convention_Is_Not_Used_When_Memeber_Is_Not_A_DateTimeOffset()
public void Convention_Is_Not_Used_When_Member_Is_Not_A_DateTimeOffset()
{
var subject = new DateTimeOffsetRepresentationConvention(BsonType.Array);
var subject = new DateTimeOffsetRepresentationConvention(BsonType.Document);
var classMap = new BsonClassMap<Bookshop>();
var memberMap = classMap.MapMember(b => b.Created);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Default_BsonRepresentation_IsUsed()
Etag = new Etag(123456789UL)
};
var json = obj.ToJson();
var expected = $"{{ '_id' : 'cake', 'Etag' : NumberLong(123456789) }}".Replace("'", "\"");
var expected = $"{{ '_id' : 'cake', 'Etag' : 123456789 }}".Replace("'", "\"");
Assert.Equal(expected, json);

var bson = obj.ToBson();
Expand All @@ -63,8 +63,8 @@ public void Default_BsonRepresentation_IsUsed()

[Theory]
[InlineData(123456789UL, typeof(BookshopString), "'Fc1bBwAAAAA='")]
[InlineData(123456789UL, typeof(BookshopInt64), "NumberLong(123456789)")]
[InlineData(123456789UL, typeof(BookshopBinary), "new BinData(0, 'Fc1bBwAAAAA=')")]
[InlineData(123456789UL, typeof(BookshopInt64), "123456789")]
[InlineData(123456789UL, typeof(BookshopBinary), "{ '$binary' : { 'base64' : 'Fc1bBwAAAAA=', 'subType' : '00' } }")]
public void BsonRepresentation_Is_Respected(ulong val, Type t, string bsonRaw)
{
var obj = (IBookshop)Activator.CreateInstance(t)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Default_BsonRepresentation_IsUsed()
Position = new SequenceNumber(123456789)
};
var json = obj.ToJson();
var expected = $"{{ '_id' : 'cake', 'Position' : NumberLong(123456789) }}".Replace("'", "\"");
var expected = $"{{ '_id' : 'cake', 'Position' : 123456789 }}".Replace("'", "\"");
Assert.Equal(expected, json);

var bson = obj.ToBson();
Expand All @@ -52,7 +52,7 @@ public void Default_BsonRepresentation_IsUsed()

[Theory]
[InlineData(123456789UL, typeof(BookshopString), "'123456789'")]
[InlineData(123456789UL, typeof(BookshopInt64), "NumberLong(123456789)")]
[InlineData(123456789UL, typeof(BookshopInt64), "123456789")]
public void BsonRepresentation_Is_Respected(long val, Type t, string bsonRaw)
{
var obj = (IBookshop)Activator.CreateInstance(t)!;
Expand Down

0 comments on commit 6d16d80

Please sign in to comment.