-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSerializationTests.cs
80 lines (64 loc) · 2.8 KB
/
SerializationTests.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#if NANOFRAMEWORK_1_0
using nanoFramework.TestFramework;
using BinaryFormatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using nanoFramework.Serialization.Helper;
#endif
namespace nanoFramework.System.Runtime.Serialization.Tests
{
[TestClass]
public class SerializationTests
{
[TestMethod]
public void SerializePersonClassTest()
{
// serialize person class
var personOne = UnitTestHelper.CreatePersonOne();
#if NANOFRAMEWORK_1_0
var serializedPerson = BinaryFormatter.Serialize(personOne);
#else
var binaryFormatter = new BinaryFormatter();
var serializedPerson = binaryFormatter.Serialize(personOne);
#endif
Assert.IsNotNull(serializedPerson);
Assert.IsTrue(serializedPerson.Length == UnitTestHelper.PersonOneSerialized.Length, "PersonOne serialized data has different length.");
CollectionAssert.AreEqual(UnitTestHelper.PersonOneSerialized, serializedPerson);
}
[TestMethod]
public void SerializeComplexClassTest()
{
// serialize complex class
var complexClassOne = UnitTestHelper.CreateComplexClassOne();
#if NANOFRAMEWORK_1_0
var serializedComplexClass = BinaryFormatter.Serialize(complexClassOne);
#else
var binaryFormatter = new BinaryFormatter();
var serializedComplexClass = binaryFormatter.Serialize(complexClassOne);
#endif
Assert.IsNotNull(serializedComplexClass);
Assert.IsTrue(serializedComplexClass.Length == UnitTestHelper.ComplexClassOneSerialized.Length, "ComplexClass serialized data has different length.");
CollectionAssert.AreEqual(UnitTestHelper.ComplexClassOneSerialized, serializedComplexClass);
}
[TestMethod]
public void SerializeArrayListTest()
{
// serialize array list
var arrayListOne = UnitTestHelper.CreateArrayListOne();
#if NANOFRAMEWORK_1_0
var serializedArrayList = BinaryFormatter.Serialize(arrayListOne);
#else
var binaryFormatter = new BinaryFormatter();
var serializedArrayList = binaryFormatter.Serialize(arrayListOne);
#endif
Assert.IsNotNull(serializedArrayList);
Assert.IsTrue(serializedArrayList.Length == UnitTestHelper.ArrayListOneSerialized.Length, "ArrayListOne serialized data has different length.");
CollectionAssert.AreEqual(UnitTestHelper.ArrayListOneSerialized, serializedArrayList);
}
}
}