-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.cs
More file actions
65 lines (57 loc) · 1.53 KB
/
Copy pathInheritance.cs
File metadata and controls
65 lines (57 loc) · 1.53 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
56
57
58
59
60
61
62
63
64
65
using System;
using NUnit.Framework;
using ProtoBuf;
namespace Examples
{
[TestFixture]
public class Inheritance
{
[ProtoContract]
public class A { }
public class B : A { }
[ProtoContract]
public class C
{
[ProtoMember(1)]
public A A { get; set; }
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage="Unexpected sub-type: Examples.Inheritance+B")]
public void UnknownSubtypeMessage()
{
var c = new C { A = new B() };
Serializer.DeepClone(c);
}
[Test]
public void TestFooAsFoo()
{
Foo foo = new Foo { Value = 1 };
Assert.AreEqual(foo.Value, Serializer.DeepClone(foo).Value);
}
[Test]
public void TestBarAsBar()
{
Bar bar = new Bar { Value = 1 };
Assert.AreEqual(bar.Value, Serializer.DeepClone<Foo>(bar).Value);
}
[Test]
public void TestBarAsFoo()
{
Foo foo = new Bar { Value = 1 };
Foo clone = Serializer.DeepClone(foo);
Assert.AreEqual(foo.Value, clone.Value);
Assert.IsInstanceOfType(typeof(Bar), clone);
}
}
[ProtoContract]
[ProtoInclude(2, typeof(Bar))]
class Foo
{
[ProtoMember(1)]
public int Value { get; set; }
}
[ProtoContract]
class Bar : Foo
{
}
}