Created
March 30, 2022 11:00
-
-
Save asapostolov/faee1ffe9b09793940799b24729d8472 to your computer and use it in GitHub Desktop.
Automatic deserialization $type failing test
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
[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