Skip to content

Instantly share code, notes, and snippets.

@asapostolov
Last active April 4, 2022 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asapostolov/01a5e95c0168065a091f4337da359671 to your computer and use it in GitHub Desktop.
Save asapostolov/01a5e95c0168065a091f4337da359671 to your computer and use it in GitHub Desktop.
Failing Test on RavenDB.Client
public class DeserializationTest : RavenTestDriver {
private IDocumentStore? _documentStore { get; set; }
protected override void PreInitialize(IDocumentStore documentStore) {
base.PreInitialize( documentStore );
documentStore.Conventions.IdentityPartsSeparator = '-';
documentStore.Conventions.Serialization = new NewtonsoftJsonSerializationConventions() {
CustomizeJsonSerializer = serializer => {
serializer.TypeNameHandling = TypeNameHandling.Objects;
}
};
}
public DeserializationTest() {
}
[Fact]
public void ShouldStoreAndRetrieveDictionary_Fails() {
ConfigureServer( new TestServerOptions {
DataDirectory = "D:\\Raven\\TestDB",
} );
_documentStore = GetDocumentStore( new GetDocumentStoreOptions() {
} );
string id = null;
using( var session = _documentStore.OpenSession() ) {
var doc = new Test() {
Settings = new Dictionary<string, object>
{
{"lastUsedUnitId", new Dictionary<int, string>()
{
{1, "units-3368"}
}}
}
};
session.Store( doc );
id = doc.Id;
session.SaveChanges();
}
WaitForUserToContinueTheTest( _documentStore );
using( var session = _documentStore.OpenSession() ) {
session.Advanced.DocumentStore.Operations.Send( new PatchOperation(
id: id,
changeVector: null,
patch: new PatchRequest {
Script = @"this.Settings[""lastUsedUnitId""] = {
""1"": ""units-3982"",
""$type"": ""System.Collections.Generic.Dictionary`2[[System.Int32, System.Private.CoreLib],[System.String, System.Private.CoreLib]], System.Private.CoreLib""
};"
},
patchIfMissing: null ) );
}
using( var session = _documentStore.OpenSession() ) {
var result = session.Load<Test>( id );
WaitForUserToContinueTheTest( _documentStore );
Assert.True( result.Settings.TryGetValue( "lastUsedUnitId", out var dict ) );
Assert.True( dict.GetType() == typeof( Dictionary<int, string> ) );
}
}
[Fact]
public void ShouldStoreAndRetrieveDictionary_Passes() {
ConfigureServer( new TestServerOptions {
DataDirectory = "D:\\Raven\\TestDB",
} );
_documentStore = GetDocumentStore( new GetDocumentStoreOptions() {
} );
string id = null;
using( var session = _documentStore.OpenSession() ) {
var doc = new Test() {
Settings = new Dictionary<string, object>
{
{"lastUsedUnitId", new Dictionary<int, string>()
{
{1, "units-3368"}
}}
}
};
session.Store( doc );
id = doc.Id;
session.SaveChanges();
}
WaitForUserToContinueTheTest( _documentStore );
using( var session = _documentStore.OpenSession() ) {
var result = session.Load<Test>( id );
WaitForUserToContinueTheTest( _documentStore );
Assert.True( result.Settings.TryGetValue( "lastUsedUnitId", out var dict ) );
Assert.True( dict.GetType() == typeof( Dictionary<int, string> ) );
}
}
private class Test {
public string Id { get; set; }
public Dictionary<string, object> Settings { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment