Skip to content

Commit

Permalink
Merge pull request #904 from airbreather/fix-656
Browse files Browse the repository at this point in the history
Add a regression test for #656

+semver:fix
  • Loading branch information
EdwardCooke authored May 11, 2024
2 parents 4da74f4 + 912e5f9 commit 22070fd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions YamlDotNet.Test/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,16 @@ public void NamingConventionAppliedToEnumWhenDeserializing()
Assert.Equal(expected, actual);
}

[Fact]
[Trait("motive", "issue #656")]
public void NestedDictionaryTypes_ShouldRoundtrip()
{
var serializer = new SerializerBuilder().EnsureRoundtrip().Build();
var yaml = serializer.Serialize(new HasNestedDictionary { Lookups = { [1] = new HasNestedDictionary.Payload { I = 1 } } }, typeof(HasNestedDictionary));
var dct = new DeserializerBuilder().Build().Deserialize<HasNestedDictionary>(yaml);
Assert.Contains(new KeyValuePair<int, HasNestedDictionary.Payload>(1, new HasNestedDictionary.Payload { I = 1 }), dct.Lookups);
}

public class TestState
{
public int OnSerializedCallCount { get; set; }
Expand Down Expand Up @@ -2574,5 +2584,15 @@ public void WriteYaml(IEmitter emitter, object value, Type type)
emitter.Emit(new Scalar(((NonSerializable)value).Text));
}
}

public sealed class HasNestedDictionary
{
public Dictionary<int, Payload> Lookups { get; set; } = new Dictionary<int, Payload>();

public struct Payload
{
public int I { get; set; }
}
}
}
}

0 comments on commit 22070fd

Please sign in to comment.