added tests for index handler

This commit is contained in:
Sean Garrett
2023-06-22 22:06:27 +01:00
parent 25766febd4
commit b7b23e7b92
6 changed files with 871 additions and 5 deletions
@@ -1,16 +1,30 @@
using MongoDB.Bson;
using System;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
using Xunit.Abstractions;
namespace CoreUnitTests.Infrastructure;
public static class IndexExtensions
{
public static bool EqualToJson<TDocument>(this IndexKeysDefinition<TDocument> keys, string json, ITestOutputHelper output)
{
var indexModelRendered = RenderIndexModelKeys(keys);
var result = indexModelRendered.Equals(json, StringComparison.Ordinal);
if (!result && output != null)
{
output.WriteLine($"Expected: {json}");
output.WriteLine($"Actual: {indexModelRendered}");
}
return result;
}
public static bool EqualToJson<TDocument>(this IndexKeysDefinition<TDocument> keys, string json)
{
var indexModelRendered = RenderIndexModelKeys(keys);
return indexModelRendered.Equals(json, System.StringComparison.Ordinal);
return indexModelRendered.Equals(json, StringComparison.Ordinal);
}
public static bool EqualTo(this IndexCreationOptions x, CreateIndexOptions y) =>
@@ -28,7 +42,7 @@ public static class IndexExtensions
x.Background == y.Background &&
x.Version == y.Version;
public static bool EqualTo(this CreateIndexOptions x, IndexCreationOptions y) =>
public static bool EqualTo(this CreateIndexOptions x, IndexCreationOptions y) =>
x.Unique == y.Unique &&
x.TextIndexVersion == y.TextIndexVersion &&
x.SphereIndexVersion == y.SphereIndexVersion &&
@@ -52,6 +66,4 @@ public static class IndexExtensions
var result = indexModelRendered.ToString();
return result.Replace(" ", "");
}
}