Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/aspnet/MessagePack-CSharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2021-07-14 16:29:34 +0300
committerAndrew Arnott <andrewarnott@gmail.com>2021-07-14 16:29:34 +0300
commit8a6a48f1eb10b9c36db24f1289fd319ba6f03045 (patch)
treed9feb4cd0bd0234f764c08043be1e5e3efe06025 /tests
parent615a0b5803f304effda4af0873b699905d0ef810 (diff)
Add C# 9 records test with `StandardResolverAllowPrivate`
This repros the failure reported in #1232.
Diffstat (limited to 'tests')
-rw-r--r--tests/MessagePack.Tests/DynamicObjectResolverRecordsTests.cs28
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/MessagePack.Tests/DynamicObjectResolverRecordsTests.cs b/tests/MessagePack.Tests/DynamicObjectResolverRecordsTests.cs
index 340ef63e..483fe4ce 100644
--- a/tests/MessagePack.Tests/DynamicObjectResolverRecordsTests.cs
+++ b/tests/MessagePack.Tests/DynamicObjectResolverRecordsTests.cs
@@ -1,6 +1,7 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using MessagePack.Resolvers;
using Xunit;
#if NET5_0_OR_GREATER
@@ -39,10 +40,20 @@ namespace MessagePack.Tests
this.AssertRoundTrip(new StudentPositional("bob", "smith", 5));
}
- protected T AssertRoundTrip<T>(T value)
+ [Fact]
+ public void RoundtripRecordWithPrivateProperties()
+ {
+ var original = new RecordWithPrivateProperties("PublicValue");
+ original.SetPrivateProperty("PrivateValue");
+ var deserializedValue = this.AssertRoundTrip(original, allowPrivate: true);
+ Assert.Equal(original.GetPrivateProperty(), deserializedValue.GetPrivateProperty());
+ }
+
+ protected T AssertRoundTrip<T>(T value, bool allowPrivate = false)
{
- byte[] msgpack = MessagePackSerializer.Serialize(value, MessagePackSerializerOptions.Standard, this.TimeoutToken);
- T deserializedValue = MessagePackSerializer.Deserialize<T>(msgpack, MessagePackSerializerOptions.Standard, this.TimeoutToken);
+ var options = allowPrivate ? StandardResolverAllowPrivate.Options : MessagePackSerializerOptions.Standard;
+ byte[] msgpack = MessagePackSerializer.Serialize(value, options, this.TimeoutToken);
+ T deserializedValue = MessagePackSerializer.Deserialize<T>(msgpack, options, this.TimeoutToken);
Assert.Equal(value, deserializedValue);
return deserializedValue;
}
@@ -73,6 +84,17 @@ namespace MessagePack.Tests
[Key(2)]
public int Grade { get; init; }
}
+
+ [MessagePackObject]
+ public record RecordWithPrivateProperties([property: Key(0)] string SomePublicProperty)
+ {
+ [Key(1)]
+ private string SomePrivateProperty { get; set; }
+
+ public string GetPrivateProperty() => this.SomePrivateProperty;
+
+ public void SetPrivateProperty(string value) => this.SomePrivateProperty = value;
+ }
}
}