forked from msgpack/msgpack-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritanceTest.cs
More file actions
55 lines (49 loc) · 1.48 KB
/
InheritanceTest.cs
File metadata and controls
55 lines (49 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// PR #162
using System;
using System.Collections.Generic;
using System.IO;
#if !MSTEST
using NUnit.Framework;
#else
using TestFixtureAttribute = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
using TestAttribute = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
using TimeoutAttribute = NUnit.Framework.TimeoutAttribute;
using Assert = NUnit.Framework.Assert;
using Is = NUnit.Framework.Is;
#endif
namespace MsgPack.Serialization
{
[TestFixture]
public class InheritanceTest
{
[Test]
public void Issue147_161_162_HidingMembersWillNotBeDuplicated()
{
var context = new SerializationContext();
context.SerializationMethod = SerializationMethod.Array;
var serializer = context.GetSerializer<Child>();
using ( var buffer = new MemoryStream() )
{
var obj = new Child { Field = new List<string> { "A", "B" }, Property = new List<string> { "C", "D" } };
serializer.Pack( buffer, obj );
buffer.Position = 0;
using ( var unpacker = Unpacker.Create( buffer, ownsStream: false ) )
{
Assert.That( unpacker.Read() );
// If the hiding is not respected, this value will be 4.
Assert.That( unpacker.LastReadData.AsInt32(), Is.EqualTo( 2 ) );
}
}
}
public abstract class Base
{
public List<int> Field;
public virtual List<int> Property { get; set; }
}
public class Child : Base
{
public new List<string> Field;
public new virtual List<string> Property { get; set; }
}
}
}