Skip to content

Instantly share code, notes, and snippets.

@asapostolov
Created March 30, 2022 11:00
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/faee1ffe9b09793940799b24729d8472 to your computer and use it in GitHub Desktop.
Save asapostolov/faee1ffe9b09793940799b24729d8472 to your computer and use it in GitHub Desktop.
Automatic deserialization $type failing test
[Fact]
public void ShouldStoreAndRetrieveDictionary() {
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, mscorlib],[System.String, mscorlib]], mscorlib""
};"
},
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> ) );
}
}
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