Skip to content

Commit

Permalink
Added private member yaml member attrribute regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Sep 1, 2024
1 parent c3b5bd0 commit 09a6ff5
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 09a6ff5

Please sign in to comment.