Changeset 16462 for branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence.Fossil/UseCases.cs
- Timestamp:
- 12/28/18 16:10:48 (6 years ago)
- Location:
- branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence.Fossil
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence.Fossil/UseCases.cs
r16453 r16462 29 29 using System.Reflection; 30 30 using System.Text; 31 using System.Text.RegularExpressions;32 31 using System.Threading.Tasks; 32 using HEAL.Fossil; 33 33 using HeuristicLab.Algorithms.GeneticAlgorithm; 34 34 using HeuristicLab.Persistence.Auxiliary; 35 35 using HeuristicLab.Persistence.Core; 36 using HeuristicLab.Persistence.Core.Tokens;37 36 using HeuristicLab.Persistence.Default.CompositeSerializers; 38 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;39 37 using HeuristicLab.Persistence.Default.DebugString; 40 using HeuristicLab.Persistence.Default.Xml;41 using HeuristicLab.Persistence.Default.Xml.Primitive;42 using HeuristicLab.Persistence.Interfaces;43 38 using HeuristicLab.Tests; 44 39 using Microsoft.VisualStudio.TestTools.UnitTesting; 45 40 46 namespace HeuristicLab.Persistence. Tests {47 48 [Storable Class]41 namespace HeuristicLab.Persistence.Fossil.Tests { 42 43 [StorableType("22B5FC22-44FA-40B4-84E3-BB53540E812E")] 49 44 public class NumberTest { 50 45 [Storable] … … 93 88 _ulong.GetHashCode(); 94 89 } 90 91 [StorableConstructor] 92 protected NumberTest(StorableConstructorFlag _) { 93 } 94 public NumberTest() { 95 } 95 96 } 96 97 97 [StorableClass] 98 public class NonDefaultConstructorClass { 99 [Storable] 100 int value; 101 public NonDefaultConstructorClass(int value) { 102 this.value = value; 103 } 104 } 105 106 [StorableClass] 98 [StorableType("2D94AD3B-D411-403F-AC42-60824C78D802")] 107 99 public class IntWrapper { 108 100 109 101 [Storable] 110 102 public int Value; 103 104 [StorableConstructor] 105 protected IntWrapper(StorableConstructorFlag _) { 106 } 111 107 112 108 private IntWrapper() { } … … 127 123 } 128 124 129 [Storable Class]125 [StorableType("45337DD7-26D0-42D0-8CC4-92E184AE0218")] 130 126 public class PrimitivesTest : NumberTest { 131 127 [Storable] … … 155 151 o.GetHashCode(); 156 152 } 153 154 [StorableConstructor] 155 protected PrimitivesTest(StorableConstructorFlag _) : base(_) { 156 } 157 public PrimitivesTest() { 158 } 157 159 } 158 160 159 public enum TestEnum { va1, va2, va3, va8 } ; 160 161 [StorableClass] 161 [StorableType("2F63F603-CE7D-4262-99B4-A797F4D04907")] 162 public enum TestEnum { va1, va2, va3, va8 }; 163 164 [StorableType("DC944CA9-5F6A-4EF3-AFBD-881FC63797DF")] 162 165 public class RootBase { 163 166 [Storable] … … 176 179 myEnum.GetHashCode(); 177 180 } 181 182 [StorableConstructor] 183 protected RootBase(StorableConstructorFlag _) { 184 } 185 public RootBase() { 186 } 178 187 } 179 188 180 [Storable Class]189 [StorableType("C478905A-5029-4F31-9D92-524F41272D46")] 181 190 public class Root : RootBase { 182 191 [Storable] … … 206 215 [Storable(DefaultValue = "default")] 207 216 public string uninitialized; 217 218 [StorableConstructor] 219 protected Root(StorableConstructorFlag _) : base(_) { 220 } 221 public Root() { 222 } 208 223 } 209 224 225 [StorableType("23DCF22C-EDAB-4C5A-9941-0F2D6030D467")] 210 226 public enum SimpleEnum { one, two, three } 227 [StorableType("1FA5C129-129E-485C-A8A7-59FCA10CBB20")] 211 228 public enum ComplexEnum { one = 1, two = 2, three = 3 } 212 229 [FlagsAttribute] 230 [StorableType("D4A5D0CD-295C-4AC1-B5DA-D8DA2861E82C")] 213 231 public enum TrickyEnum { zero = 0, one = 1, two = 2 } 214 232 215 [Storable Class]233 [StorableType("C6EC77AF-C565-4A83-8922-3C6E2370627B")] 216 234 public class EnumTest { 217 235 [Storable] … … 221 239 [Storable] 222 240 public TrickyEnum trickyEnum = (TrickyEnum)15; 241 242 [StorableConstructor] 243 protected EnumTest(StorableConstructorFlag _) { 244 } 245 public EnumTest() { 246 } 223 247 } 224 248 225 [Storable Class]249 [StorableType("9E73E52B-9BF1-489D-9349-C490D518B7C4")] 226 250 public class Custom { 227 251 [Storable] … … 231 255 [Storable] 232 256 public string name = "<![CDATA[<![CDATA[Serial]]>]]>"; 257 258 [StorableConstructor] 259 protected Custom(StorableConstructorFlag _) { 260 } 261 262 public Custom() { 263 264 } 233 265 } 234 266 235 [Storable Class]267 [StorableType("CEE5C689-948F-443A-A645-54868D913364")] 236 268 public class Manager { 237 269 … … 244 276 [Storable] 245 277 public double? dbl; 278 279 [StorableConstructor] 280 protected Manager(StorableConstructorFlag _) { 281 } 282 public Manager() { 283 } 246 284 } 247 285 248 [Storable Class]286 [StorableType("14EB77CD-7061-4B2E-96EB-3E45CC265256")] 249 287 public class C { 250 288 [Storable] … … 252 290 [Storable] 253 291 public KeyValuePair<List<C>, C> kvpList; 292 293 [StorableConstructor] 294 protected C(StorableConstructorFlag _) { 295 } 296 public C() { 297 } 254 298 } 255 299 … … 287 331 288 332 [TestMethod] 289 [TestCategory("Persistence ")]333 [TestCategory("Persistence.Fossil")] 290 334 [TestProperty("Time", "short")] 291 335 public void ComplexStorable() { 292 336 Root r = InitializeComplexStorable(); 293 XmlGenerator.Serialize(r, tempFile); 294 Root newR = (Root)XmlParser.Deserialize(tempFile); 337 var ser = new ProtoBufSerializer(); 338 ser.Serialize(r, tempFile); 339 Root newR = (Root)ser.Deserialize(tempFile); 295 340 CompareComplexStorables(r, newR); 296 341 } 297 342 298 [TestMethod]299 [TestCategory("Persistence")]300 [TestProperty("Time", "short")]301 public void ComplexEasyStorable() {302 Root r = InitializeComplexStorable();303 ReadableXmlGenerator.Serialize(r, tempFile);304 using (var reader = new StreamReader(tempFile)) {305 string text = reader.ReadToEnd();306 Assert.IsTrue(text.StartsWith("<Root"));307 }308 }309 310 343 private static void CompareComplexStorables(Root r, Root newR) { 311 Assert.AreEqual(312 DebugStringGenerator.Serialize(r),313 DebugStringGenerator.Serialize(newR));314 344 Assert.AreSame(newR, newR.selfReferences[0]); 315 345 Assert.AreNotSame(r, newR); … … 388 418 389 419 [TestMethod] 390 [TestCategory("Persistence ")]420 [TestCategory("Persistence.Fossil")] 391 421 [TestProperty("Time", "short")] 392 422 public void SelfReferences() { … … 397 427 c.allCs = cs; 398 428 c.kvpList = new KeyValuePair<List<C>, C>(new List<C> { c }, c); 399 XmlGenerator.Serialize(cs, tempFile);400 object o = XmlParser.Deserialize(tempFile);429 new ProtoBufSerializer().Serialize(cs, tempFile); 430 object o = new ProtoBufSerializer().Deserialize(tempFile); 401 431 Assert.AreEqual( 402 432 DebugStringGenerator.Serialize(cs), … … 415 445 416 446 [TestMethod] 417 [TestCategory("Persistence ")]447 [TestCategory("Persistence.Fossil")] 418 448 [TestProperty("Time", "short")] 419 449 public void ArrayCreation() { … … 431 461 new[] { 1, 2 }, new[] { 3, 4 }); 432 462 arrayListArray[2].Add(a); 433 XmlGenerator.Serialize(arrayListArray, tempFile);434 object o = XmlParser.Deserialize(tempFile);463 new ProtoBufSerializer().Serialize(arrayListArray, tempFile); 464 object o = new ProtoBufSerializer().Deserialize(tempFile); 435 465 Assert.AreEqual( 436 466 DebugStringGenerator.Serialize(arrayListArray), … … 444 474 445 475 [TestMethod] 446 [TestCategory("Persistence ")]476 [TestCategory("Persistence.Fossil")] 447 477 [TestProperty("Time", "short")] 448 478 public void CustomSerializationProperty() { 449 479 Manager m = new Manager(); 450 XmlGenerator.Serialize(m, tempFile);451 Manager newM = (Manager) XmlParser.Deserialize(tempFile);480 new ProtoBufSerializer().Serialize(m, tempFile); 481 Manager newM = (Manager)new ProtoBufSerializer().Deserialize(tempFile); 452 482 Assert.AreNotEqual( 453 483 DebugStringGenerator.Serialize(m), … … 460 490 461 491 [TestMethod] 462 [TestCategory("Persistence ")]492 [TestCategory("Persistence.Fossil")] 463 493 [TestProperty("Time", "short")] 464 494 public void Primitives() { 465 495 PrimitivesTest sdt = new PrimitivesTest(); 466 XmlGenerator.Serialize(sdt, tempFile);467 object o = XmlParser.Deserialize(tempFile);496 new ProtoBufSerializer().Serialize(sdt, tempFile); 497 object o = new ProtoBufSerializer().Deserialize(tempFile); 468 498 Assert.AreEqual( 469 499 DebugStringGenerator.Serialize(sdt), … … 472 502 473 503 [TestMethod] 474 [TestCategory("Persistence ")]504 [TestCategory("Persistence.Fossil")] 475 505 [TestProperty("Time", "short")] 476 506 public void MultiDimensionalArray() { … … 479 509 {"Beten", "und", "Arbeiten"} 480 510 }; 481 XmlGenerator.Serialize(mDimString, tempFile);482 object o = XmlParser.Deserialize(tempFile);511 new ProtoBufSerializer().Serialize(mDimString, tempFile); 512 object o = new ProtoBufSerializer().Deserialize(tempFile); 483 513 Assert.AreEqual( 484 514 DebugStringGenerator.Serialize(mDimString), … … 486 516 } 487 517 488 [Storable Class]518 [StorableType("59E73F41-B9D4-489B-AA9C-3A72173498CC")] 489 519 public class NestedType { 490 520 [Storable] … … 499 529 return value.GetHashCode(); 500 530 } 501 } 502 503 [TestMethod] 504 [TestCategory("Persistence")] 531 532 [StorableConstructor] 533 protected NestedType(StorableConstructorFlag _) { 534 } 535 public NestedType() { 536 } 537 } 538 539 [TestMethod] 540 [TestCategory("Persistence.Fossil")] 505 541 [TestProperty("Time", "short")] 506 542 public void NestedTypeTest() { 507 543 NestedType t = new NestedType(); 508 XmlGenerator.Serialize(t, tempFile);509 object o = XmlParser.Deserialize(tempFile);544 new ProtoBufSerializer().Serialize(t, tempFile); 545 object o = new ProtoBufSerializer().Deserialize(tempFile); 510 546 Assert.AreEqual( 511 547 DebugStringGenerator.Serialize(t), … … 516 552 517 553 [TestMethod] 518 [TestCategory("Persistence ")]554 [TestCategory("Persistence.Fossil")] 519 555 [TestProperty("Time", "short")] 520 556 public void SimpleArray() { 521 557 string[] strings = { "ora", "et", "labora" }; 522 XmlGenerator.Serialize(strings, tempFile);523 object o = XmlParser.Deserialize(tempFile);558 new ProtoBufSerializer().Serialize(strings, tempFile); 559 object o = new ProtoBufSerializer().Deserialize(tempFile); 524 560 Assert.AreEqual( 525 561 DebugStringGenerator.Serialize(strings), … … 528 564 529 565 [TestMethod] 530 [TestCategory("Persistence ")]566 [TestCategory("Persistence.Fossil")] 531 567 [TestProperty("Time", "short")] 532 568 public void PrimitiveRoot() { 533 XmlGenerator.Serialize(12.3f, tempFile);534 object o = XmlParser.Deserialize(tempFile);569 new ProtoBufSerializer().Serialize(12.3f, tempFile); 570 object o = new ProtoBufSerializer().Deserialize(tempFile); 535 571 Assert.AreEqual( 536 572 DebugStringGenerator.Serialize(12.3f), … … 582 618 583 619 [TestMethod] 584 [TestCategory("Persistence")] 585 [TestProperty("Time", "short")] 586 public void Number2StringDecomposer() { 587 NumberTest sdt = new NumberTest(); 588 XmlGenerator.Serialize(sdt, tempFile, 589 new Configuration(new XmlFormat(), 590 new List<IPrimitiveSerializer> { new String2XmlSerializer() }, 591 new List<ICompositeSerializer> { 592 new StorableSerializer(), 593 new Number2StringSerializer() })); 594 object o = XmlParser.Deserialize(tempFile); 595 Assert.AreEqual( 596 DebugStringGenerator.Serialize(sdt), 597 DebugStringGenerator.Serialize(o)); 598 Assert.IsTrue(sdt.Equals(o)); 599 } 600 601 [TestMethod] 602 [TestCategory("Persistence")] 620 [TestCategory("Persistence.Fossil")] 603 621 [TestProperty("Time", "short")] 604 622 public void Enums() { … … 607 625 et.complexEnum = ComplexEnum.three; 608 626 et.trickyEnum = TrickyEnum.two | TrickyEnum.one; 609 XmlGenerator.Serialize(et, tempFile);610 EnumTest newEt = (EnumTest) XmlParser.Deserialize(tempFile);627 new ProtoBufSerializer().Serialize(et, tempFile); 628 EnumTest newEt = (EnumTest)new ProtoBufSerializer().Deserialize(tempFile); 611 629 Assert.AreEqual(et.simpleEnum, SimpleEnum.two); 612 630 Assert.AreEqual(et.complexEnum, ComplexEnum.three); … … 615 633 616 634 [TestMethod] 617 [TestCategory("Persistence ")]635 [TestCategory("Persistence.Fossil")] 618 636 [TestProperty("Time", "short")] 619 637 public void TestAliasingWithOverriddenEquals() { … … 623 641 Assert.AreEqual(ints[0], ints[1]); 624 642 Assert.AreNotSame(ints[0], ints[1]); 625 XmlGenerator.Serialize(ints, tempFile);626 List<IntWrapper> newInts = (List<IntWrapper>) XmlParser.Deserialize(tempFile);643 new ProtoBufSerializer().Serialize(ints, tempFile); 644 List<IntWrapper> newInts = (List<IntWrapper>)new ProtoBufSerializer().Deserialize(tempFile); 627 645 Assert.AreEqual(newInts[0].Value, 1); 628 646 Assert.AreEqual(newInts[1].Value, 1); … … 632 650 633 651 [TestMethod] 634 [TestCategory("Persistence")] 635 [TestProperty("Time", "short")] 636 public void NonDefaultConstructorTest() { 637 NonDefaultConstructorClass c = new NonDefaultConstructorClass(1); 638 try { 639 XmlGenerator.Serialize(c, tempFile); 640 Assert.Fail("Exception not thrown"); 641 } catch (PersistenceException) { 642 } 643 } 644 645 [TestMethod] 646 [TestCategory("Persistence")] 652 [TestCategory("Persistence.Fossil")] 647 653 [TestProperty("Time", "short")] 648 654 public void TestSavingException() { 649 655 List<int> list = new List<int> { 1, 2, 3 }; 650 XmlGenerator.Serialize(list, tempFile);656 new ProtoBufSerializer().Serialize(list, tempFile); 651 657 NonSerializable s = new NonSerializable(); 652 658 try { 653 XmlGenerator.Serialize(s, tempFile);659 new ProtoBufSerializer().Serialize(s, tempFile); 654 660 Assert.Fail("Exception expected"); 655 661 } catch (PersistenceException) { } 656 List<int> newList = (List<int>) XmlParser.Deserialize(tempFile);662 List<int> newList = (List<int>)new ProtoBufSerializer().Deserialize(tempFile); 657 663 Assert.AreEqual(list[0], newList[0]); 658 664 Assert.AreEqual(list[1], newList[1]); … … 660 666 661 667 [TestMethod] 662 [TestCategory("Persistence ")]668 [TestCategory("Persistence.Fossil")] 663 669 [TestProperty("Time", "short")] 664 670 public void TestTypeStringConversion() { … … 672 678 673 679 [TestMethod] 674 [TestCategory("Persistence ")]680 [TestCategory("Persistence.Fossil")] 675 681 [TestProperty("Time", "short")] 676 682 public void TestHexadecimalPublicKeyToken() { … … 682 688 683 689 [TestMethod] 684 [TestCategory("Persistence ")]690 [TestCategory("Persistence.Fossil")] 685 691 [TestProperty("Time", "short")] 686 692 public void TestMultipleFailure() { … … 690 696 l.Add(new NonSerializable()); 691 697 try { 692 Serializer s = new Serializer(l, 693 ConfigurationService.Instance.GetConfiguration(new XmlFormat()), 694 "ROOT", true); 695 StringBuilder tokens = new StringBuilder(); 696 foreach (var token in s) { 697 tokens.Append(token.ToString()); 698 } 698 var s = new ProtoBufSerializer(); 699 s.Serialize(l); 699 700 Assert.Fail("Exception expected"); 700 701 } catch (PersistenceException px) { 701 Assert.AreEqual(3, px.Data.Count); 702 } 703 } 704 705 [TestMethod] 706 [TestCategory("Persistence")] 707 [TestProperty("Time", "short")] 708 public void TestAssemblyVersionCheck() { 709 IntWrapper i = new IntWrapper(1); 710 Serializer s = new Serializer(i, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 711 XmlGenerator g = new XmlGenerator(); 712 StringBuilder dataString = new StringBuilder(); 713 foreach (var token in s) { 714 dataString.Append(g.Format(token)); 715 } 716 StringBuilder typeString = new StringBuilder(); 717 foreach (var line in g.Format(s.TypeCache)) 718 typeString.Append(line); 719 Deserializer d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(typeString.ToString()))); 720 XmlParser p = new XmlParser(new StringReader(dataString.ToString())); 721 IntWrapper newI = (IntWrapper)d.Deserialize(p); 722 Assert.AreEqual(i.Value, newI.Value); 723 724 string newTypeString = Regex.Replace(typeString.ToString(), 725 "Version=\\d+\\.\\d+\\.\\d+\\.\\d+", 726 "Version=0.0.9999.9999"); 727 try { 728 d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(newTypeString))); 729 Assert.Fail("Exception expected"); 730 } catch (PersistenceException x) { 731 Assert.IsTrue(x.Message.Contains("incompatible")); 732 } 733 newTypeString = Regex.Replace(typeString.ToString(), 734 "Version=(\\d+\\.\\d+)\\.\\d+\\.\\d+", 735 "Version=$1.9999.9999"); 736 try { 737 d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(newTypeString))); 738 Assert.Fail("Exception expected"); 739 } catch (PersistenceException x) { 740 Assert.IsTrue(x.Message.Contains("newer")); 741 } 742 } 743 744 [TestMethod] 745 [TestCategory("Persistence")] 702 } 703 } 704 705 [TestMethod] 706 [TestCategory("Persistence.Fossil")] 746 707 [TestProperty("Time", "short")] 747 708 public void InheritanceTest() { 748 709 New n = new New(); 749 XmlGenerator.Serialize(n, tempFile);750 New nn = (New) XmlParser.Deserialize(tempFile);710 new ProtoBufSerializer().Serialize(n, tempFile); 711 New nn = (New)new ProtoBufSerializer().Deserialize(tempFile); 751 712 Assert.AreEqual(n.Name, nn.Name); 752 713 Assert.AreEqual(((Override)n).Name, ((Override)nn).Name); 753 714 } 754 715 755 [Storable Class]716 [StorableType("78636BDB-03B9-4BA1-979D-358997AA8063")] 756 717 class Child { 757 718 [Storable] 758 719 public GrandParent grandParent; 759 } 760 761 [StorableClass] 720 721 [StorableConstructor] 722 protected Child(StorableConstructorFlag _) { 723 } 724 public Child() { 725 } 726 } 727 728 [StorableType("B90F2371-DE30-48ED-BDAA-671B175C5698")] 762 729 class Parent { 763 730 [Storable] 764 731 public Child child; 765 } 766 767 [StorableClass] 732 733 [StorableConstructor] 734 protected Parent(StorableConstructorFlag _) { 735 } 736 public Parent() { 737 } 738 } 739 740 [StorableType("C48C28A9-F197-4B75-A21D-F21EF6AC0602")] 768 741 class GrandParent { 769 742 [Storable] 770 743 public Parent parent; 771 } 772 773 [TestMethod] 774 [TestCategory("Persistence")] 744 745 [StorableConstructor] 746 protected GrandParent(StorableConstructorFlag _) { 747 } 748 public GrandParent() { 749 } 750 } 751 752 [TestMethod] 753 [TestCategory("Persistence.Fossil")] 775 754 [TestProperty("Time", "short")] 776 755 public void InstantiateParentChainReference() { … … 780 759 gp.parent.child.grandParent = gp; 781 760 Assert.AreSame(gp, gp.parent.child.grandParent); 782 XmlGenerator.Serialize(gp, tempFile);783 GrandParent newGp = (GrandParent) XmlParser.Deserialize(tempFile);761 new ProtoBufSerializer().Serialize(gp, tempFile); 762 GrandParent newGp = (GrandParent)new ProtoBufSerializer().Deserialize(tempFile); 784 763 Assert.AreSame(newGp, newGp.parent.child.grandParent); 785 764 } 786 765 766 [StorableType("FB4F08BB-6B65-4FBE-BA72-531DB2194F1F")] 787 767 struct TestStruct { 788 768 int value; … … 796 776 797 777 [TestMethod] 798 [TestCategory("Persistence ")]778 [TestCategory("Persistence.Fossil")] 799 779 [TestProperty("Time", "short")] 800 780 public void StructTest() { 801 781 TestStruct s = new TestStruct(10); 802 XmlGenerator.Serialize(s, tempFile);803 TestStruct newS = (TestStruct) XmlParser.Deserialize(tempFile);782 new ProtoBufSerializer().Serialize(s, tempFile); 783 TestStruct newS = (TestStruct)new ProtoBufSerializer().Deserialize(tempFile); 804 784 Assert.AreEqual(s, newS); 805 785 } 806 786 807 787 [TestMethod] 808 [TestCategory("Persistence ")]788 [TestCategory("Persistence.Fossil")] 809 789 [TestProperty("Time", "short")] 810 790 public void PointTest() { 811 791 Point p = new Point(12, 34); 812 XmlGenerator.Serialize(p, tempFile);813 Point newP = (Point) XmlParser.Deserialize(tempFile);792 new ProtoBufSerializer().Serialize(p, tempFile); 793 Point newP = (Point)new ProtoBufSerializer().Deserialize(tempFile); 814 794 Assert.AreEqual(p, newP); 815 795 } 816 796 817 797 [TestMethod] 818 [TestCategory("Persistence ")]798 [TestCategory("Persistence.Fossil")] 819 799 [TestProperty("Time", "short")] 820 800 public void NullableValueTypes() { 821 801 double?[] d = new double?[] { null, 1, 2, 3 }; 822 XmlGenerator.Serialize(d, tempFile);823 double?[] newD = (double?[]) XmlParser.Deserialize(tempFile);802 new ProtoBufSerializer().Serialize(d, tempFile); 803 double?[] newD = (double?[])new ProtoBufSerializer().Deserialize(tempFile); 824 804 Assert.AreEqual(d[0], newD[0]); 825 805 Assert.AreEqual(d[1], newD[1]); … … 829 809 830 810 [TestMethod] 831 [TestCategory("Persistence ")]811 [TestCategory("Persistence.Fossil")] 832 812 [TestProperty("Time", "short")] 833 813 public void BitmapTest() { 834 814 Icon icon = System.Drawing.SystemIcons.Hand; 835 815 Bitmap bitmap = icon.ToBitmap(); 836 XmlGenerator.Serialize(bitmap, tempFile);837 Bitmap newBitmap = (Bitmap) XmlParser.Deserialize(tempFile);816 new ProtoBufSerializer().Serialize(bitmap, tempFile); 817 Bitmap newBitmap = (Bitmap)new ProtoBufSerializer().Deserialize(tempFile); 838 818 839 819 Assert.AreEqual(bitmap.Size, newBitmap.Size); … … 843 823 } 844 824 845 [Storable Class]825 [StorableType("5924A5A2-24C7-4588-951E-61212B041B0A")] 846 826 private class PersistenceHooks { 847 827 [Storable] … … 859 839 sum = a + b; 860 840 } 861 } 862 863 [TestMethod] 864 [TestCategory("Persistence")] 841 842 [StorableConstructor] 843 protected PersistenceHooks(StorableConstructorFlag _) { 844 } 845 public PersistenceHooks() { 846 } 847 } 848 849 [TestMethod] 850 [TestCategory("Persistence.Fossil")] 865 851 [TestProperty("Time", "short")] 866 852 public void HookTest() { … … 870 856 Assert.IsFalse(hookTest.WasSerialized); 871 857 Assert.AreEqual(hookTest.sum, 0); 872 XmlGenerator.Serialize(hookTest, tempFile);858 new ProtoBufSerializer().Serialize(hookTest, tempFile); 873 859 Assert.IsTrue(hookTest.WasSerialized); 874 860 Assert.AreEqual(hookTest.sum, 0); 875 PersistenceHooks newHookTest = (PersistenceHooks) XmlParser.Deserialize(tempFile);861 PersistenceHooks newHookTest = (PersistenceHooks)new ProtoBufSerializer().Deserialize(tempFile); 876 862 Assert.AreEqual(newHookTest.a, hookTest.a); 877 863 Assert.AreEqual(newHookTest.b, hookTest.b); … … 880 866 } 881 867 882 [Storable Class]868 [StorableType("35824217-F1BC-450F-BB40-9B0A4F7C7582")] 883 869 private class CustomConstructor { 884 870 public string Value = "none"; … … 887 873 } 888 874 [StorableConstructor] 889 private CustomConstructor(bool deserializing) { 890 Assert.IsTrue(deserializing); 875 private CustomConstructor(StorableConstructorFlag _) { 891 876 Value = "persistence"; 892 877 } … … 894 879 895 880 [TestMethod] 896 [TestCategory("Persistence ")]881 [TestCategory("Persistence.Fossil")] 897 882 [TestProperty("Time", "short")] 898 883 public void TestCustomConstructor() { 899 884 CustomConstructor cc = new CustomConstructor(); 900 885 Assert.AreEqual(cc.Value, "default"); 901 XmlGenerator.Serialize(cc, tempFile);902 CustomConstructor newCC = (CustomConstructor) XmlParser.Deserialize(tempFile);886 new ProtoBufSerializer().Serialize(cc, tempFile); 887 CustomConstructor newCC = (CustomConstructor)new ProtoBufSerializer().Deserialize(tempFile); 903 888 Assert.AreEqual(newCC.Value, "persistence"); 904 889 } 905 890 906 [StorableClass] 907 public class ExplodingDefaultConstructor { 908 public ExplodingDefaultConstructor() { 909 throw new Exception("this constructor will always fail"); 910 } 911 public ExplodingDefaultConstructor(string password) { 912 } 913 } 914 915 [TestMethod] 916 [TestCategory("Persistence")] 917 [TestProperty("Time", "short")] 918 public void TestConstructorExceptionUnwrapping() { 919 ExplodingDefaultConstructor x = new ExplodingDefaultConstructor("password"); 920 XmlGenerator.Serialize(x, tempFile); 921 try { 922 ExplodingDefaultConstructor newX = (ExplodingDefaultConstructor)XmlParser.Deserialize(tempFile); 923 Assert.Fail("Exception expected"); 924 } catch (PersistenceException pe) { 925 Assert.AreEqual(pe.InnerException.Message, "this constructor will always fail"); 926 } 927 } 928 929 [TestMethod] 930 [TestCategory("Persistence")] 931 [TestProperty("Time", "short")] 932 public void TestRejectionJustifications() { 933 NonSerializable ns = new NonSerializable(); 934 try { 935 XmlGenerator.Serialize(ns, tempFile); 936 Assert.Fail("PersistenceException expected"); 937 } catch (PersistenceException x) { 938 Assert.IsTrue(x.Message.Contains(new StorableSerializer().JustifyRejection(typeof(NonSerializable)))); 939 } 940 } 941 942 [TestMethod] 943 [TestCategory("Persistence")] 891 [TestMethod] 892 [TestCategory("Persistence.Fossil")] 944 893 [TestProperty("Time", "short")] 945 894 public void TestStreaming() { 946 895 using (MemoryStream stream = new MemoryStream()) { 947 896 Root r = InitializeComplexStorable(); 948 XmlGenerator.Serialize(r, stream); 897 var ser = new ProtoBufSerializer(); 898 ser.Serialize(r, stream); 949 899 using (MemoryStream stream2 = new MemoryStream(stream.ToArray())) { 950 Root newR = (Root) XmlParser.Deserialize(stream2);900 Root newR = (Root)ser.Deserialize(stream2); 951 901 CompareComplexStorables(r, newR); 952 902 } … … 954 904 } 955 905 956 [Storable Class]906 [StorableType("7CD5F148-397E-4539-88E0-EE19907E8BA6")] 957 907 public class HookInheritanceTestBase { 958 908 [Storable] … … 963 913 link = a; 964 914 } 965 } 966 967 [StorableClass] 915 916 [StorableConstructor] 917 protected HookInheritanceTestBase(StorableConstructorFlag _) { 918 } 919 public HookInheritanceTestBase() { 920 } 921 } 922 923 [StorableType("79E3EF89-A19A-408B-A18C-BFEB345159F0")] 968 924 public class HookInheritanceTestDerivedClass : HookInheritanceTestBase { 969 925 [Storable] … … 974 930 link = b; 975 931 } 976 } 977 978 [TestMethod] 979 [TestCategory("Persistence")] 932 933 [StorableConstructor] 934 protected HookInheritanceTestDerivedClass(StorableConstructorFlag _) : base(_) { 935 } 936 public HookInheritanceTestDerivedClass() { 937 } 938 } 939 940 [TestMethod] 941 [TestCategory("Persistence.Fossil")] 980 942 [TestProperty("Time", "short")] 981 943 public void TestLinkInheritance() { 982 944 HookInheritanceTestDerivedClass c = new HookInheritanceTestDerivedClass(); 983 945 c.a = new object(); 984 XmlGenerator.Serialize(c, tempFile);985 HookInheritanceTestDerivedClass newC = (HookInheritanceTestDerivedClass) XmlParser.Deserialize(tempFile);946 new ProtoBufSerializer().Serialize(c, tempFile); 947 HookInheritanceTestDerivedClass newC = (HookInheritanceTestDerivedClass)new ProtoBufSerializer().Deserialize(tempFile); 986 948 Assert.AreSame(c.b, c.link); 987 949 } 988 950 989 [Storable Class(StorableClassType.AllFields)]951 [StorableType(StorableMemberSelection.AllFields, "B32F5C7A-F1C5-4B96-8A61-01E0DB1C526B")] 990 952 public class AllFieldsStorable { 991 953 public int Value1 = 1; … … 995 957 public int Value4 { get; private set; } 996 958 [StorableConstructor] 997 public AllFieldsStorable(bool isDeserializing) { 998 if (!isDeserializing) { 999 Value1 = 12; 1000 Value2 = 23; 1001 Value3 = 34; 1002 Value4 = 56; 1003 } 1004 } 1005 } 1006 1007 [TestMethod] 1008 [TestCategory("Persistence")] 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")] 1009 970 [TestProperty("Time", "short")] 1010 971 public void TestStorableClassDiscoveryAllFields() { 1011 AllFieldsStorable afs = new AllFieldsStorable( false);1012 XmlGenerator.Serialize(afs, tempFile);1013 AllFieldsStorable newAfs = (AllFieldsStorable) XmlParser.Deserialize(tempFile);972 AllFieldsStorable afs = new AllFieldsStorable(); 973 new ProtoBufSerializer().Serialize(afs, tempFile); 974 AllFieldsStorable newAfs = (AllFieldsStorable)new ProtoBufSerializer().Deserialize(tempFile); 1014 975 Assert.AreEqual(afs.Value1, newAfs.Value1); 1015 976 Assert.AreEqual(afs.Value2, newAfs.Value2); … … 1018 979 } 1019 980 1020 [Storable Class(StorableClassType.AllProperties)]981 [StorableType(StorableMemberSelection.AllProperties, "60EE99CA-B391-4211-9FFB-2677490B33B6")] 1021 982 public class AllPropertiesStorable { 1022 983 public int Value1 = 1; … … 1026 987 public int Value4 { get; private set; } 1027 988 [StorableConstructor] 1028 public AllPropertiesStorable(bool isDeserializing) { 1029 if (!isDeserializing) { 1030 Value1 = 12; 1031 Value2 = 23; 1032 Value3 = 34; 1033 Value4 = 56; 1034 } 1035 } 1036 } 1037 1038 [TestMethod] 1039 [TestCategory("Persistence")] 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")] 1040 1000 [TestProperty("Time", "short")] 1041 1001 public void TestStorableClassDiscoveryAllProperties() { 1042 AllPropertiesStorable afs = new AllPropertiesStorable( false);1043 XmlGenerator.Serialize(afs, tempFile);1044 AllPropertiesStorable newAfs = (AllPropertiesStorable) XmlParser.Deserialize(tempFile);1002 AllPropertiesStorable afs = new AllPropertiesStorable(); 1003 new ProtoBufSerializer().Serialize(afs, tempFile); 1004 AllPropertiesStorable newAfs = (AllPropertiesStorable)new ProtoBufSerializer().Deserialize(tempFile); 1045 1005 Assert.AreEqual(1, newAfs.Value1); 1046 1006 Assert.AreEqual(2, newAfs.Value2); … … 1050 1010 } 1051 1011 1052 [Storable Class(StorableClassType.AllFieldsAndAllProperties)]1012 [StorableType(StorableMemberSelection.AllFieldsAndAllProperties, "97FAFC16-EC58-44CC-A833-CB951C0DD23B")] 1053 1013 public class AllFieldsAndAllPropertiesStorable { 1054 1014 public int Value1 = 1; … … 1058 1018 public int Value4 { get; private set; } 1059 1019 [StorableConstructor] 1060 public AllFieldsAndAllPropertiesStorable(bool isDeserializing) { 1061 if (!isDeserializing) { 1062 Value1 = 12; 1063 Value2 = 23; 1064 Value3 = 34; 1065 Value4 = 56; 1066 } 1067 } 1068 } 1069 1070 [TestMethod] 1071 [TestCategory("Persistence")] 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")] 1072 1031 [TestProperty("Time", "short")] 1073 1032 public void TestStorableClassDiscoveryAllFieldsAndAllProperties() { 1074 AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable( false);1075 XmlGenerator.Serialize(afs, tempFile);1076 AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable) XmlParser.Deserialize(tempFile);1033 AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable(); 1034 new ProtoBufSerializer().Serialize(afs, tempFile); 1035 AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)new ProtoBufSerializer().Deserialize(tempFile); 1077 1036 Assert.AreEqual(afs.Value1, newAfs.Value1); 1078 1037 Assert.AreEqual(afs.Value2, newAfs.Value2); … … 1081 1040 } 1082 1041 1083 [Storable Class(StorableClassType.MarkedOnly)]1042 [StorableType("74BDE240-59D5-48C9-9A2A-5D44750DAF78")] 1084 1043 public class MarkedOnlyStorable { 1085 1044 public int Value1 = 1; … … 1089 1048 public int Value4 { get; private set; } 1090 1049 [StorableConstructor] 1091 public MarkedOnlyStorable(bool isDeserializing) { 1092 if (!isDeserializing) { 1093 Value1 = 12; 1094 Value2 = 23; 1095 Value3 = 34; 1096 Value4 = 56; 1097 } 1098 } 1099 } 1100 1101 [TestMethod] 1102 [TestCategory("Persistence")] 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")] 1103 1061 [TestProperty("Time", "short")] 1104 1062 public void TestStorableClassDiscoveryMarkedOnly() { 1105 MarkedOnlyStorable afs = new MarkedOnlyStorable( false);1106 XmlGenerator.Serialize(afs, tempFile);1107 MarkedOnlyStorable newAfs = (MarkedOnlyStorable) XmlParser.Deserialize(tempFile);1063 MarkedOnlyStorable afs = new MarkedOnlyStorable(); 1064 new ProtoBufSerializer().Serialize(afs, tempFile); 1065 MarkedOnlyStorable newAfs = (MarkedOnlyStorable)new ProtoBufSerializer().Deserialize(tempFile); 1108 1066 Assert.AreEqual(1, newAfs.Value1); 1109 1067 Assert.AreEqual(afs.Value2, newAfs.Value2); … … 1113 1071 1114 1072 [TestMethod] 1115 [TestCategory("Persistence ")]1073 [TestCategory("Persistence.Fossil")] 1116 1074 [TestProperty("Time", "short")] 1117 1075 public void TestLineEndings() { … … 1120 1078 foreach (var br in lineBreaks) 1121 1079 lines.Add("line1" + br + "line2"); 1122 XmlGenerator.Serialize(lines, tempFile);1123 List<string> newLines = XmlParser.Deserialize<List<string>>(tempFile);1080 new ProtoBufSerializer().Serialize(lines, tempFile); 1081 List<string> newLines = (List<string>)new ProtoBufSerializer().Deserialize(tempFile); 1124 1082 Assert.AreEqual(lines.Count, newLines.Count); 1125 1083 for (int i = 0; i < lineBreaks.Count; i++) { … … 1129 1087 1130 1088 [TestMethod] 1131 [TestCategory("Persistence ")]1089 [TestCategory("Persistence.Fossil")] 1132 1090 [TestProperty("Time", "short")] 1133 1091 public void TestSpecialNumbers() { … … 1136 1094 Assert.IsTrue(double.IsNegativeInfinity(specials[1])); 1137 1095 Assert.IsTrue(double.IsNaN(specials[2])); 1138 XmlGenerator.Serialize(specials, tempFile);1139 List<double> newSpecials = XmlParser.Deserialize<List<double>>(tempFile);1096 new ProtoBufSerializer().Serialize(specials, tempFile); 1097 List<double> newSpecials = (List<double>)new ProtoBufSerializer().Deserialize(tempFile); 1140 1098 Assert.IsTrue(double.IsPositiveInfinity(newSpecials[0])); 1141 1099 Assert.IsTrue(double.IsNegativeInfinity(newSpecials[1])); … … 1144 1102 1145 1103 [TestMethod] 1146 [TestCategory("Persistence ")]1104 [TestCategory("Persistence.Fossil")] 1147 1105 [TestProperty("Time", "short")] 1148 1106 public void TestStringSplit() { … … 1156 1114 1157 1115 [TestMethod] 1158 [TestCategory("Persistence ")]1116 [TestCategory("Persistence.Fossil")] 1159 1117 [TestProperty("Time", "medium")] 1160 1118 public void TestCompactNumberArraySerializer() { … … 1163 1121 for (int i = 0; i < a.Length; i++) 1164 1122 a[i] = r.Next(10); 1165 var config = ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()); 1166 config = new Configuration(config.Format, 1167 config.PrimitiveSerializers.Where(s => s.SourceType != typeof(double[])), 1168 config.CompositeSerializers); 1169 XmlGenerator.Serialize(a, tempFile, config); 1170 double[] newA = XmlParser.Deserialize<double[]>(tempFile); 1123 new ProtoBufSerializer().Serialize(a, tempFile); 1124 double[] newA = (double[])new ProtoBufSerializer().Deserialize(tempFile); 1171 1125 Assert.AreEqual(a.Length, newA.Length); 1172 1126 for (int i = 0; i < a.Rank; i++) { … … 1178 1132 } 1179 1133 } 1134 [StorableType("A174C85C-3B7C-477D-9E6C-121301470DDE")] 1180 1135 private class IdentityComparer<T> : IEqualityComparer<T> { 1181 1136 … … 1187 1142 return obj.GetHashCode(); 1188 1143 } 1189 } 1190 1191 [TestMethod] 1192 [TestCategory("Persistence")] 1144 1145 [StorableConstructor] 1146 protected IdentityComparer(StorableConstructorFlag _) { 1147 } 1148 public IdentityComparer() { 1149 } 1150 } 1151 1152 [TestMethod] 1153 [TestCategory("Persistence.Fossil")] 1193 1154 [TestProperty("Time", "short")] 1194 1155 public void TestHashSetSerializer() { … … 1197 1158 new HashSet<int>(new[] { 4, 5, 6 }, new IdentityComparer<int>()), 1198 1159 }; 1199 XmlGenerator.Serialize(hashSets, tempFile);1200 var newHashSets = XmlParser.Deserialize<List<HashSet<int>>>(tempFile);1160 new ProtoBufSerializer().Serialize(hashSets, tempFile); 1161 var newHashSets = (List<HashSet<int>>)new ProtoBufSerializer().Deserialize(tempFile); 1201 1162 Assert.IsTrue(newHashSets[0].Contains(1)); 1202 1163 Assert.IsTrue(newHashSets[0].Contains(2)); … … 1210 1171 1211 1172 [TestMethod] 1212 [TestCategory("Persistence ")]1173 [TestCategory("Persistence.Fossil")] 1213 1174 [TestProperty("Time", "short")] 1214 1175 public void TestConcreteDictionarySerializer() { … … 1223 1184 dictionaries[1].Add(5, 5); 1224 1185 dictionaries[1].Add(6, 6); 1225 XmlGenerator.Serialize(dictionaries, tempFile, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));1226 var newDictionaries = XmlParser.Deserialize<List<Dictionary<int, int>>>(tempFile);1186 new ProtoBufSerializer().Serialize(dictionaries, tempFile); 1187 var newDictionaries = (List<Dictionary<int, int>>)new ProtoBufSerializer().Deserialize(tempFile); 1227 1188 Assert.IsTrue(newDictionaries[0].ContainsKey(1)); 1228 1189 Assert.IsTrue(newDictionaries[0].ContainsKey(2)); … … 1241 1202 } 1242 1203 1243 [Storable Class]1204 [StorableType("A5DAC970-4E03-4B69-A95A-9DAC683D051F")] 1244 1205 public class ReadOnlyFail { 1245 1206 [Storable] … … 1247 1208 get { return "fail"; } 1248 1209 } 1249 } 1250 1251 [TestMethod] 1252 [TestCategory("Persistence")] 1210 1211 [StorableConstructor] 1212 protected ReadOnlyFail(StorableConstructorFlag _) { 1213 } 1214 public ReadOnlyFail() { 1215 } 1216 } 1217 1218 [TestMethod] 1219 [TestCategory("Persistence.Fossil")] 1253 1220 [TestProperty("Time", "short")] 1254 1221 public void TestReadOnlyFail() { 1255 1222 try { 1256 XmlGenerator.Serialize(new ReadOnlyFail(), tempFile);1223 new ProtoBufSerializer().Serialize(new ReadOnlyFail(), tempFile); 1257 1224 Assert.Fail("Exception expected"); 1258 1225 } catch (PersistenceException) { … … 1263 1230 1264 1231 1265 [Storable Class]1232 [StorableType("653EBC18-E461-4F5C-8FD6-9F588AAC70D9")] 1266 1233 public class WriteOnlyFail { 1267 1234 [Storable] … … 1269 1236 set { throw new InvalidOperationException("this property should never be set."); } 1270 1237 } 1271 } 1272 1273 [TestMethod] 1274 [TestCategory("Persistence")] 1238 1239 [StorableConstructor] 1240 protected WriteOnlyFail(StorableConstructorFlag _) { 1241 } 1242 public WriteOnlyFail() { 1243 } 1244 } 1245 1246 [TestMethod] 1247 [TestCategory("Persistence.Fossil")] 1275 1248 [TestProperty("Time", "short")] 1276 1249 public void TestWriteOnlyFail() { 1277 1250 try { 1278 XmlGenerator.Serialize(new WriteOnlyFail(), tempFile);1251 new ProtoBufSerializer().Serialize(new WriteOnlyFail(), tempFile); 1279 1252 Assert.Fail("Exception expected"); 1280 1253 } catch (PersistenceException) { … … 1284 1257 } 1285 1258 1286 [Storable Class]1259 [StorableType("67BEAF29-9D7C-4C82-BD9F-9957798D6A2D")] 1287 1260 public class OneWayTest { 1261 [StorableConstructor] 1262 protected OneWayTest(StorableConstructorFlag _) { 1263 } 1264 1288 1265 public OneWayTest() { this.value = "default"; } 1289 1266 public string value; … … 1299 1276 1300 1277 [TestMethod] 1301 [TestCategory("Persistence")] 1302 [TestProperty("Time", "short")] 1303 public void TestOneWaySerialization() { 1304 var test = new OneWayTest(); 1305 var serializer = new Serializer(test, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 1306 var it = serializer.GetEnumerator(); 1307 it.MoveNext(); 1308 Assert.AreEqual("ROOT", ((BeginToken)it.Current).Name); it.MoveNext(); 1309 Assert.AreEqual("ReadOnly", ((PrimitiveToken)it.Current).Name); it.MoveNext(); 1310 Assert.AreEqual("ROOT", ((EndToken)it.Current).Name); it.MoveNext(); 1311 var deserializer = new Deserializer(new[] { 1312 new TypeMapping(0, typeof(OneWayTest).AssemblyQualifiedName, typeof(StorableSerializer).AssemblyQualifiedName), 1313 new TypeMapping(1, typeof(string).AssemblyQualifiedName, typeof(String2XmlSerializer).AssemblyQualifiedName) }); 1314 var newTest = (OneWayTest)deserializer.Deserialize(new ISerializationToken[] { 1315 new BeginToken("ROOT", 0, 0), 1316 new PrimitiveToken("WriteOnly", 1, 1, new XmlString("<![CDATA[serial data]]>")), 1317 new EndToken("ROOT", 0, 0) 1318 }); 1319 Assert.AreEqual("serial data", newTest.value); 1320 } 1321 1322 [TestMethod] 1323 [TestCategory("Persistence")] 1324 [TestProperty("Time", "short")] 1325 public void TestTypeCacheExport() { 1326 var test = new List<List<int>>(); 1327 test.Add(new List<int>() { 1, 2, 3 }); 1328 IEnumerable<Type> types; 1329 using (var stream = new MemoryStream()) { 1330 XmlGenerator.Serialize(test, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types); 1331 } 1332 List<Type> t = new List<Type>(types); 1333 // Assert.IsTrue(t.Contains(typeof(int))); not serialized as an int list is directly transformed into a string 1334 Assert.IsTrue(t.Contains(typeof(List<int>))); 1335 Assert.IsTrue(t.Contains(typeof(List<List<int>>))); 1336 Assert.AreEqual(t.Count, 2); 1337 } 1338 1339 [TestMethod] 1340 [TestCategory("Persistence")] 1278 [TestCategory("Persistence.Fossil")] 1341 1279 [TestProperty("Time", "short")] 1342 1280 public void TupleTest() { … … 1346 1284 var t4 = Tuple.Create(Tuple.Create(1, 2, 3), Tuple.Create(4, 5, 6), Tuple.Create(8, 9, 10)); 1347 1285 var tuple = Tuple.Create(t1, t2, t3, t4); 1348 XmlGenerator.Serialize(tuple, tempFile);1349 var newTuple = XmlParser.Deserialize<Tuple<Tuple<int>, Tuple<char, string>, Tuple<double, float, int>, Tuple<Tuple<int, int, int>, Tuple<int, int, int>, Tuple<int, int, int>>>>(tempFile);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); 1350 1288 Assert.AreEqual(tuple, newTuple); 1351 1289 } 1352 1290 1353 1291 [TestMethod] 1354 [TestCategory("Persistence ")]1292 [TestCategory("Persistence.Fossil")] 1355 1293 [TestProperty("Time", "short")] 1356 1294 public void FontTest() { … … 1361 1299 new Font("Helvetica", 21, FontStyle.Strikeout, GraphicsUnit.Inch, 0, true), 1362 1300 }; 1363 XmlGenerator.Serialize(fonts, tempFile);1364 var newFonts = XmlParser.Deserialize<List<Font>>(tempFile);1301 new ProtoBufSerializer().Serialize(fonts, tempFile); 1302 var newFonts = (List<Font>)new ProtoBufSerializer().Deserialize(tempFile); 1365 1303 Assert.AreEqual(fonts[0], newFonts[0]); 1366 1304 Assert.AreEqual(fonts[1], newFonts[1]); … … 1370 1308 1371 1309 [TestMethod] 1372 [TestCategory("Persistence ")]1310 [TestCategory("Persistence.Fossil")] 1373 1311 [TestProperty("Time", "medium")] 1374 1312 public void ConcurrencyTest() { … … 1379 1317 byte[] data; 1380 1318 using (var stream = new MemoryStream()) { 1381 XmlGenerator.Serialize(new GeneticAlgorithm(), stream);1319 new ProtoBufSerializer().Serialize(new GeneticAlgorithm(), stream); 1382 1320 data = stream.ToArray(); 1383 1321 } … … 1388 1326 1389 1327 [TestMethod] 1390 [TestCategory("Persistence ")]1328 [TestCategory("Persistence.Fossil")] 1391 1329 [TestProperty("Time", "medium")] 1392 1330 public void ConcurrentBitmapTest() { … … 1403 1341 tasks[i] = Task.Factory.StartNew((idx) => { 1404 1342 using (var stream = new MemoryStream()) { 1405 XmlGenerator.Serialize(b, stream);1343 new ProtoBufSerializer().Serialize(b, stream); 1406 1344 datas[(int)idx] = stream.ToArray(); 1407 1345 } … … 1411 1349 } 1412 1350 1351 [StorableType("6923FC3A-AC33-4CA9-919F-9707C00A663B")] 1413 1352 public class G<T, T2> { 1353 [StorableType("16B88964-ECB3-4B41-95BC-EE3BE908CE4A")] 1414 1354 public class S { } 1355 [StorableType("23CC1C7C-031E-4CBD-A87A-8F2235803BB4")] 1415 1356 public class S2<T3, T4> { } 1416 1357 } 1417 1358 1418 1359 [TestMethod] 1419 [TestCategory("Persistence ")]1360 [TestCategory("Persistence.Fossil")] 1420 1361 [TestProperty("Time", "short")] 1421 1362 public void TestInternalClassOfGeneric() { … … 1425 1366 "UseCases.G<Int32,Char>.S", 1426 1367 TypeNameParser.Parse(typeName).GetTypeNameInCode(false)); 1427 XmlGenerator.Serialize(s, tempFile);1428 var s1 = XmlParser.Deserialize(tempFile);1429 } 1430 1431 [TestMethod] 1432 [TestCategory("Persistence ")]1368 new ProtoBufSerializer().Serialize(s, tempFile); 1369 var s1 = new ProtoBufSerializer().Deserialize(tempFile); 1370 } 1371 1372 [TestMethod] 1373 [TestCategory("Persistence.Fossil")] 1433 1374 [TestProperty("Time", "short")] 1434 1375 public void TestInternalClassOfGeneric2() { … … 1438 1379 "UseCases.G<Int32,Single>.S2<Int32,Char>", 1439 1380 TypeNameParser.Parse(typeName).GetTypeNameInCode(false)); 1440 XmlGenerator.Serialize(s, tempFile);1441 var s1 = XmlParser.Deserialize(tempFile);1442 } 1443 1444 [TestMethod] 1445 [TestCategory("Persistence ")]1381 new ProtoBufSerializer().Serialize(s, tempFile); 1382 var s1 = new ProtoBufSerializer().Deserialize(tempFile); 1383 } 1384 1385 [TestMethod] 1386 [TestCategory("Persistence.Fossil")] 1446 1387 [TestProperty("Time", "short")] 1447 1388 public void TestSpecialCharacters() { 1448 1389 var s = "abc" + "\x15" + "def"; 1449 XmlGenerator.Serialize(s, tempFile);1450 var newS = XmlParser.Deserialize(tempFile);1390 new ProtoBufSerializer().Serialize(s, tempFile); 1391 var newS = new ProtoBufSerializer().Deserialize(tempFile); 1451 1392 Assert.AreEqual(s, newS); 1452 1393 } 1453 1394 1454 1395 [TestMethod] 1455 [TestCategory("Persistence ")]1396 [TestCategory("Persistence.Fossil")] 1456 1397 [TestProperty("Time", "short")] 1457 1398 public void TestByteArray() { … … 1460 1401 b[1] = 200; 1461 1402 b[2] = byte.MaxValue; 1462 XmlGenerator.Serialize(b, tempFile);1463 var newB = (byte[]) XmlParser.Deserialize(tempFile);1403 new ProtoBufSerializer().Serialize(b, tempFile); 1404 var newB = (byte[])new ProtoBufSerializer().Deserialize(tempFile); 1464 1405 CollectionAssert.AreEqual(b, newB); 1465 1406 } 1466 1407 1467 1408 [TestMethod] 1468 [TestCategory("Persistence ")]1409 [TestCategory("Persistence.Fossil")] 1469 1410 [TestProperty("Time", "short")] 1470 1411 public void TestOptionalNumberEnumerable() { 1471 var values = new List<double?> { 0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1};1472 XmlGenerator.Serialize(values, tempFile);1473 var newValues = (List<double?>) XmlParser.Deserialize(tempFile);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); 1474 1415 CollectionAssert.AreEqual(values, newValues); 1475 1416 } 1476 1417 1477 1418 [TestMethod] 1478 [TestCategory("Persistence ")]1419 [TestCategory("Persistence.Fossil")] 1479 1420 [TestProperty("Time", "short")] 1480 1421 public void TestOptionalDateTimeEnumerable() { 1481 1422 var values = new List<DateTime?> { DateTime.MinValue, null, DateTime.Now, DateTime.Now.Add(TimeSpan.FromDays(1)), 1482 1423 DateTime.ParseExact("10.09.2014 12:21", "dd.MM.yyyy hh:mm", CultureInfo.InvariantCulture), DateTime.MaxValue}; 1483 XmlGenerator.Serialize(values, tempFile);1484 var newValues = (List<DateTime?>) XmlParser.Deserialize(tempFile);1424 new ProtoBufSerializer().Serialize(values, tempFile); 1425 var newValues = (List<DateTime?>)new ProtoBufSerializer().Deserialize(tempFile); 1485 1426 CollectionAssert.AreEqual(values, newValues); 1486 1427 } 1487 1428 1488 1429 [TestMethod] 1489 [TestCategory("Persistence ")]1430 [TestCategory("Persistence.Fossil")] 1490 1431 [TestProperty("Time", "short")] 1491 1432 public void TestStringEnumerable() { 1492 var values = new List<string> { "", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated"};1493 XmlGenerator.Serialize(values, tempFile);1494 var newValues = (List<String>) XmlParser.Deserialize(tempFile);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); 1495 1436 CollectionAssert.AreEqual(values, newValues); 1496 1437 } 1497 1438 1498 1439 [TestMethod] 1499 [TestCategory("Persistence ")]1440 [TestCategory("Persistence.Fossil")] 1500 1441 [TestProperty("Time", "short")] 1501 1442 public void TestUnicodeCharArray() { 1502 var s = Encoding.UTF8.GetChars(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb});1503 XmlGenerator.Serialize(s, tempFile);1504 var newS = (char[]) XmlParser.Deserialize(tempFile);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); 1505 1446 CollectionAssert.AreEqual(s, newS); 1506 1447 } 1507 1448 1508 1449 [TestMethod] 1509 [TestCategory("Persistence ")]1450 [TestCategory("Persistence.Fossil")] 1510 1451 [TestProperty("Time", "short")] 1511 1452 public void TestUnicode() { 1512 var s = Encoding.UTF8.GetString(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb});1513 XmlGenerator.Serialize(s, tempFile);1514 var newS = XmlParser.Deserialize(tempFile);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); 1515 1456 Assert.AreEqual(s, newS); 1516 1457 } 1517 1458 1518 1459 [TestMethod] 1519 [TestCategory("Persistence ")]1460 [TestCategory("Persistence.Fossil")] 1520 1461 [TestProperty("Time", "short")] 1521 1462 public void TestQueue() { 1522 var q = new Queue<int>(new[] { 1, 2, 3, 4, 0});1523 XmlGenerator.Serialize(q, tempFile);1524 var newQ = (Queue<int>) XmlParser.Deserialize(tempFile);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); 1525 1466 CollectionAssert.AreEqual(q, newQ); 1526 1467 }
Note: See TracChangeset
for help on using the changeset viewer.