Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/04/17 18:16:25 (7 years ago)
Author:
gkronber
Message:

#2520 added unit tests and fixed all test cases for old persistence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs

    r14927 r14928  
    3636using HeuristicLab.Persistence.Core.Tokens;
    3737using HeuristicLab.Persistence.Default.CompositeSerializers;
    38 using HeuristicLab.Persistence;
    3938using HeuristicLab.Persistence.Default.DebugString;
    4039using HeuristicLab.Persistence.Default.Xml;
     
    4342using HeuristicLab.Tests;
    4443using Microsoft.VisualStudio.TestTools.UnitTesting;
     44using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    4545
    4646namespace HeuristicLab.Persistence.Tests {
    4747
    48   [StorableClass]
     48  [StorableType("8658966d-3731-4588-8a92-25740c677478")]
    4949  public class NumberTest {
    5050    [Storable]
     
    9595  }
    9696
    97   [StorableClass]
     97  [StorableType("30315bb1-3cac-498f-9ff4-b27f0f6234a8")]
    9898  public class NonDefaultConstructorClass {
    9999    [Storable]
     
    104104  }
    105105
    106   [StorableClass]
     106  [StorableType("42019826-a9f7-4e78-b035-19292cd34d26")]
    107107  public class IntWrapper {
    108108
     
    127127  }
    128128
    129   [StorableClass]
     129  [StorableType("92810c22-155c-4e61-a3ec-79533e5d3c1e")]
    130130  public class PrimitivesTest : NumberTest {
    131131    [Storable]
     
    157157  }
    158158
    159   public enum TestEnum { va1, va2, va3, va8 } ;
    160 
    161   [StorableClass]
     159  [StorableType("09355759-308f-438d-95a1-63704159b833")]
     160  public enum TestEnum { va1, va2, va3, va8 };
     161
     162  [StorableType("92efaa22-6ae0-4004-a0a8-7bfe397d25d0")]
    162163  public class RootBase {
    163164    [Storable]
     
    178179  }
    179180
    180   [StorableClass]
     181  [StorableType("26b42eae-7dbb-46bb-84b3-d50d357eec05")]
    181182  public class Root : RootBase {
    182183    [Storable]
     
    208209  }
    209210
     211  [StorableType("b976a474-cae4-4f08-b425-e69977e1e4bf")]
    210212  public enum SimpleEnum { one, two, three }
     213  [StorableType("4f41591b-e0be-42ae-af66-800c20d21356")]
    211214  public enum ComplexEnum { one = 1, two = 2, three = 3 }
    212215  [FlagsAttribute]
     216  [StorableType("426bb2f4-7951-4378-a923-bc7a8ce56bd7")]
    213217  public enum TrickyEnum { zero = 0, one = 1, two = 2 }
    214218
    215   [StorableClass]
     219  [StorableType("0fe878c9-35e6-4478-8cbe-438211b7a3a5")]
    216220  public class EnumTest {
    217221    [Storable]
     
    223227  }
    224228
    225   [StorableClass]
     229  [StorableType("b83a36e8-7ba7-4ce4-82c3-602678c2a7a5")]
    226230  public class Custom {
    227231    [Storable]
     
    233237  }
    234238
    235   [StorableClass]
     239  [StorableType("fe285830-9dc6-4b77-8f8b-3c09a02ef1e0")]
    236240  public class Manager {
    237241
     
    246250  }
    247251
    248   [StorableClass]
     252  [StorableType("49551a89-6586-4ce1-8323-a8fd4409a0f6")]
    249253  public class C {
    250254    [Storable]
     
    269273
    270274  [TestClass]
     275  [StorableType("adca4c31-c835-4113-83aa-26a7a2cb3204")]
    271276  public class UseCases {
    272277
     
    486491    }
    487492
    488     [StorableClass]
     493    [StorableType("f4af4d3d-7ae6-4da5-ab3c-5df3ca2daca7")]
    489494    public class NestedType {
    490495      [Storable]
     
    589594        new Configuration(new XmlFormat(),
    590595          new List<IPrimitiveSerializer> { new String2XmlSerializer() },
    591           new List<ICompositeSerializer> { 
     596          new List<ICompositeSerializer> {
    592597            new StorableSerializer(),
    593598            new Number2StringSerializer() }));
     
    690695      l.Add(new NonSerializable());
    691696      try {
    692         Serializer s = new Serializer(l,
     697        var s = new HeuristicLab.Persistence.Core.Serializer(l,
    693698          ConfigurationService.Instance.GetConfiguration(new XmlFormat()),
    694699          "ROOT", true);
     
    708713    public void TestAssemblyVersionCheck() {
    709714      IntWrapper i = new IntWrapper(1);
    710       Serializer s = new Serializer(i, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));
     715      var s = new HeuristicLab.Persistence.Core.Serializer(i, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));
    711716      XmlGenerator g = new XmlGenerator();
    712717      StringBuilder dataString = new StringBuilder();
     
    753758    }
    754759
    755     [StorableClass]
     760    [StorableType("121169c6-b68a-491b-93e7-9925d508c0f3")]
    756761    class Child {
    757762      [Storable]
     
    759764    }
    760765
    761     [StorableClass]
     766    [StorableType("58a160dd-1851-4f78-b585-cdd05d4213f2")]
    762767    class Parent {
    763768      [Storable]
     
    765770    }
    766771
    767     [StorableClass]
     772    [StorableType("f99dbc0d-6f4c-4165-8d94-fb749f8cee33")]
    768773    class GrandParent {
    769774      [Storable]
     
    785790    }
    786791
     792    [StorableType("d4898d57-d578-4136-86f6-c8f615dbb4ab")]
    787793    struct TestStruct {
    788794      int value;
     
    843849    }
    844850
    845     [StorableClass]
     851    [StorableType("2a354c02-5268-41d1-b80f-c68f1d9c2337")]
    846852    private class PersistenceHooks {
    847853      [Storable]
     
    880886    }
    881887
    882     [StorableClass]
     888    [StorableType("fd155497-a299-413e-a251-220f9d21c92e")]
    883889    private class CustomConstructor {
    884890      public string Value = "none";
     
    904910    }
    905911
    906     [StorableClass]
     912    [StorableType("f6cbcbdd-a3a1-4a87-b2e4-413f0255b12a")]
    907913    public class ExplodingDefaultConstructor {
    908914      public ExplodingDefaultConstructor() {
     
    954960    }
    955961
    956     [StorableClass]
     962    [StorableType("7333a419-f549-4f88-a761-a1197cf90bce")]
    957963    public class HookInheritanceTestBase {
    958964      [Storable]
     
    965971    }
    966972
    967     [StorableClass]
     973    [StorableType("d05112d0-57db-43fc-86b2-a4da9d6cb84b")]
    968974    public class HookInheritanceTestDerivedClass : HookInheritanceTestBase {
    969975      [Storable]
     
    987993    }
    988994
    989     [StorableClass(StorableClassType.AllFields)]
     995    [StorableType(StorableMemberSelection.AllFields, "6f92b947-032a-4455-81e6-116bf4c31f92")]
    990996    public class AllFieldsStorable {
    991997      public int Value1 = 1;
     
    10181024    }
    10191025
    1020     [StorableClass(StorableClassType.AllProperties)]
     1026    [StorableType(StorableMemberSelection.AllProperties, "9e5eff24-617e-44bc-ae0f-258bfd804247")]
    10211027    public class AllPropertiesStorable {
    10221028      public int Value1 = 1;
     
    10501056    }
    10511057
    1052     [StorableClass(StorableClassType.AllFieldsAndAllProperties)]
     1058    [StorableType(StorableMemberSelection.AllFieldsAndAllProperties, "b6e3468d-5aaf-47d9-bd87-6931b2c705cd")]
    10531059    public class AllFieldsAndAllPropertiesStorable {
    10541060      public int Value1 = 1;
     
    10811087    }
    10821088
    1083     [StorableClass(StorableClassType.MarkedOnly)]
     1089    [StorableType(StorableMemberSelection.MarkedOnly, "1730eaa1-0507-4e08-94d8-64e213f3401d")]
    10841090    public class MarkedOnlyStorable {
    10851091      public int Value1 = 1;
     
    11781184      }
    11791185    }
     1186    [StorableType("57867b53-fafd-4c4f-aa15-dcfd87fbffe7")]
    11801187    private class IdentityComparer<T> : IEqualityComparer<T> {
    11811188
     
    12411248    }
    12421249
    1243     [StorableClass]
     1250    [StorableType("aa595fbc-7359-49ad-a274-204ff3c97bb4")]
    12441251    public class ReadOnlyFail {
    12451252      [Storable]
     
    12631270
    12641271
    1265     [StorableClass]
     1272    [StorableType("34008801-bb73-4810-ad1a-de9921b49a5d")]
    12661273    public class WriteOnlyFail {
    12671274      [Storable]
     
    12841291    }
    12851292
    1286     [StorableClass]
     1293    [StorableType("38575b53-c706-4d20-a255-c567c21c99a4")]
    12871294    public class OneWayTest {
    12881295      public OneWayTest() { this.value = "default"; }
     
    13031310    public void TestOneWaySerialization() {
    13041311      var test = new OneWayTest();
    1305       var serializer = new Serializer(test, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));
     1312      var serializer = new HeuristicLab.Persistence.Core.Serializer(test, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));
    13061313      var it = serializer.GetEnumerator();
    13071314      it.MoveNext();
     
    13091316      Assert.AreEqual("ReadOnly", ((PrimitiveToken)it.Current).Name); it.MoveNext();
    13101317      Assert.AreEqual("ROOT", ((EndToken)it.Current).Name); it.MoveNext();
    1311       var deserializer = new Deserializer(new[] { 
     1318      var deserializer = new Deserializer(new[] {
    13121319        new TypeMapping(0, typeof(OneWayTest).AssemblyQualifiedName, typeof(StorableSerializer).AssemblyQualifiedName),
    13131320        new TypeMapping(1, typeof(string).AssemblyQualifiedName, typeof(String2XmlSerializer).AssemblyQualifiedName) });
     
    14111418    }
    14121419
     1420    [StorableType("07c965fc-8bd3-4baf-967c-374e1e9d9b31")]
    14131421    public class G<T, T2> {
     1422      [StorableType("f9b10931-841f-4e93-b5d7-3d025a9bf998")]
    14141423      public class S { }
     1424      [StorableType("a9414e79-427a-4dd2-a231-832314c834e3")]
    14151425      public class S2<T3, T4> { }
    14161426    }
     
    14611471      b[2] = byte.MaxValue;
    14621472      XmlGenerator.Serialize(b, tempFile);
    1463       var newB = (byte[]) XmlParser.Deserialize(tempFile);
     1473      var newB = (byte[])XmlParser.Deserialize(tempFile);
    14641474      CollectionAssert.AreEqual(b, newB);
    14651475    }
     
    14691479    [TestProperty("Time", "short")]
    14701480    public void TestOptionalNumberEnumerable() {
    1471       var values = new List<double?> {0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1};
     1481      var values = new List<double?> { 0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1 };
    14721482      XmlGenerator.Serialize(values, tempFile);
    1473       var newValues = (List<double?>) XmlParser.Deserialize(tempFile);
     1483      var newValues = (List<double?>)XmlParser.Deserialize(tempFile);
    14741484      CollectionAssert.AreEqual(values, newValues);
    14751485    }
     
    14821492        DateTime.ParseExact("10.09.2014 12:21", "dd.MM.yyyy hh:mm", CultureInfo.InvariantCulture), DateTime.MaxValue};
    14831493      XmlGenerator.Serialize(values, tempFile);
    1484       var newValues = (List<DateTime?>) XmlParser.Deserialize(tempFile);
     1494      var newValues = (List<DateTime?>)XmlParser.Deserialize(tempFile);
    14851495      CollectionAssert.AreEqual(values, newValues);
    14861496    }
     
    14901500    [TestProperty("Time", "short")]
    14911501    public void TestStringEnumerable() {
    1492       var values = new List<string> {"", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated"};
     1502      var values = new List<string> { "", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated" };
    14931503      XmlGenerator.Serialize(values, tempFile);
    1494       var newValues = (List<String>) XmlParser.Deserialize(tempFile);
     1504      var newValues = (List<String>)XmlParser.Deserialize(tempFile);
    14951505      CollectionAssert.AreEqual(values, newValues);
    14961506    }
     
    15001510    [TestProperty("Time", "short")]
    15011511    public void TestUnicodeCharArray() {
    1502       var s = Encoding.UTF8.GetChars(new byte[] {0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb});
     1512      var s = Encoding.UTF8.GetChars(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb });
    15031513      XmlGenerator.Serialize(s, tempFile);
    15041514      var newS = (char[])XmlParser.Deserialize(tempFile);
     
    15101520    [TestProperty("Time", "short")]
    15111521    public void TestUnicode() {
    1512       var s = Encoding.UTF8.GetString(new byte[] {0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb});
     1522      var s = Encoding.UTF8.GetString(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb });
    15131523      XmlGenerator.Serialize(s, tempFile);
    15141524      var newS = XmlParser.Deserialize(tempFile);
     
    15201530    [TestProperty("Time", "short")]
    15211531    public void TestQueue() {
    1522       var q = new Queue<int>(new[] {1, 2, 3, 4, 0});
     1532      var q = new Queue<int>(new[] { 1, 2, 3, 4, 0 });
    15231533      XmlGenerator.Serialize(q, tempFile);
    15241534      var newQ = (Queue<int>)XmlParser.Deserialize(tempFile);
Note: See TracChangeset for help on using the changeset viewer.