Changeset 16466


Ignore:
Timestamp:
12/29/18 16:03:54 (6 months ago)
Author:
gkronber
Message:

#2520: removed unit tests which are moved to the HEAL.Fossil repository

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence.Fossil/UseCases.cs

    r16462 r16466  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections;
    2422using System.Collections.Generic;
    2523using System.Drawing;
    26 using System.Globalization;
    2724using System.IO;
    28 using System.Linq;
    29 using System.Reflection;
    30 using System.Text;
    3125using System.Threading.Tasks;
    3226using HEAL.Fossil;
    3327using HeuristicLab.Algorithms.GeneticAlgorithm;
    34 using HeuristicLab.Persistence.Auxiliary;
    3528using HeuristicLab.Persistence.Core;
    36 using HeuristicLab.Persistence.Default.CompositeSerializers;
    37 using HeuristicLab.Persistence.Default.DebugString;
    38 using HeuristicLab.Tests;
    3929using Microsoft.VisualStudio.TestTools.UnitTesting;
    4030
    4131namespace HeuristicLab.Persistence.Fossil.Tests {
    42 
    43   [StorableType("22B5FC22-44FA-40B4-84E3-BB53540E812E")]
    44   public class NumberTest {
    45     [Storable]
    46     private bool _bool = true;
    47     [Storable]
    48     private byte _byte = 0xFF;
    49     [Storable]
    50     private sbyte _sbyte = 0xF;
    51     [Storable]
    52     private short _short = -123;
    53     [Storable]
    54     private ushort _ushort = 123;
    55     [Storable]
    56     private int _int = -123;
    57     [Storable]
    58     private uint _uint = 123;
    59     [Storable]
    60     private long _long = 123456;
    61     [Storable]
    62     private ulong _ulong = 123456;
    63     public override bool Equals(object obj) {
    64       NumberTest nt = obj as NumberTest;
    65       if (nt == null)
    66         throw new NotSupportedException();
    67       return
    68         nt._bool == _bool &&
    69         nt._byte == _byte &&
    70         nt._sbyte == _sbyte &&
    71         nt._short == _short &&
    72         nt._ushort == _ushort &&
    73         nt._int == _int &&
    74         nt._uint == _uint &&
    75         nt._long == _long &&
    76         nt._ulong == _ulong;
    77     }
    78     public override int GetHashCode() {
    79       return
    80         _bool.GetHashCode() ^
    81         _byte.GetHashCode() ^
    82         _sbyte.GetHashCode() ^
    83         _short.GetHashCode() ^
    84         _short.GetHashCode() ^
    85         _int.GetHashCode() ^
    86         _uint.GetHashCode() ^
    87         _long.GetHashCode() ^
    88         _ulong.GetHashCode();
    89     }
    90 
    91     [StorableConstructor]
    92     protected NumberTest(StorableConstructorFlag _) {
    93     }
    94     public NumberTest() {
    95     }
    96   }
    97 
    98   [StorableType("2D94AD3B-D411-403F-AC42-60824C78D802")]
    99   public class IntWrapper {
    100 
    101     [Storable]
    102     public int Value;
    103 
    104     [StorableConstructor]
    105     protected IntWrapper(StorableConstructorFlag _) {
    106     }
    107 
    108     private IntWrapper() { }
    109 
    110     public IntWrapper(int value) {
    111       this.Value = value;
    112     }
    113 
    114     public override bool Equals(object obj) {
    115       if (obj as IntWrapper == null)
    116         return false;
    117       return Value.Equals(((IntWrapper)obj).Value);
    118     }
    119     public override int GetHashCode() {
    120       return Value.GetHashCode();
    121     }
    122 
    123   }
    124 
    125   [StorableType("45337DD7-26D0-42D0-8CC4-92E184AE0218")]
    126   public class PrimitivesTest : NumberTest {
    127     [Storable]
    128     private char c = 'e';
    129     [Storable]
    130     private long[,] _long_array =
    131       new long[,] { { 123, 456, }, { 789, 123 } };
    132     [Storable]
    133     public List<int> list = new List<int> { 1, 2, 3, 4, 5 };
    134     [Storable]
    135     private object o = new object();
    136     public override bool Equals(object obj) {
    137       PrimitivesTest pt = obj as PrimitivesTest;
    138       if (pt == null)
    139         throw new NotSupportedException();
    140       return base.Equals(obj) &&
    141         c == pt.c &&
    142         _long_array == pt._long_array &&
    143         list == pt.list &&
    144         o == pt.o;
    145     }
    146     public override int GetHashCode() {
    147       return base.GetHashCode() ^
    148         c.GetHashCode() ^
    149         _long_array.GetHashCode() ^
    150         list.GetHashCode() ^
    151         o.GetHashCode();
    152     }
    153 
    154     [StorableConstructor]
    155     protected PrimitivesTest(StorableConstructorFlag _) : base(_) {
    156     }
    157     public PrimitivesTest() {
    158     }
    159   }
    160 
    161   [StorableType("2F63F603-CE7D-4262-99B4-A797F4D04907")]
    162   public enum TestEnum { va1, va2, va3, va8 };
    163 
    164   [StorableType("DC944CA9-5F6A-4EF3-AFBD-881FC63797DF")]
    165   public class RootBase {
    166     [Storable]
    167     private string baseString = "   Serial  ";
    168     [Storable]
    169     public TestEnum myEnum = TestEnum.va3;
    170     public override bool Equals(object obj) {
    171       RootBase rb = obj as RootBase;
    172       if (rb == null)
    173         throw new NotSupportedException();
    174       return baseString == rb.baseString &&
    175         myEnum == rb.myEnum;
    176     }
    177     public override int GetHashCode() {
    178       return baseString.GetHashCode() ^
    179         myEnum.GetHashCode();
    180     }
    181 
    182     [StorableConstructor]
    183     protected RootBase(StorableConstructorFlag _) {
    184     }
    185     public RootBase() {
    186     }
    187   }
    188 
    189   [StorableType("C478905A-5029-4F31-9D92-524F41272D46")]
    190   public class Root : RootBase {
    191     [Storable]
    192     public Stack<int> intStack = new Stack<int>();
    193     [Storable]
    194     public int[] i = new[] { 3, 4, 5, 6 };
    195     [Storable(Name = "Test String")]
    196     public string s;
    197     [Storable]
    198     public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
    199     [Storable]
    200     public List<int> intList = new List<int>(new[] { 321, 312, 321 });
    201     [Storable]
    202     public Custom c;
    203     [Storable]
    204     public List<Root> selfReferences;
    205     [Storable]
    206     public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
    207     [Storable]
    208     public bool boolean = true;
    209     [Storable]
    210     public DateTime dateTime;
    211     [Storable]
    212     public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("Serial", 123);
    213     [Storable]
    214     public Dictionary<string, int> dict = new Dictionary<string, int>();
    215     [Storable(DefaultValue = "default")]
    216     public string uninitialized;
    217 
    218     [StorableConstructor]
    219     protected Root(StorableConstructorFlag _) : base(_) {
    220     }
    221     public Root() {
    222     }
    223   }
    224 
    225   [StorableType("23DCF22C-EDAB-4C5A-9941-0F2D6030D467")]
    226   public enum SimpleEnum { one, two, three }
    227   [StorableType("1FA5C129-129E-485C-A8A7-59FCA10CBB20")]
    228   public enum ComplexEnum { one = 1, two = 2, three = 3 }
    229   [FlagsAttribute]
    230   [StorableType("D4A5D0CD-295C-4AC1-B5DA-D8DA2861E82C")]
    231   public enum TrickyEnum { zero = 0, one = 1, two = 2 }
    232 
    233   [StorableType("C6EC77AF-C565-4A83-8922-3C6E2370627B")]
    234   public class EnumTest {
    235     [Storable]
    236     public SimpleEnum simpleEnum = SimpleEnum.one;
    237     [Storable]
    238     public ComplexEnum complexEnum = (ComplexEnum)2;
    239     [Storable]
    240     public TrickyEnum trickyEnum = (TrickyEnum)15;
    241 
    242     [StorableConstructor]
    243     protected EnumTest(StorableConstructorFlag _) {
    244     }
    245     public EnumTest() {
    246     }
    247   }
    248 
    249   [StorableType("9E73E52B-9BF1-489D-9349-C490D518B7C4")]
    250   public class Custom {
    251     [Storable]
    252     public int i;
    253     [Storable]
    254     public Root r;
    255     [Storable]
    256     public string name = "<![CDATA[<![CDATA[Serial]]>]]>";
    257 
    258     [StorableConstructor]
    259     protected Custom(StorableConstructorFlag _) {
    260     }
    261 
    262     public Custom() {
    263 
    264     }
    265   }
    266 
    267   [StorableType("CEE5C689-948F-443A-A645-54868D913364")]
    268   public class Manager {
    269 
    270     public DateTime lastLoadTime;
    271     [Storable]
    272     private DateTime lastLoadTimePersistence {
    273       get { return lastLoadTime; }
    274       set { lastLoadTime = DateTime.Now; }
    275     }
    276     [Storable]
    277     public double? dbl;
    278 
    279     [StorableConstructor]
    280     protected Manager(StorableConstructorFlag _) {
    281     }
    282     public Manager() {
    283     }
    284   }
    285 
    286   [StorableType("14EB77CD-7061-4B2E-96EB-3E45CC265256")]
    287   public class C {
    288     [Storable]
    289     public C[][] allCs;
    290     [Storable]
    291     public KeyValuePair<List<C>, C> kvpList;
    292 
    293     [StorableConstructor]
    294     protected C(StorableConstructorFlag _) {
    295     }
    296     public C() {
    297     }
    298   }
    299 
    300   public class NonSerializable {
    301     int x = 0;
    302     public override bool Equals(object obj) {
    303       NonSerializable ns = obj as NonSerializable;
    304       if (ns == null)
    305         throw new NotSupportedException();
    306       return ns.x == x;
    307     }
    308     public override int GetHashCode() {
    309       return x.GetHashCode();
    310     }
    311   }
    312 
    313 
    31432  [TestClass]
    31533  public class UseCases {
     
    33351    [TestCategory("Persistence.Fossil")]
    33452    [TestProperty("Time", "short")]
    335     public void ComplexStorable() {
    336       Root r = InitializeComplexStorable();
    337       var ser = new ProtoBufSerializer();
    338       ser.Serialize(r, tempFile);
    339       Root newR = (Root)ser.Deserialize(tempFile);
    340       CompareComplexStorables(r, newR);
    341     }
    342 
    343     private static void CompareComplexStorables(Root r, Root newR) {
    344       Assert.AreSame(newR, newR.selfReferences[0]);
    345       Assert.AreNotSame(r, newR);
    346       Assert.AreEqual(r.myEnum, TestEnum.va1);
    347       Assert.AreEqual(r.i[0], 7);
    348       Assert.AreEqual(r.i[1], 5);
    349       Assert.AreEqual(r.i[2], 6);
    350       Assert.AreEqual(r.s, "new value");
    351       Assert.AreEqual(r.intArray[0], 3);
    352       Assert.AreEqual(r.intArray[1], 2);
    353       Assert.AreEqual(r.intArray[2], 1);
    354       Assert.AreEqual(r.intList[0], 9);
    355       Assert.AreEqual(r.intList[1], 8);
    356       Assert.AreEqual(r.intList[2], 7);
    357       Assert.AreEqual(r.multiDimArray[0, 0], 5);
    358       Assert.AreEqual(r.multiDimArray[0, 1], 4);
    359       Assert.AreEqual(r.multiDimArray[0, 2], 3);
    360       Assert.AreEqual(r.multiDimArray[1, 0], 1);
    361       Assert.AreEqual(r.multiDimArray[1, 1], 4);
    362       Assert.AreEqual(r.multiDimArray[1, 2], 6);
    363       Assert.IsFalse(r.boolean);
    364       Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10);
    365       Assert.AreEqual(r.kvp.Key, "string key");
    366       Assert.AreEqual(r.kvp.Value, 321);
    367       Assert.IsNull(r.uninitialized);
    368       Assert.AreEqual(newR.myEnum, TestEnum.va1);
    369       Assert.AreEqual(newR.i[0], 7);
    370       Assert.AreEqual(newR.i[1], 5);
    371       Assert.AreEqual(newR.i[2], 6);
    372       Assert.AreEqual(newR.s, "new value");
    373       Assert.AreEqual(newR.intArray[0], 3);
    374       Assert.AreEqual(newR.intArray[1], 2);
    375       Assert.AreEqual(newR.intArray[2], 1);
    376       Assert.AreEqual(newR.intList[0], 9);
    377       Assert.AreEqual(newR.intList[1], 8);
    378       Assert.AreEqual(newR.intList[2], 7);
    379       Assert.AreEqual(newR.multiDimArray[0, 0], 5);
    380       Assert.AreEqual(newR.multiDimArray[0, 1], 4);
    381       Assert.AreEqual(newR.multiDimArray[0, 2], 3);
    382       Assert.AreEqual(newR.multiDimArray[1, 0], 1);
    383       Assert.AreEqual(newR.multiDimArray[1, 1], 4);
    384       Assert.AreEqual(newR.multiDimArray[1, 2], 6);
    385       Assert.AreEqual(newR.intStack.Pop(), 3);
    386       Assert.AreEqual(newR.intStack.Pop(), 2);
    387       Assert.AreEqual(newR.intStack.Pop(), 1);
    388       Assert.IsFalse(newR.boolean);
    389       Assert.IsTrue((DateTime.Now - newR.dateTime).TotalSeconds < 10);
    390       Assert.AreEqual(newR.kvp.Key, "string key");
    391       Assert.AreEqual(newR.kvp.Value, 321);
    392       Assert.IsNull(newR.uninitialized);
    393     }
    394 
    395     private static Root InitializeComplexStorable() {
    396       Root r = new Root();
    397       r.intStack.Push(1);
    398       r.intStack.Push(2);
    399       r.intStack.Push(3);
    400       r.selfReferences = new List<Root> { r, r };
    401       r.c = new Custom { r = r };
    402       r.dict.Add("one", 1);
    403       r.dict.Add("two", 2);
    404       r.dict.Add("three", 3);
    405       r.myEnum = TestEnum.va1;
    406       r.i = new[] { 7, 5, 6 };
    407       r.s = "new value";
    408       r.intArray = new ArrayList { 3, 2, 1 };
    409       r.intList = new List<int> { 9, 8, 7 };
    410       r.multiDimArray = new double[,] { { 5, 4, 3 }, { 1, 4, 6 } };
    411       r.boolean = false;
    412       r.dateTime = DateTime.Now;
    413       r.kvp = new KeyValuePair<string, int>("string key", 321);
    414       r.uninitialized = null;
    415 
    416       return r;
    417     }
    418 
    419     [TestMethod]
    420     [TestCategory("Persistence.Fossil")]
    421     [TestProperty("Time", "short")]
    422     public void SelfReferences() {
    423       C c = new C();
    424       C[][] cs = new C[2][];
    425       cs[0] = new C[] { c };
    426       cs[1] = new C[] { c };
    427       c.allCs = cs;
    428       c.kvpList = new KeyValuePair<List<C>, C>(new List<C> { c }, c);
    429       new ProtoBufSerializer().Serialize(cs, tempFile);
    430       object o = new ProtoBufSerializer().Deserialize(tempFile);
    431       Assert.AreEqual(
    432         DebugStringGenerator.Serialize(cs),
    433         DebugStringGenerator.Serialize(o));
    434       Assert.AreSame(c, c.allCs[0][0]);
    435       Assert.AreSame(c, c.allCs[1][0]);
    436       Assert.AreSame(c, c.kvpList.Key[0]);
    437       Assert.AreSame(c, c.kvpList.Value);
    438       C[][] newCs = (C[][])o;
    439       C newC = newCs[0][0];
    440       Assert.AreSame(newC, newC.allCs[0][0]);
    441       Assert.AreSame(newC, newC.allCs[1][0]);
    442       Assert.AreSame(newC, newC.kvpList.Key[0]);
    443       Assert.AreSame(newC, newC.kvpList.Value);
    444     }
    445 
    446     [TestMethod]
    447     [TestCategory("Persistence.Fossil")]
    448     [TestProperty("Time", "short")]
    449     public void ArrayCreation() {
    450       ArrayList[] arrayListArray = new ArrayList[4];
    451       arrayListArray[0] = new ArrayList();
    452       arrayListArray[0].Add(arrayListArray);
    453       arrayListArray[0].Add(arrayListArray);
    454       arrayListArray[1] = new ArrayList();
    455       arrayListArray[1].Add(arrayListArray);
    456       arrayListArray[2] = new ArrayList();
    457       arrayListArray[2].Add(arrayListArray);
    458       arrayListArray[2].Add(arrayListArray);
    459       Array a = Array.CreateInstance(
    460                               typeof(object),
    461                               new[] { 1, 2 }, new[] { 3, 4 });
    462       arrayListArray[2].Add(a);
    463       new ProtoBufSerializer().Serialize(arrayListArray, tempFile);
    464       object o = new ProtoBufSerializer().Deserialize(tempFile);
    465       Assert.AreEqual(
    466         DebugStringGenerator.Serialize(arrayListArray),
    467         DebugStringGenerator.Serialize(o));
    468       ArrayList[] newArray = (ArrayList[])o;
    469       Assert.AreSame(arrayListArray, arrayListArray[0][0]);
    470       Assert.AreSame(arrayListArray, arrayListArray[2][1]);
    471       Assert.AreSame(newArray, newArray[0][0]);
    472       Assert.AreSame(newArray, newArray[2][1]);
    473     }
    474 
    475     [TestMethod]
    476     [TestCategory("Persistence.Fossil")]
    477     [TestProperty("Time", "short")]
    478     public void CustomSerializationProperty() {
    479       Manager m = new Manager();
    480       new ProtoBufSerializer().Serialize(m, tempFile);
    481       Manager newM = (Manager)new ProtoBufSerializer().Deserialize(tempFile);
    482       Assert.AreNotEqual(
    483         DebugStringGenerator.Serialize(m),
    484         DebugStringGenerator.Serialize(newM));
    485       Assert.AreEqual(m.dbl, newM.dbl);
    486       Assert.AreEqual(m.lastLoadTime, new DateTime());
    487       Assert.AreNotEqual(newM.lastLoadTime, new DateTime());
    488       Assert.IsTrue((DateTime.Now - newM.lastLoadTime).TotalSeconds < 10);
    489     }
    490 
    491     [TestMethod]
    492     [TestCategory("Persistence.Fossil")]
    493     [TestProperty("Time", "short")]
    494     public void Primitives() {
    495       PrimitivesTest sdt = new PrimitivesTest();
    496       new ProtoBufSerializer().Serialize(sdt, tempFile);
    497       object o = new ProtoBufSerializer().Deserialize(tempFile);
    498       Assert.AreEqual(
    499         DebugStringGenerator.Serialize(sdt),
    500         DebugStringGenerator.Serialize(o));
    501     }
    502 
    503     [TestMethod]
    504     [TestCategory("Persistence.Fossil")]
    505     [TestProperty("Time", "short")]
    506     public void MultiDimensionalArray() {
    507       string[,] mDimString = new string[,] {
    508         {"ora", "et", "labora"},
    509         {"Beten", "und", "Arbeiten"}
    510       };
    511       new ProtoBufSerializer().Serialize(mDimString, tempFile);
    512       object o = new ProtoBufSerializer().Deserialize(tempFile);
    513       Assert.AreEqual(
    514         DebugStringGenerator.Serialize(mDimString),
    515         DebugStringGenerator.Serialize(o));
    516     }
    517 
    518     [StorableType("59E73F41-B9D4-489B-AA9C-3A72173498CC")]
    519     public class NestedType {
    520       [Storable]
    521       private string value = "value";
    522       public override bool Equals(object obj) {
    523         NestedType nt = obj as NestedType;
    524         if (nt == null)
    525           throw new NotSupportedException();
    526         return nt.value == value;
    527       }
    528       public override int GetHashCode() {
    529         return value.GetHashCode();
    530       }
    531 
    532       [StorableConstructor]
    533       protected NestedType(StorableConstructorFlag _) {
    534       }
    535       public NestedType() {
    536       }
    537     }
    538 
    539     [TestMethod]
    540     [TestCategory("Persistence.Fossil")]
    541     [TestProperty("Time", "short")]
    542     public void NestedTypeTest() {
    543       NestedType t = new NestedType();
    544       new ProtoBufSerializer().Serialize(t, tempFile);
    545       object o = new ProtoBufSerializer().Deserialize(tempFile);
    546       Assert.AreEqual(
    547         DebugStringGenerator.Serialize(t),
    548         DebugStringGenerator.Serialize(o));
    549       Assert.IsTrue(t.Equals(o));
    550     }
    551 
    552 
    553     [TestMethod]
    554     [TestCategory("Persistence.Fossil")]
    555     [TestProperty("Time", "short")]
    556     public void SimpleArray() {
    557       string[] strings = { "ora", "et", "labora" };
    558       new ProtoBufSerializer().Serialize(strings, tempFile);
    559       object o = new ProtoBufSerializer().Deserialize(tempFile);
    560       Assert.AreEqual(
    561         DebugStringGenerator.Serialize(strings),
    562         DebugStringGenerator.Serialize(o));
    563     }
    564 
    565     [TestMethod]
    566     [TestCategory("Persistence.Fossil")]
    567     [TestProperty("Time", "short")]
    568     public void PrimitiveRoot() {
    569       new ProtoBufSerializer().Serialize(12.3f, tempFile);
    570       object o = new ProtoBufSerializer().Deserialize(tempFile);
    571       Assert.AreEqual(
    572         DebugStringGenerator.Serialize(12.3f),
    573         DebugStringGenerator.Serialize(o));
    574     }
    575 
    576     private string formatFullMemberName(MemberInfo mi) {
    577       return new StringBuilder()
    578         .Append(mi.DeclaringType.Assembly.GetName().Name)
    579         .Append(": ")
    580         .Append(mi.DeclaringType.Namespace)
    581         .Append('.')
    582         .Append(mi.DeclaringType.Name)
    583         .Append('.')
    584         .Append(mi.Name).ToString();
    585     }
    586 
    587     public void CodingConventions() {
    588       List<string> lowerCaseMethodNames = new List<string>();
    589       List<string> lowerCaseProperties = new List<string>();
    590       List<string> lowerCaseFields = new List<string>();
    591       foreach (Assembly a in PluginLoader.Assemblies) {
    592         if (!a.GetName().Name.StartsWith("HeuristicLab"))
    593           continue;
    594         foreach (Type t in a.GetTypes()) {
    595           foreach (MemberInfo mi in t.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) {
    596             if (mi.DeclaringType.Name.StartsWith("<>"))
    597               continue;
    598             if (char.IsLower(mi.Name[0])) {
    599               if (mi.MemberType == MemberTypes.Field)
    600                 lowerCaseFields.Add(formatFullMemberName(mi));
    601               if (mi.MemberType == MemberTypes.Property)
    602                 lowerCaseProperties.Add(formatFullMemberName(mi));
    603               if (mi.MemberType == MemberTypes.Method &&
    604                 !mi.Name.StartsWith("get_") &&
    605                 !mi.Name.StartsWith("set_") &&
    606                 !mi.Name.StartsWith("add_") &&
    607                 !mi.Name.StartsWith("remove_") &&
    608                 !mi.Name.StartsWith("op_"))
    609                 lowerCaseMethodNames.Add(formatFullMemberName(mi));
    610             }
    611           }
    612         }
    613       }
    614       //Assert.AreEqual("", lowerCaseFields.Aggregate("", (a, b) => a + "\r\n" + b));
    615       Assert.AreEqual("", lowerCaseMethodNames.Aggregate("", (a, b) => a + "\r\n" + b));
    616       Assert.AreEqual("", lowerCaseProperties.Aggregate("", (a, b) => a + "\r\n" + b));
    617     }
    618 
    619     [TestMethod]
    620     [TestCategory("Persistence.Fossil")]
    621     [TestProperty("Time", "short")]
    622     public void Enums() {
    623       EnumTest et = new EnumTest();
    624       et.simpleEnum = SimpleEnum.two;
    625       et.complexEnum = ComplexEnum.three;
    626       et.trickyEnum = TrickyEnum.two | TrickyEnum.one;
    627       new ProtoBufSerializer().Serialize(et, tempFile);
    628       EnumTest newEt = (EnumTest)new ProtoBufSerializer().Deserialize(tempFile);
    629       Assert.AreEqual(et.simpleEnum, SimpleEnum.two);
    630       Assert.AreEqual(et.complexEnum, ComplexEnum.three);
    631       Assert.AreEqual(et.trickyEnum, (TrickyEnum)3);
    632     }
    633 
    634     [TestMethod]
    635     [TestCategory("Persistence.Fossil")]
    636     [TestProperty("Time", "short")]
    637     public void TestAliasingWithOverriddenEquals() {
    638       List<IntWrapper> ints = new List<IntWrapper>();
    639       ints.Add(new IntWrapper(1));
    640       ints.Add(new IntWrapper(1));
    641       Assert.AreEqual(ints[0], ints[1]);
    642       Assert.AreNotSame(ints[0], ints[1]);
    643       new ProtoBufSerializer().Serialize(ints, tempFile);
    644       List<IntWrapper> newInts = (List<IntWrapper>)new ProtoBufSerializer().Deserialize(tempFile);
    645       Assert.AreEqual(newInts[0].Value, 1);
    646       Assert.AreEqual(newInts[1].Value, 1);
    647       Assert.AreEqual(newInts[0], newInts[1]);
    648       Assert.AreNotSame(newInts[0], newInts[1]);
    649     }
    650 
    651     [TestMethod]
    652     [TestCategory("Persistence.Fossil")]
    653     [TestProperty("Time", "short")]
    654     public void TestSavingException() {
    655       List<int> list = new List<int> { 1, 2, 3 };
    656       new ProtoBufSerializer().Serialize(list, tempFile);
    657       NonSerializable s = new NonSerializable();
    658       try {
    659         new ProtoBufSerializer().Serialize(s, tempFile);
    660         Assert.Fail("Exception expected");
    661       } catch (PersistenceException) { }
    662       List<int> newList = (List<int>)new ProtoBufSerializer().Deserialize(tempFile);
    663       Assert.AreEqual(list[0], newList[0]);
    664       Assert.AreEqual(list[1], newList[1]);
    665     }
    666 
    667     [TestMethod]
    668     [TestCategory("Persistence.Fossil")]
    669     [TestProperty("Time", "short")]
    670     public void TestTypeStringConversion() {
    671       string name = typeof(List<int>[]).AssemblyQualifiedName;
    672       string shortName =
    673         "System.Collections.Generic.List`1[[System.Int32, mscorlib]][], mscorlib";
    674       Assert.AreEqual(name, TypeNameParser.Parse(name).ToString());
    675       Assert.AreEqual(shortName, TypeNameParser.Parse(name).ToString(false));
    676       Assert.AreEqual(shortName, typeof(List<int>[]).VersionInvariantName());
    677     }
    678 
    679     [TestMethod]
    680     [TestCategory("Persistence.Fossil")]
    681     [TestProperty("Time", "short")]
    682     public void TestHexadecimalPublicKeyToken() {
    683       string name = "TestClass, TestAssembly, Version=1.2.3.4, PublicKey=1234abc";
    684       string shortName = "TestClass, TestAssembly";
    685       Assert.AreEqual(name, TypeNameParser.Parse(name).ToString());
    686       Assert.AreEqual(shortName, TypeNameParser.Parse(name).ToString(false));
    687     }
    688 
    689     [TestMethod]
    690     [TestCategory("Persistence.Fossil")]
    691     [TestProperty("Time", "short")]
    692     public void TestMultipleFailure() {
    693       List<NonSerializable> l = new List<NonSerializable>();
    694       l.Add(new NonSerializable());
    695       l.Add(new NonSerializable());
    696       l.Add(new NonSerializable());
    697       try {
    698         var s = new ProtoBufSerializer();
    699         s.Serialize(l);
    700         Assert.Fail("Exception expected");
    701       } catch (PersistenceException px) {
    702       }
    703     }
    704 
    705     [TestMethod]
    706     [TestCategory("Persistence.Fossil")]
    707     [TestProperty("Time", "short")]
    708     public void InheritanceTest() {
    709       New n = new New();
    710       new ProtoBufSerializer().Serialize(n, tempFile);
    711       New nn = (New)new ProtoBufSerializer().Deserialize(tempFile);
    712       Assert.AreEqual(n.Name, nn.Name);
    713       Assert.AreEqual(((Override)n).Name, ((Override)nn).Name);
    714     }
    715 
    716     [StorableType("78636BDB-03B9-4BA1-979D-358997AA8063")]
    717     class Child {
    718       [Storable]
    719       public GrandParent grandParent;
    720 
    721       [StorableConstructor]
    722       protected Child(StorableConstructorFlag _) {
    723       }
    724       public Child() {
    725       }
    726     }
    727 
    728     [StorableType("B90F2371-DE30-48ED-BDAA-671B175C5698")]
    729     class Parent {
    730       [Storable]
    731       public Child child;
    732 
    733       [StorableConstructor]
    734       protected Parent(StorableConstructorFlag _) {
    735       }
    736       public Parent() {
    737       }
    738     }
    739 
    740     [StorableType("C48C28A9-F197-4B75-A21D-F21EF6AC0602")]
    741     class GrandParent {
    742       [Storable]
    743       public Parent parent;
    744 
    745       [StorableConstructor]
    746       protected GrandParent(StorableConstructorFlag _) {
    747       }
    748       public GrandParent() {
    749       }
    750     }
    751 
    752     [TestMethod]
    753     [TestCategory("Persistence.Fossil")]
    754     [TestProperty("Time", "short")]
    755     public void InstantiateParentChainReference() {
    756       GrandParent gp = new GrandParent();
    757       gp.parent = new Parent();
    758       gp.parent.child = new Child();
    759       gp.parent.child.grandParent = gp;
    760       Assert.AreSame(gp, gp.parent.child.grandParent);
    761       new ProtoBufSerializer().Serialize(gp, tempFile);
    762       GrandParent newGp = (GrandParent)new ProtoBufSerializer().Deserialize(tempFile);
    763       Assert.AreSame(newGp, newGp.parent.child.grandParent);
    764     }
    765 
    766     [StorableType("FB4F08BB-6B65-4FBE-BA72-531DB2194F1F")]
    767     struct TestStruct {
    768       int value;
    769       int PropertyValue { get; set; }
    770       public TestStruct(int value)
    771         : this() {
    772         this.value = value;
    773         PropertyValue = value;
    774       }
    775     }
    776 
    777     [TestMethod]
    778     [TestCategory("Persistence.Fossil")]
    779     [TestProperty("Time", "short")]
    780     public void StructTest() {
    781       TestStruct s = new TestStruct(10);
    782       new ProtoBufSerializer().Serialize(s, tempFile);
    783       TestStruct newS = (TestStruct)new ProtoBufSerializer().Deserialize(tempFile);
    784       Assert.AreEqual(s, newS);
    785     }
    786 
    787     [TestMethod]
    788     [TestCategory("Persistence.Fossil")]
    789     [TestProperty("Time", "short")]
    790     public void PointTest() {
    791       Point p = new Point(12, 34);
    792       new ProtoBufSerializer().Serialize(p, tempFile);
    793       Point newP = (Point)new ProtoBufSerializer().Deserialize(tempFile);
    794       Assert.AreEqual(p, newP);
    795     }
    796 
    797     [TestMethod]
    798     [TestCategory("Persistence.Fossil")]
    799     [TestProperty("Time", "short")]
    800     public void NullableValueTypes() {
    801       double?[] d = new double?[] { null, 1, 2, 3 };
    802       new ProtoBufSerializer().Serialize(d, tempFile);
    803       double?[] newD = (double?[])new ProtoBufSerializer().Deserialize(tempFile);
    804       Assert.AreEqual(d[0], newD[0]);
    805       Assert.AreEqual(d[1], newD[1]);
    806       Assert.AreEqual(d[2], newD[2]);
    807       Assert.AreEqual(d[3], newD[3]);
    808     }
    809 
    810     [TestMethod]
    811     [TestCategory("Persistence.Fossil")]
    812     [TestProperty("Time", "short")]
    81353    public void BitmapTest() {
    81454      Icon icon = System.Drawing.SystemIcons.Hand;
     
    82363    }
    82464
    825     [StorableType("5924A5A2-24C7-4588-951E-61212B041B0A")]
    826     private class PersistenceHooks {
    827       [Storable]
    828       public int a;
    829       [Storable]
    830       public int b;
    831       public int sum;
    832       public bool WasSerialized { get; private set; }
    833       [StorableHook(HookType.BeforeSerialization)]
    834       void PreSerializationHook() {
    835         WasSerialized = true;
    836       }
    837       [StorableHook(HookType.AfterDeserialization)]
    838       void PostDeserializationHook() {
    839         sum = a + b;
    840       }
    841 
    842       [StorableConstructor]
    843       protected PersistenceHooks(StorableConstructorFlag _) {
    844       }
    845       public PersistenceHooks() {
    846       }
    847     }
    848 
    849     [TestMethod]
    850     [TestCategory("Persistence.Fossil")]
    851     [TestProperty("Time", "short")]
    852     public void HookTest() {
    853       PersistenceHooks hookTest = new PersistenceHooks();
    854       hookTest.a = 2;
    855       hookTest.b = 5;
    856       Assert.IsFalse(hookTest.WasSerialized);
    857       Assert.AreEqual(hookTest.sum, 0);
    858       new ProtoBufSerializer().Serialize(hookTest, tempFile);
    859       Assert.IsTrue(hookTest.WasSerialized);
    860       Assert.AreEqual(hookTest.sum, 0);
    861       PersistenceHooks newHookTest = (PersistenceHooks)new ProtoBufSerializer().Deserialize(tempFile);
    862       Assert.AreEqual(newHookTest.a, hookTest.a);
    863       Assert.AreEqual(newHookTest.b, hookTest.b);
    864       Assert.AreEqual(newHookTest.sum, newHookTest.a + newHookTest.b);
    865       Assert.IsFalse(newHookTest.WasSerialized);
    866     }
    867 
    868     [StorableType("35824217-F1BC-450F-BB40-9B0A4F7C7582")]
    869     private class CustomConstructor {
    870       public string Value = "none";
    871       public CustomConstructor() {
    872         Value = "default";
    873       }
    874       [StorableConstructor]
    875       private CustomConstructor(StorableConstructorFlag _) {
    876         Value = "persistence";
    877       }
    878     }
    879 
    880     [TestMethod]
    881     [TestCategory("Persistence.Fossil")]
    882     [TestProperty("Time", "short")]
    883     public void TestCustomConstructor() {
    884       CustomConstructor cc = new CustomConstructor();
    885       Assert.AreEqual(cc.Value, "default");
    886       new ProtoBufSerializer().Serialize(cc, tempFile);
    887       CustomConstructor newCC = (CustomConstructor)new ProtoBufSerializer().Deserialize(tempFile);
    888       Assert.AreEqual(newCC.Value, "persistence");
    889     }
    890 
    891     [TestMethod]
    892     [TestCategory("Persistence.Fossil")]
    893     [TestProperty("Time", "short")]
    894     public void TestStreaming() {
    895       using (MemoryStream stream = new MemoryStream()) {
    896         Root r = InitializeComplexStorable();
    897         var ser = new ProtoBufSerializer();
    898         ser.Serialize(r, stream);
    899         using (MemoryStream stream2 = new MemoryStream(stream.ToArray())) {
    900           Root newR = (Root)ser.Deserialize(stream2);
    901           CompareComplexStorables(r, newR);
    902         }
    903       }
    904     }
    905 
    906     [StorableType("7CD5F148-397E-4539-88E0-EE19907E8BA6")]
    907     public class HookInheritanceTestBase {
    908       [Storable]
    909       public object a;
    910       public object link;
    911       [StorableHook(HookType.AfterDeserialization)]
    912       private void relink() {
    913         link = a;
    914       }
    915 
    916       [StorableConstructor]
    917       protected HookInheritanceTestBase(StorableConstructorFlag _) {
    918       }
    919       public HookInheritanceTestBase() {
    920       }
    921     }
    922 
    923     [StorableType("79E3EF89-A19A-408B-A18C-BFEB345159F0")]
    924     public class HookInheritanceTestDerivedClass : HookInheritanceTestBase {
    925       [Storable]
    926       public object b;
    927       [StorableHook(HookType.AfterDeserialization)]
    928       private void relink() {
    929         Assert.AreSame(a, link);
    930         link = b;
    931       }
    932 
    933       [StorableConstructor]
    934       protected HookInheritanceTestDerivedClass(StorableConstructorFlag _) : base(_) {
    935       }
    936       public HookInheritanceTestDerivedClass() {
    937       }
    938     }
    939 
    940     [TestMethod]
    941     [TestCategory("Persistence.Fossil")]
    942     [TestProperty("Time", "short")]
    943     public void TestLinkInheritance() {
    944       HookInheritanceTestDerivedClass c = new HookInheritanceTestDerivedClass();
    945       c.a = new object();
    946       new ProtoBufSerializer().Serialize(c, tempFile);
    947       HookInheritanceTestDerivedClass newC = (HookInheritanceTestDerivedClass)new ProtoBufSerializer().Deserialize(tempFile);
    948       Assert.AreSame(c.b, c.link);
    949     }
    950 
    951     [StorableType(StorableMemberSelection.AllFields, "B32F5C7A-F1C5-4B96-8A61-01E0DB1C526B")]
    952     public class AllFieldsStorable {
    953       public int Value1 = 1;
    954       [Storable]
    955       public int Value2 = 2;
    956       public int Value3 { get; private set; }
    957       public int Value4 { get; private set; }
    958       [StorableConstructor]
    959       protected AllFieldsStorable(StorableConstructorFlag _) { }
    960       public AllFieldsStorable() {
    961         Value1 = 12;
    962         Value2 = 23;
    963         Value3 = 34;
    964         Value4 = 56;
    965       }
    966     }
    967 
    968     [TestMethod]
    969     [TestCategory("Persistence.Fossil")]
    970     [TestProperty("Time", "short")]
    971     public void TestStorableClassDiscoveryAllFields() {
    972       AllFieldsStorable afs = new AllFieldsStorable();
    973       new ProtoBufSerializer().Serialize(afs, tempFile);
    974       AllFieldsStorable newAfs = (AllFieldsStorable)new ProtoBufSerializer().Deserialize(tempFile);
    975       Assert.AreEqual(afs.Value1, newAfs.Value1);
    976       Assert.AreEqual(afs.Value2, newAfs.Value2);
    977       Assert.AreEqual(0, newAfs.Value3);
    978       Assert.AreEqual(0, newAfs.Value4);
    979     }
    980 
    981     [StorableType(StorableMemberSelection.AllProperties, "60EE99CA-B391-4211-9FFB-2677490B33B6")]
    982     public class AllPropertiesStorable {
    983       public int Value1 = 1;
    984       [Storable]
    985       public int Value2 = 2;
    986       public int Value3 { get; private set; }
    987       public int Value4 { get; private set; }
    988       [StorableConstructor]
    989       protected AllPropertiesStorable(StorableConstructorFlag _) { }
    990       public AllPropertiesStorable() {
    991         Value1 = 12;
    992         Value2 = 23;
    993         Value3 = 34;
    994         Value4 = 56;
    995       }
    996     }
    997 
    998     [TestMethod]
    999     [TestCategory("Persistence.Fossil")]
    1000     [TestProperty("Time", "short")]
    1001     public void TestStorableClassDiscoveryAllProperties() {
    1002       AllPropertiesStorable afs = new AllPropertiesStorable();
    1003       new ProtoBufSerializer().Serialize(afs, tempFile);
    1004       AllPropertiesStorable newAfs = (AllPropertiesStorable)new ProtoBufSerializer().Deserialize(tempFile);
    1005       Assert.AreEqual(1, newAfs.Value1);
    1006       Assert.AreEqual(2, newAfs.Value2);
    1007       Assert.AreEqual(afs.Value3, newAfs.Value3);
    1008       Assert.AreEqual(afs.Value4, newAfs.Value4);
    1009 
    1010     }
    1011 
    1012     [StorableType(StorableMemberSelection.AllFieldsAndAllProperties, "97FAFC16-EC58-44CC-A833-CB951C0DD23B")]
    1013     public class AllFieldsAndAllPropertiesStorable {
    1014       public int Value1 = 1;
    1015       [Storable]
    1016       public int Value2 = 2;
    1017       public int Value3 { get; private set; }
    1018       public int Value4 { get; private set; }
    1019       [StorableConstructor]
    1020       protected AllFieldsAndAllPropertiesStorable(StorableConstructorFlag _) { }
    1021       public AllFieldsAndAllPropertiesStorable() {
    1022         Value1 = 12;
    1023         Value2 = 23;
    1024         Value3 = 34;
    1025         Value4 = 56;
    1026       }
    1027     }
    1028 
    1029     [TestMethod]
    1030     [TestCategory("Persistence.Fossil")]
    1031     [TestProperty("Time", "short")]
    1032     public void TestStorableClassDiscoveryAllFieldsAndAllProperties() {
    1033       AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable();
    1034       new ProtoBufSerializer().Serialize(afs, tempFile);
    1035       AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)new ProtoBufSerializer().Deserialize(tempFile);
    1036       Assert.AreEqual(afs.Value1, newAfs.Value1);
    1037       Assert.AreEqual(afs.Value2, newAfs.Value2);
    1038       Assert.AreEqual(afs.Value3, newAfs.Value3);
    1039       Assert.AreEqual(afs.Value4, newAfs.Value4);
    1040     }
    1041 
    1042     [StorableType("74BDE240-59D5-48C9-9A2A-5D44750DAF78")]
    1043     public class MarkedOnlyStorable {
    1044       public int Value1 = 1;
    1045       [Storable]
    1046       public int Value2 = 2;
    1047       public int Value3 { get; private set; }
    1048       public int Value4 { get; private set; }
    1049       [StorableConstructor]
    1050       protected MarkedOnlyStorable(StorableConstructorFlag _) { }
    1051       public MarkedOnlyStorable() {
    1052         Value1 = 12;
    1053         Value2 = 23;
    1054         Value3 = 34;
    1055         Value4 = 56;
    1056       }
    1057     }
    1058 
    1059     [TestMethod]
    1060     [TestCategory("Persistence.Fossil")]
    1061     [TestProperty("Time", "short")]
    1062     public void TestStorableClassDiscoveryMarkedOnly() {
    1063       MarkedOnlyStorable afs = new MarkedOnlyStorable();
    1064       new ProtoBufSerializer().Serialize(afs, tempFile);
    1065       MarkedOnlyStorable newAfs = (MarkedOnlyStorable)new ProtoBufSerializer().Deserialize(tempFile);
    1066       Assert.AreEqual(1, newAfs.Value1);
    1067       Assert.AreEqual(afs.Value2, newAfs.Value2);
    1068       Assert.AreEqual(0, newAfs.Value3);
    1069       Assert.AreEqual(0, newAfs.Value4);
    1070     }
    1071 
    1072     [TestMethod]
    1073     [TestCategory("Persistence.Fossil")]
    1074     [TestProperty("Time", "short")]
    1075     public void TestLineEndings() {
    1076       List<string> lineBreaks = new List<string> { "\r\n", "\n", "\r", "\n\r", Environment.NewLine };
    1077       List<string> lines = new List<string>();
    1078       foreach (var br in lineBreaks)
    1079         lines.Add("line1" + br + "line2");
    1080       new ProtoBufSerializer().Serialize(lines, tempFile);
    1081       List<string> newLines = (List<string>)new ProtoBufSerializer().Deserialize(tempFile);
    1082       Assert.AreEqual(lines.Count, newLines.Count);
    1083       for (int i = 0; i < lineBreaks.Count; i++) {
    1084         Assert.AreEqual(lines[i], newLines[i]);
    1085       }
    1086     }
    1087 
    1088     [TestMethod]
    1089     [TestCategory("Persistence.Fossil")]
    1090     [TestProperty("Time", "short")]
    1091     public void TestSpecialNumbers() {
    1092       List<double> specials = new List<double>() { 1.0 / 0, -1.0 / 0, 0.0 / 0 };
    1093       Assert.IsTrue(double.IsPositiveInfinity(specials[0]));
    1094       Assert.IsTrue(double.IsNegativeInfinity(specials[1]));
    1095       Assert.IsTrue(double.IsNaN(specials[2]));
    1096       new ProtoBufSerializer().Serialize(specials, tempFile);
    1097       List<double> newSpecials = (List<double>)new ProtoBufSerializer().Deserialize(tempFile);
    1098       Assert.IsTrue(double.IsPositiveInfinity(newSpecials[0]));
    1099       Assert.IsTrue(double.IsNegativeInfinity(newSpecials[1]));
    1100       Assert.IsTrue(double.IsNaN(newSpecials[2]));
    1101     }
    1102 
    1103     [TestMethod]
    1104     [TestCategory("Persistence.Fossil")]
    1105     [TestProperty("Time", "short")]
    1106     public void TestStringSplit() {
    1107       string s = "1.2;2.3;3.4;;;4.9";
    1108       var l = s.EnumerateSplit(';').ToList();
    1109       Assert.AreEqual("1.2", l[0]);
    1110       Assert.AreEqual("2.3", l[1]);
    1111       Assert.AreEqual("3.4", l[2]);
    1112       Assert.AreEqual("4.9", l[3]);
    1113     }
    1114 
    1115     [TestMethod]
    1116     [TestCategory("Persistence.Fossil")]
    1117     [TestProperty("Time", "medium")]
    1118     public void TestCompactNumberArraySerializer() {
    1119       System.Random r = new System.Random();
    1120       double[] a = new double[CompactNumberArray2StringSerializer.SPLIT_THRESHOLD * 2 + 1];
    1121       for (int i = 0; i < a.Length; i++)
    1122         a[i] = r.Next(10);
    1123       new ProtoBufSerializer().Serialize(a, tempFile);
    1124       double[] newA = (double[])new ProtoBufSerializer().Deserialize(tempFile);
    1125       Assert.AreEqual(a.Length, newA.Length);
    1126       for (int i = 0; i < a.Rank; i++) {
    1127         Assert.AreEqual(a.GetLength(i), newA.GetLength(i));
    1128         Assert.AreEqual(a.GetLowerBound(i), newA.GetLowerBound(i));
    1129       }
    1130       for (int i = 0; i < a.Length; i++) {
    1131         Assert.AreEqual(a[i], newA[i]);
    1132       }
    1133     }
    1134     [StorableType("A174C85C-3B7C-477D-9E6C-121301470DDE")]
    1135     private class IdentityComparer<T> : IEqualityComparer<T> {
    1136 
    1137       public bool Equals(T x, T y) {
    1138         return x.Equals(y);
    1139       }
    1140 
    1141       public int GetHashCode(T obj) {
    1142         return obj.GetHashCode();
    1143       }
    1144 
    1145       [StorableConstructor]
    1146       protected IdentityComparer(StorableConstructorFlag _) {
    1147       }
    1148       public IdentityComparer() {
    1149       }
    1150     }
    1151 
    1152     [TestMethod]
    1153     [TestCategory("Persistence.Fossil")]
    1154     [TestProperty("Time", "short")]
    1155     public void TestHashSetSerializer() {
    1156       var hashSets = new List<HashSet<int>>() {
    1157         new HashSet<int>(new[] { 1, 2, 3 }),
    1158         new HashSet<int>(new[] { 4, 5, 6 }, new IdentityComparer<int>()),
    1159       };
    1160       new ProtoBufSerializer().Serialize(hashSets, tempFile);
    1161       var newHashSets = (List<HashSet<int>>)new ProtoBufSerializer().Deserialize(tempFile);
    1162       Assert.IsTrue(newHashSets[0].Contains(1));
    1163       Assert.IsTrue(newHashSets[0].Contains(2));
    1164       Assert.IsTrue(newHashSets[0].Contains(3));
    1165       Assert.IsTrue(newHashSets[1].Contains(4));
    1166       Assert.IsTrue(newHashSets[1].Contains(5));
    1167       Assert.IsTrue(newHashSets[1].Contains(6));
    1168       Assert.AreEqual(newHashSets[0].Comparer.GetType(), new HashSet<int>().Comparer.GetType());
    1169       Assert.AreEqual(newHashSets[1].Comparer.GetType(), typeof(IdentityComparer<int>));
    1170     }
    1171 
    1172     [TestMethod]
    1173     [TestCategory("Persistence.Fossil")]
    1174     [TestProperty("Time", "short")]
    1175     public void TestConcreteDictionarySerializer() {
    1176       var dictionaries = new List<Dictionary<int, int>>() {
    1177         new Dictionary<int, int>(),
    1178         new Dictionary<int, int>(new IdentityComparer<int>()),
    1179       };
    1180       dictionaries[0].Add(1, 1);
    1181       dictionaries[0].Add(2, 2);
    1182       dictionaries[0].Add(3, 3);
    1183       dictionaries[1].Add(4, 4);
    1184       dictionaries[1].Add(5, 5);
    1185       dictionaries[1].Add(6, 6);
    1186       new ProtoBufSerializer().Serialize(dictionaries, tempFile);
    1187       var newDictionaries = (List<Dictionary<int, int>>)new ProtoBufSerializer().Deserialize(tempFile);
    1188       Assert.IsTrue(newDictionaries[0].ContainsKey(1));
    1189       Assert.IsTrue(newDictionaries[0].ContainsKey(2));
    1190       Assert.IsTrue(newDictionaries[0].ContainsKey(3));
    1191       Assert.IsTrue(newDictionaries[1].ContainsKey(4));
    1192       Assert.IsTrue(newDictionaries[1].ContainsKey(5));
    1193       Assert.IsTrue(newDictionaries[1].ContainsKey(6));
    1194       Assert.IsTrue(newDictionaries[0].ContainsValue(1));
    1195       Assert.IsTrue(newDictionaries[0].ContainsValue(2));
    1196       Assert.IsTrue(newDictionaries[0].ContainsValue(3));
    1197       Assert.IsTrue(newDictionaries[1].ContainsValue(4));
    1198       Assert.IsTrue(newDictionaries[1].ContainsValue(5));
    1199       Assert.IsTrue(newDictionaries[1].ContainsValue(6));
    1200       Assert.AreEqual(new Dictionary<int, int>().Comparer.GetType(), newDictionaries[0].Comparer.GetType());
    1201       Assert.AreEqual(typeof(IdentityComparer<int>), newDictionaries[1].Comparer.GetType());
    1202     }
    1203 
    1204     [StorableType("A5DAC970-4E03-4B69-A95A-9DAC683D051F")]
    1205     public class ReadOnlyFail {
    1206       [Storable]
    1207       public string ReadOnly {
    1208         get { return "fail"; }
    1209       }
    1210 
    1211       [StorableConstructor]
    1212       protected ReadOnlyFail(StorableConstructorFlag _) {
    1213       }
    1214       public ReadOnlyFail() {
    1215       }
    1216     }
    1217 
    1218     [TestMethod]
    1219     [TestCategory("Persistence.Fossil")]
    1220     [TestProperty("Time", "short")]
    1221     public void TestReadOnlyFail() {
    1222       try {
    1223         new ProtoBufSerializer().Serialize(new ReadOnlyFail(), tempFile);
    1224         Assert.Fail("Exception expected");
    1225       } catch (PersistenceException) {
    1226       } catch {
    1227         Assert.Fail("PersistenceException expected");
    1228       }
    1229     }
    1230 
    1231 
    1232     [StorableType("653EBC18-E461-4F5C-8FD6-9F588AAC70D9")]
    1233     public class WriteOnlyFail {
    1234       [Storable]
    1235       public string WriteOnly {
    1236         set { throw new InvalidOperationException("this property should never be set."); }
    1237       }
    1238 
    1239       [StorableConstructor]
    1240       protected WriteOnlyFail(StorableConstructorFlag _) {
    1241       }
    1242       public WriteOnlyFail() {
    1243       }
    1244     }
    1245 
    1246     [TestMethod]
    1247     [TestCategory("Persistence.Fossil")]
    1248     [TestProperty("Time", "short")]
    1249     public void TestWriteOnlyFail() {
    1250       try {
    1251         new ProtoBufSerializer().Serialize(new WriteOnlyFail(), tempFile);
    1252         Assert.Fail("Exception expected");
    1253       } catch (PersistenceException) {
    1254       } catch {
    1255         Assert.Fail("PersistenceException expected.");
    1256       }
    1257     }
    1258 
    1259     [StorableType("67BEAF29-9D7C-4C82-BD9F-9957798D6A2D")]
    1260     public class OneWayTest {
    1261       [StorableConstructor]
    1262       protected OneWayTest(StorableConstructorFlag _) {
    1263       }
    1264 
    1265       public OneWayTest() { this.value = "default"; }
    1266       public string value;
    1267       [Storable(AllowOneWay = true)]
    1268       public string ReadOnly {
    1269         get { return "ReadOnly"; }
    1270       }
    1271       [Storable(AllowOneWay = true)]
    1272       public string WriteOnly {
    1273         set { this.value = value; }
    1274       }
    1275     }
    1276 
    1277     [TestMethod]
    1278     [TestCategory("Persistence.Fossil")]
    1279     [TestProperty("Time", "short")]
    1280     public void TupleTest() {
    1281       var t1 = Tuple.Create(1);
    1282       var t2 = Tuple.Create('1', "2");
    1283       var t3 = Tuple.Create(3.0, 3f, 5);
    1284       var t4 = Tuple.Create(Tuple.Create(1, 2, 3), Tuple.Create(4, 5, 6), Tuple.Create(8, 9, 10));
    1285       var tuple = Tuple.Create(t1, t2, t3, t4);
    1286       new ProtoBufSerializer().Serialize(tuple, tempFile);
    1287       var newTuple = (Tuple<Tuple<int>, Tuple<char, string>, Tuple<double, float, int>, Tuple<Tuple<int, int, int>, Tuple<int, int, int>, Tuple<int, int, int>>>)new ProtoBufSerializer().Deserialize(tempFile);
    1288       Assert.AreEqual(tuple, newTuple);
    1289     }
    129065
    129166    [TestMethod]
     
    1349124    }
    1350125
    1351     [StorableType("6923FC3A-AC33-4CA9-919F-9707C00A663B")]
    1352     public class G<T, T2> {
    1353       [StorableType("16B88964-ECB3-4B41-95BC-EE3BE908CE4A")]
    1354       public class S { }
    1355       [StorableType("23CC1C7C-031E-4CBD-A87A-8F2235803BB4")]
    1356       public class S2<T3, T4> { }
    1357     }
    1358 
    1359     [TestMethod]
    1360     [TestCategory("Persistence.Fossil")]
    1361     [TestProperty("Time", "short")]
    1362     public void TestInternalClassOfGeneric() {
    1363       var s = new G<int, char>.S();
    1364       var typeName = s.GetType().AssemblyQualifiedName;
    1365       Assert.AreEqual(
    1366         "UseCases.G<Int32,Char>.S",
    1367         TypeNameParser.Parse(typeName).GetTypeNameInCode(false));
    1368       new ProtoBufSerializer().Serialize(s, tempFile);
    1369       var s1 = new ProtoBufSerializer().Deserialize(tempFile);
    1370     }
    1371 
    1372     [TestMethod]
    1373     [TestCategory("Persistence.Fossil")]
    1374     [TestProperty("Time", "short")]
    1375     public void TestInternalClassOfGeneric2() {
    1376       var s = new G<int, float>.S2<int, char>();
    1377       var typeName = s.GetType().AssemblyQualifiedName;
    1378       Assert.AreEqual(
    1379         "UseCases.G<Int32,Single>.S2<Int32,Char>",
    1380         TypeNameParser.Parse(typeName).GetTypeNameInCode(false));
    1381       new ProtoBufSerializer().Serialize(s, tempFile);
    1382       var s1 = new ProtoBufSerializer().Deserialize(tempFile);
    1383     }
    1384 
    1385     [TestMethod]
    1386     [TestCategory("Persistence.Fossil")]
    1387     [TestProperty("Time", "short")]
    1388     public void TestSpecialCharacters() {
    1389       var s = "abc" + "\x15" + "def";
    1390       new ProtoBufSerializer().Serialize(s, tempFile);
    1391       var newS = new ProtoBufSerializer().Deserialize(tempFile);
    1392       Assert.AreEqual(s, newS);
    1393     }
    1394 
    1395     [TestMethod]
    1396     [TestCategory("Persistence.Fossil")]
    1397     [TestProperty("Time", "short")]
    1398     public void TestByteArray() {
    1399       var b = new byte[3];
    1400       b[0] = 0;
    1401       b[1] = 200;
    1402       b[2] = byte.MaxValue;
    1403       new ProtoBufSerializer().Serialize(b, tempFile);
    1404       var newB = (byte[])new ProtoBufSerializer().Deserialize(tempFile);
    1405       CollectionAssert.AreEqual(b, newB);
    1406     }
    1407 
    1408     [TestMethod]
    1409     [TestCategory("Persistence.Fossil")]
    1410     [TestProperty("Time", "short")]
    1411     public void TestOptionalNumberEnumerable() {
    1412       var values = new List<double?> { 0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1 };
    1413       new ProtoBufSerializer().Serialize(values, tempFile);
    1414       var newValues = (List<double?>)new ProtoBufSerializer().Deserialize(tempFile);
    1415       CollectionAssert.AreEqual(values, newValues);
    1416     }
    1417 
    1418     [TestMethod]
    1419     [TestCategory("Persistence.Fossil")]
    1420     [TestProperty("Time", "short")]
    1421     public void TestOptionalDateTimeEnumerable() {
    1422       var values = new List<DateTime?> { DateTime.MinValue, null, DateTime.Now, DateTime.Now.Add(TimeSpan.FromDays(1)),
    1423         DateTime.ParseExact("10.09.2014 12:21", "dd.MM.yyyy hh:mm", CultureInfo.InvariantCulture), DateTime.MaxValue};
    1424       new ProtoBufSerializer().Serialize(values, tempFile);
    1425       var newValues = (List<DateTime?>)new ProtoBufSerializer().Deserialize(tempFile);
    1426       CollectionAssert.AreEqual(values, newValues);
    1427     }
    1428 
    1429     [TestMethod]
    1430     [TestCategory("Persistence.Fossil")]
    1431     [TestProperty("Time", "short")]
    1432     public void TestStringEnumerable() {
    1433       var values = new List<string> { "", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated" };
    1434       new ProtoBufSerializer().Serialize(values, tempFile);
    1435       var newValues = (List<String>)new ProtoBufSerializer().Deserialize(tempFile);
    1436       CollectionAssert.AreEqual(values, newValues);
    1437     }
    1438 
    1439     [TestMethod]
    1440     [TestCategory("Persistence.Fossil")]
    1441     [TestProperty("Time", "short")]
    1442     public void TestUnicodeCharArray() {
    1443       var s = Encoding.UTF8.GetChars(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb });
    1444       new ProtoBufSerializer().Serialize(s, tempFile);
    1445       var newS = (char[])new ProtoBufSerializer().Deserialize(tempFile);
    1446       CollectionAssert.AreEqual(s, newS);
    1447     }
    1448 
    1449     [TestMethod]
    1450     [TestCategory("Persistence.Fossil")]
    1451     [TestProperty("Time", "short")]
    1452     public void TestUnicode() {
    1453       var s = Encoding.UTF8.GetString(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb });
    1454       new ProtoBufSerializer().Serialize(s, tempFile);
    1455       var newS = new ProtoBufSerializer().Deserialize(tempFile);
    1456       Assert.AreEqual(s, newS);
    1457     }
    1458 
    1459     [TestMethod]
    1460     [TestCategory("Persistence.Fossil")]
    1461     [TestProperty("Time", "short")]
    1462     public void TestQueue() {
    1463       var q = new Queue<int>(new[] { 1, 2, 3, 4, 0 });
    1464       new ProtoBufSerializer().Serialize(q, tempFile);
    1465       var newQ = (Queue<int>)new ProtoBufSerializer().Deserialize(tempFile);
    1466       CollectionAssert.AreEqual(q, newQ);
    1467     }
    1468 
    1469 
    1470 
    1471126    [ClassInitialize]
    1472127    public static void Initialize(TestContext testContext) {
Note: See TracChangeset for help on using the changeset viewer.