Created
September 30, 2014 08:56
-
-
Save andreabalducci/5c397cce09bd16e14f09 to your computer and use it in GitHub Desktop.
Reset class map for unit testing
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using MongoDB.Bson.Serialization; | |
namespace CQRS.Tests.DomainTests | |
{ | |
public static class BsonClassMapHelper | |
{ | |
public static void Unregister<T>() | |
{ | |
var classType = typeof(T); | |
GetClassMap().Remove(classType); | |
} | |
static Dictionary<Type, BsonClassMap> GetClassMap() | |
{ | |
var cm = BsonClassMap.GetRegisteredClassMaps().First(); | |
var fi = typeof(BsonClassMap).GetField("__classMaps", BindingFlags.Static | BindingFlags.NonPublic); | |
var classMaps = (Dictionary<Type, BsonClassMap>)fi.GetValue(cm); | |
return classMaps; | |
} | |
public static void Clear() | |
{ | |
GetClassMap().Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like the current driver is still comatible to this code.