Skip to content

Commit

Permalink
Merge pull request #963 from EdwardCooke/ec-privateyamlmember
Browse files Browse the repository at this point in the history
Added private member yaml member attrribute regression test
  • Loading branch information
EdwardCooke authored Sep 1, 2024
2 parents c3b5bd0 + 09a6ff5 commit 5240bf7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions YamlDotNet.Test/Serialization/DeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public void SerializeStateMethodsGetCalledOnce()
Assert.Equal(1, test.OnDeserializedCallCount);
Assert.Equal(1, test.OnDeserializingCallCount);
}

[Fact]
public void DeserializeConcurrently()
{
Expand All @@ -389,7 +389,7 @@ public void DeserializeConcurrently()
// Failures don't occur consistently - running repeatedly increases the chances
RunTest();
}

Assert.Empty(exceptions);

void RunTest()
Expand Down Expand Up @@ -444,6 +444,27 @@ public void WithCaseInsensitivePropertyMatching_IgnoreCase()
Assert.Equal("Value", test.Field);
}

[Fact]
public void PrivateMembersExposeYamlMemberAttribute()
{
var yaml = "key: value";

var result = new DeserializerBuilder()
.IncludeNonPublicProperties()
.Build()
.Deserialize<PrivateYamlMemberTest>(yaml);

Assert.Equal("value", result.PublicValue);
}

class PrivateYamlMemberTest
{
[YamlMember(Alias = "key")]
private string YamlValue { get; set; } = null!;

public string PublicValue => YamlValue;
}

#if NET8_0_OR_GREATER
[Fact]
public void WithRequiredMemberSet_ThrowsWhenFieldNotSet()
Expand Down

0 comments on commit 5240bf7

Please sign in to comment.