Skip to content

Commit 289bb44

Browse files
authored
Merge pull request MessagePack-CSharp#1155 from AArnott/docCtorPlusSetter
Add test to document ctor+property setter behavior
2 parents 8b558a5 + 2a47f9c commit 289bb44

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/MessagePack.UnityClient/Assets/Scripts/Tests/ShareTests/DynamicObjectResolverTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public void DeserializerSetsMissingPropertiesToDefaultValue_OrdinalKey()
8484
Assert.Null(instance.Prop2);
8585
}
8686

87+
[Fact]
88+
public void CtorParameterAndPropertySetterExists()
89+
{
90+
var m1 = new ClassWithPropertySetterAndDummyCtor(999) { MyProperty = 100 };
91+
byte[] bin = MessagePackSerializer.Serialize(m1);
92+
var m2 = MessagePackSerializer.Deserialize<ClassWithPropertySetterAndDummyCtor>(bin);
93+
94+
// In this version of the deserializer, we expect the property setter to be invoked
95+
// and reaffirm the value already passed to the constructor.
96+
Assert.Equal(m1.MyProperty, m2.MyProperty);
97+
}
98+
8799
/// <summary>
88100
/// Verifies that virtual and overridden properties do not cause the dynamic resolver to malfunction.
89101
/// </summary>
@@ -357,6 +369,17 @@ public class DerivedClass : BaseClass
357369
[DataMember]
358370
public string Name { get; set; }
359371
}
372+
373+
[MessagePackObject(true)]
374+
public class ClassWithPropertySetterAndDummyCtor
375+
{
376+
public int MyProperty { get; set; }
377+
378+
public ClassWithPropertySetterAndDummyCtor(int myProperty)
379+
{
380+
// This constructor intentionally left blank.
381+
}
382+
}
360383
}
361384
}
362385

0 commit comments

Comments
 (0)