Changeset 15857 for branches/PersistenceReintegration/HeuristicLab.Tests
- Timestamp:
- 03/23/18 14:38:14 (6 years ago)
- Location:
- branches/PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs
r15018 r15857 36 36 using HeuristicLab.Persistence.Core.Tokens; 37 37 using HeuristicLab.Persistence.Default.CompositeSerializers; 38 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 38 39 using HeuristicLab.Persistence.Default.DebugString; 39 40 using HeuristicLab.Persistence.Default.Xml; … … 42 43 using HeuristicLab.Tests; 43 44 using Microsoft.VisualStudio.TestTools.UnitTesting; 44 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;45 45 46 46 namespace HeuristicLab.Persistence.Tests { … … 1030 1030 public int Value3 { get; private set; } 1031 1031 public int Value4 { get; private set; } 1032 1032 1033 [StorableConstructor] 1033 1034 public AllPropertiesStorable(bool isDeserializing) { -
branches/PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs
r15529 r15857 285 285 public int y { get; set; } 286 286 } 287 288 287 #endregion 289 288 … … 293 292 #region Helpers 294 293 private string tempFile; 294 private static Dictionary<Guid, Type> guid2Type; 295 private static Dictionary<Type, Guid> type2Guid; 296 private static Dictionary<Type, Persistence.TypeInfo> typeInfos; 297 private static PropertyInfo guidPropertyInfo = typeof(StorableTypeAttribute).GetProperty("Guid"); 298 295 299 296 300 [ClassInitialize] 297 301 public static void Initialize(TestContext testContext) { 298 302 ConfigurationService.Instance.Reset(); 303 304 var guid2TypeFieldInfo = typeof(StaticCache).GetField("guid2Type", BindingFlags.NonPublic | BindingFlags.Instance); 305 var type2GuidFieldInfo = typeof(StaticCache).GetField("type2Guid", BindingFlags.NonPublic | BindingFlags.Instance); 306 var typeInfosFieldInfo = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance); 307 308 guid2Type = (Dictionary<Guid, Type>)guid2TypeFieldInfo.GetValue(Mapper.StaticCache); 309 type2Guid = (Dictionary<Type, Guid>)type2GuidFieldInfo.GetValue(Mapper.StaticCache); 310 typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosFieldInfo.GetValue(Mapper.StaticCache); 299 311 } 300 312 … … 310 322 reader.Close(); 311 323 File.Delete(tempFile); 324 } 325 326 public static void RegisterType(Guid guid, Type type) { 327 Mapper.StaticCache.RegisterType(guid, type); 328 } 329 330 public static void DeregisterType(Type type) { 331 var typeInfo = GetTypeInfo(type); 332 type2Guid.Remove(guid2Type[typeInfo.StorableTypeAttribute.Guid]); 333 guid2Type.Remove(typeInfo.StorableTypeAttribute.Guid); 334 } 335 336 public static Persistence.TypeInfo GetTypeInfo(Type type) { 337 return Mapper.StaticCache.GetTypeInfo(type); 338 } 339 340 public static void RemoveTypeInfo(Type type) { 341 typeInfos.Remove(typeof(ConversionA)); 342 } 343 344 public static Guid GetTypeGuid(Type type) { 345 var typeInfo = GetTypeInfo(type); 346 return typeInfo.StorableTypeAttribute.Guid; 347 } 348 349 public static void SetTypeGuid(Type type, Guid guid) { 350 var typeInfo = GetTypeInfo(type); 351 guidPropertyInfo.SetValue(typeInfo.StorableTypeAttribute, guid); 312 352 } 313 353 #endregion … … 455 495 #endregion 456 496 457 #region Persistence 4.0 test methods458 [TestMethod] 459 [TestCategory("Persistence 4")]497 #region Persistence 4.0 Test methods 498 [TestMethod] 499 [TestCategory("PersistenceNew")] 460 500 [TestProperty("Time", "short")] 461 501 public void TestBool() { … … 472 512 473 513 [TestMethod] 474 [TestCategory("Persistence 4")]514 [TestCategory("PersistenceNew")] 475 515 [TestProperty("Time", "short")] 476 516 public void TestInt() { … … 487 527 488 528 [TestMethod] 489 [TestCategory("Persistence 4")]529 [TestCategory("PersistenceNew")] 490 530 [TestProperty("Time", "short")] 491 531 public void TestDouble() { … … 503 543 504 544 [TestMethod] 505 [TestCategory("Persistence 4")]545 [TestCategory("PersistenceNew")] 506 546 [TestProperty("Time", "short")] 507 547 public void TestFloat() { … … 519 559 520 560 [TestMethod] 521 [TestCategory("Persistence 4")]561 [TestCategory("PersistenceNew")] 522 562 [TestProperty("Time", "short")] 523 563 public void TestDecimal() { … … 535 575 536 576 [TestMethod] 537 [TestCategory("Persistence 4")]577 [TestCategory("PersistenceNew")] 538 578 [TestProperty("Time", "short")] 539 579 public void TestLong() { … … 551 591 552 592 [TestMethod] 553 [TestCategory("Persistence 4")]593 [TestCategory("PersistenceNew")] 554 594 [TestProperty("Time", "short")] 555 595 public void TestUInt() { … … 567 607 568 608 [TestMethod] 569 [TestCategory("Persistence 4")]609 [TestCategory("PersistenceNew")] 570 610 [TestProperty("Time", "short")] 571 611 public void TestShort() { … … 583 623 584 624 [TestMethod] 585 [TestCategory("Persistence 4")]625 [TestCategory("PersistenceNew")] 586 626 [TestProperty("Time", "short")] 587 627 public void TestByte() { … … 599 639 600 640 [TestMethod] 601 [TestCategory("Persistence 4")]641 [TestCategory("PersistenceNew")] 602 642 [TestProperty("Time", "short")] 603 643 public void TestEnumSimple() { … … 615 655 616 656 [TestMethod] 617 [TestCategory("Persistence 4")]657 [TestCategory("PersistenceNew")] 618 658 [TestProperty("Time", "short")] 619 659 public void TestEnumComplex() { … … 630 670 631 671 [TestMethod] 632 [TestCategory("Persistence 4")]672 [TestCategory("PersistenceNew")] 633 673 [TestProperty("Time", "short")] 634 674 public void TestType() { … … 645 685 646 686 [TestMethod] 647 [TestCategory("Persistence 4")]687 [TestCategory("PersistenceNew")] 648 688 [TestProperty("Time", "short")] 649 689 public void TestBytes() { … … 661 701 662 702 [TestMethod] 663 [TestCategory("Persistence 4")]703 [TestCategory("PersistenceNew")] 664 704 [TestProperty("Time", "short")] 665 705 public void TestSBytes() { … … 677 717 678 718 [TestMethod] 679 [TestCategory("Persistence 4")]719 [TestCategory("PersistenceNew")] 680 720 [TestProperty("Time", "short")] 681 721 public void TestChars() { … … 693 733 694 734 [TestMethod] 695 [TestCategory("Persistence 4")]735 [TestCategory("PersistenceNew")] 696 736 [TestProperty("Time", "short")] 697 737 public void TestShorts() { … … 709 749 710 750 [TestMethod] 711 [TestCategory("Persistence 4")]751 [TestCategory("PersistenceNew")] 712 752 [TestProperty("Time", "short")] 713 753 public void TestUShorts() { … … 725 765 726 766 [TestMethod] 727 [TestCategory("Persistence 4")]767 [TestCategory("PersistenceNew")] 728 768 [TestProperty("Time", "short")] 729 769 public void TestString() { … … 740 780 741 781 [TestMethod] 742 [TestCategory("Persistence 4")]782 [TestCategory("PersistenceNew")] 743 783 [TestProperty("Time", "short")] 744 784 public void TestColor() { … … 755 795 756 796 [TestMethod] 757 [TestCategory("Persistence 4")]797 [TestCategory("PersistenceNew")] 758 798 [TestProperty("Time", "short")] 759 799 public void TestPoint() { … … 771 811 772 812 [TestMethod] 773 [TestCategory("Persistence 4")]813 [TestCategory("PersistenceNew")] 774 814 [TestProperty("Time", "short")] 775 815 public void TestBoolArray() { … … 788 828 789 829 [TestMethod] 790 [TestCategory("Persistence 4")]830 [TestCategory("PersistenceNew")] 791 831 [TestProperty("Time", "short")] 792 832 public void TestIntArray() { … … 805 845 806 846 [TestMethod] 807 [TestCategory("Persistence 4")]847 [TestCategory("PersistenceNew")] 808 848 [TestProperty("Time", "short")] 809 849 public void TestLongArray() { … … 822 862 823 863 [TestMethod] 824 [TestCategory("Persistence 4")]864 [TestCategory("PersistenceNew")] 825 865 [TestProperty("Time", "short")] 826 866 public void TestDoubleArray() { … … 839 879 840 880 [TestMethod] 841 [TestCategory("Persistence 4")]881 [TestCategory("PersistenceNew")] 842 882 [TestProperty("Time", "short")] 843 883 public void TestObjectArray() { … … 863 903 864 904 [TestMethod] 865 [TestCategory("Persistence 4")]905 [TestCategory("PersistenceNew")] 866 906 [TestProperty("Time", "short")] 867 907 public void TestStack() { … … 883 923 884 924 [TestMethod] 885 [TestCategory("Persistence 4")]925 [TestCategory("PersistenceNew")] 886 926 [TestProperty("Time", "short")] 887 927 public void TestArrayOfStack() { … … 915 955 916 956 [TestMethod] 917 [TestCategory("Persistence 4")]957 [TestCategory("PersistenceNew")] 918 958 [TestProperty("Time", "short")] 919 959 public void TestIntValueArray() { … … 932 972 933 973 [TestMethod] 934 [TestCategory("Persistence 4")]974 [TestCategory("PersistenceNew")] 935 975 [TestProperty("Time", "short")] 936 976 public void TestIntValueArrayArray() { … … 949 989 #endregion 950 990 951 952 #region Old persistence test methods 953 [TestMethod] 954 [TestCategory("Persistence4")] 991 #region Old Persistence Tests 992 [TestMethod] 993 [TestCategory("PersistenceNew")] 955 994 [TestProperty("Time", "short")] 956 995 public void ComplexStorable() { … … 1042 1081 1043 1082 [TestMethod] 1044 [TestCategory("Persistence 4")]1083 [TestCategory("PersistenceNew")] 1045 1084 [TestProperty("Time", "short")] 1046 1085 public void SelfReferences() { … … 1070 1109 1071 1110 [TestMethod] 1072 [TestCategory("Persistence 4")]1111 [TestCategory("PersistenceNew")] 1073 1112 [TestProperty("Time", "short")] 1074 1113 public void ArrayCreation() { … … 1083 1122 arrayListArray[2].Add(arrayListArray); 1084 1123 arrayListArray[2].Add(arrayListArray); 1085 //Array a = Array.CreateInstance(1086 //typeof(object),1087 //new[] { 1, 2 }, new[] { 3, 4 });1088 //arrayListArray[2].Add(a);1124 Array a = Array.CreateInstance( 1125 typeof(object), 1126 new[] { 1, 2 }, new[] { 3, 4 }); 1127 arrayListArray[2].Add(a); 1089 1128 serializer.Serialize(arrayListArray, tempFile); 1090 1129 object o = serializer.Deserialize(tempFile); … … 1100 1139 1101 1140 [TestMethod] 1102 [TestCategory("Persistence 4")]1141 [TestCategory("PersistenceNew")] 1103 1142 [TestProperty("Time", "short")] 1104 1143 public void CustomSerializationProperty() { … … 1117 1156 1118 1157 [TestMethod] 1119 [TestCategory("Persistence 4")]1158 [TestCategory("PersistenceNew")] 1120 1159 [TestProperty("Time", "short")] 1121 1160 public void Primitives() { … … 1130 1169 1131 1170 [TestMethod] 1132 [TestCategory("Persistence 4")]1171 [TestCategory("PersistenceNew")] 1133 1172 [TestProperty("Time", "short")] 1134 1173 public void MultiDimensionalArray() { … … 1161 1200 1162 1201 [TestMethod] 1163 [TestCategory("Persistence 4")]1202 [TestCategory("PersistenceNew")] 1164 1203 [TestProperty("Time", "short")] 1165 1204 public void NestedTypeTest() { … … 1176 1215 1177 1216 [TestMethod] 1178 [TestCategory("Persistence 4")]1217 [TestCategory("PersistenceNew")] 1179 1218 [TestProperty("Time", "short")] 1180 1219 public void SimpleArray() { … … 1189 1228 1190 1229 [TestMethod] 1191 [TestCategory("Persistence 4")]1230 [TestCategory("PersistenceNew")] 1192 1231 [TestProperty("Time", "short")] 1193 1232 public void PrimitiveRoot() { … … 1244 1283 1245 1284 [TestMethod] 1246 [TestCategory("Persistence 4")]1285 [TestCategory("PersistenceNew")] 1247 1286 [TestProperty("Time", "short")] 1248 1287 public void Enums() { … … 1260 1299 1261 1300 [TestMethod] 1262 [TestCategory("Persistence 4")]1301 [TestCategory("PersistenceNew")] 1263 1302 [TestProperty("Time", "short")] 1264 1303 public void TestAliasingWithOverriddenEquals() { … … 1278 1317 1279 1318 [TestMethod] 1280 [TestCategory("Persistence 4")]1319 [TestCategory("PersistenceNew")] 1281 1320 [TestProperty("Time", "short")] 1282 1321 public void NonDefaultConstructorTest() { … … 1291 1330 1292 1331 [TestMethod] 1293 [TestCategory("Persistence 4")]1332 [TestCategory("PersistenceNew")] 1294 1333 [TestProperty("Time", "short")] 1295 1334 public void TestSavingException() { … … 1308 1347 1309 1348 [TestMethod] 1310 [TestCategory("Persistence 4")]1349 [TestCategory("PersistenceNew")] 1311 1350 [TestProperty("Time", "short")] 1312 1351 public void TestTypeStringConversion() { … … 1320 1359 1321 1360 [TestMethod] 1322 [TestCategory("Persistence 4")]1361 [TestCategory("PersistenceNew")] 1323 1362 [TestProperty("Time", "short")] 1324 1363 public void TestHexadecimalPublicKeyToken() { … … 1330 1369 1331 1370 [TestMethod] 1332 [TestCategory("Persistence 4")]1371 [TestCategory("PersistenceNew")] 1333 1372 [TestProperty("Time", "short")] 1334 1373 public void InheritanceTest() { … … 1360 1399 1361 1400 [TestMethod] 1362 [TestCategory("Persistence 4")]1401 [TestCategory("PersistenceNew")] 1363 1402 [TestProperty("Time", "short")] 1364 1403 public void InstantiateParentChainReference() { … … 1378 1417 int value; 1379 1418 int PropertyValue { get; set; } 1380 1381 /*1382 [StorableConstructor]1383 public TestStruct(StorableConstructorFlag deserializing) {1384 value = 0;1385 PropertyValue = 0;1386 }1387 */1388 1389 1419 public TestStruct(int value) 1390 1420 : this() { … … 1395 1425 1396 1426 [TestMethod] 1397 [TestCategory("Persistence 4")]1427 [TestCategory("PersistenceNew")] 1398 1428 [TestProperty("Time", "short")] 1399 1429 public void StructTest() { … … 1406 1436 1407 1437 [TestMethod] 1408 [TestCategory("Persistence 4")]1438 [TestCategory("PersistenceNew")] 1409 1439 [TestProperty("Time", "short")] 1410 1440 public void PointTest() { … … 1417 1447 1418 1448 [TestMethod] 1419 [TestCategory("Persistence 4")]1449 [TestCategory("PersistenceNew")] 1420 1450 [TestProperty("Time", "short")] 1421 1451 public void NullableValueTypes() { … … 1431 1461 1432 1462 [TestMethod] 1433 [TestCategory("Persistence 4")]1463 [TestCategory("PersistenceNew")] 1434 1464 [TestProperty("Time", "short")] 1435 1465 public void BitmapTest() { … … 1465 1495 1466 1496 [TestMethod] 1467 [TestCategory("Persistence 4")]1497 [TestCategory("PersistenceNew")] 1468 1498 [TestProperty("Time", "short")] 1469 1499 public void HookTest() { … … 1491 1521 } 1492 1522 [StorableConstructor] 1493 private CustomConstructor(StorableConstructorFlag deserializing) {1523 private CustomConstructor(StorableConstructorFlag _) { 1494 1524 Value = "persistence"; 1495 1525 } … … 1497 1527 1498 1528 [TestMethod] 1499 [TestCategory("Persistence 4")]1529 [TestCategory("PersistenceNew")] 1500 1530 [TestProperty("Time", "short")] 1501 1531 public void TestCustomConstructor() { … … 1518 1548 1519 1549 [TestMethod] 1520 [TestCategory("Persistence 4")]1550 [TestCategory("PersistenceNew")] 1521 1551 [TestProperty("Time", "short")] 1522 1552 public void TestConstructorExceptionUnwrapping() { … … 1533 1563 1534 1564 [TestMethod] 1535 [TestCategory("Persistence 4")]1565 [TestCategory("PersistenceNew")] 1536 1566 [TestProperty("Time", "short")] 1537 1567 public void TestStreaming() { … … 1570 1600 1571 1601 [TestMethod] 1572 [TestCategory("Persistence 4")]1602 [TestCategory("PersistenceNew")] 1573 1603 [TestProperty("Time", "short")] 1574 1604 public void TestLinkInheritance() { … … 1589 1619 public int Value4 { get; private set; } 1590 1620 [StorableConstructor] 1591 public AllFieldsStorable(StorableConstructorFlag isdeserializing) { 1592 } 1593 1594 public void InitValues() { 1621 private AllFieldsStorable(StorableConstructorFlag _) { } 1622 public AllFieldsStorable() { 1595 1623 Value1 = 12; 1596 1624 Value2 = 23; … … 1601 1629 1602 1630 [TestMethod] 1603 [TestCategory("Persistence 4")]1631 [TestCategory("PersistenceNew")] 1604 1632 [TestProperty("Time", "short")] 1605 1633 public void TestStorableTypeDiscoveryAllFields() { 1606 1634 ProtoBufSerializer serializer = new ProtoBufSerializer(); 1607 AllFieldsStorable afs = new AllFieldsStorable(default(StorableConstructorFlag)); 1608 afs.InitValues(); 1635 AllFieldsStorable afs = new AllFieldsStorable(); 1609 1636 serializer.Serialize(afs, tempFile); 1610 1637 AllFieldsStorable newAfs = (AllFieldsStorable)serializer.Deserialize(tempFile); … … 1623 1650 public int Value4 { get; private set; } 1624 1651 1652 [StorableConstructor] 1653 private AllPropertiesStorable(StorableConstructorFlag _) { } 1625 1654 public AllPropertiesStorable() { 1626 }1627 1628 public void InitValues() {1629 1655 Value1 = 12; 1630 1656 Value2 = 23; … … 1635 1661 1636 1662 [TestMethod] 1637 [TestCategory("Persistence 4")]1663 [TestCategory("PersistenceNew")] 1638 1664 [TestProperty("Time", "short")] 1639 1665 public void TestStorableTypeDiscoveryAllProperties() { 1640 1666 ProtoBufSerializer serializer = new ProtoBufSerializer(); 1641 1667 AllPropertiesStorable afs = new AllPropertiesStorable(); 1642 afs.InitValues();1643 1668 serializer.Serialize(afs, tempFile); 1644 1669 AllPropertiesStorable newAfs = (AllPropertiesStorable)serializer.Deserialize(tempFile); … … 1657 1682 public int Value3 { get; private set; } 1658 1683 public int Value4 { get; private set; } 1659 1684 [StorableConstructor] 1685 private AllFieldsAndAllPropertiesStorable(StorableConstructorFlag _) { } 1660 1686 public AllFieldsAndAllPropertiesStorable() { 1661 }1662 1663 public void InitValues() {1664 1687 Value1 = 12; 1665 1688 Value2 = 23; 1666 1689 Value3 = 34; 1667 1690 Value4 = 56; 1668 1669 } 1670 } 1671 1672 [TestMethod] 1673 [TestCategory("Persistence4")] 1691 } 1692 } 1693 1694 [TestMethod] 1695 [TestCategory("PersistenceNew")] 1674 1696 [TestProperty("Time", "short")] 1675 1697 public void TestStorableTypeDiscoveryAllFieldsAndAllProperties() { 1676 1698 ProtoBufSerializer serializer = new ProtoBufSerializer(); 1677 1699 AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable(); 1678 afs.InitValues();1679 1700 serializer.Serialize(afs, tempFile); 1680 1701 AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)serializer.Deserialize(tempFile); … … 1692 1713 public int Value3 { get; private set; } 1693 1714 public int Value4 { get; private set; } 1715 [StorableConstructor] 1716 private MarkedOnlyStorable(StorableConstructorFlag _) { } 1694 1717 public MarkedOnlyStorable() { 1695 }1696 1697 public void InitValues() {1698 1718 Value1 = 12; 1699 1719 Value2 = 23; … … 1704 1724 1705 1725 [TestMethod] 1706 [TestCategory("Persistence 4")]1726 [TestCategory("PersistenceNew")] 1707 1727 [TestProperty("Time", "short")] 1708 1728 public void TestStorableTypeDiscoveryMarkedOnly() { 1709 1729 ProtoBufSerializer serializer = new ProtoBufSerializer(); 1710 1730 MarkedOnlyStorable afs = new MarkedOnlyStorable(); 1711 afs.InitValues();1712 1731 serializer.Serialize(afs, tempFile); 1713 1732 MarkedOnlyStorable newAfs = (MarkedOnlyStorable)serializer.Deserialize(tempFile); … … 1719 1738 1720 1739 [TestMethod] 1721 [TestCategory("Persistence 4")]1740 [TestCategory("PersistenceNew")] 1722 1741 [TestProperty("Time", "short")] 1723 1742 public void TestLineEndings() { … … 1736 1755 1737 1756 [TestMethod] 1738 [TestCategory("Persistence 4")]1757 [TestCategory("PersistenceNew")] 1739 1758 [TestProperty("Time", "short")] 1740 1759 public void TestSpecialNumbers() { … … 1752 1771 1753 1772 [TestMethod] 1754 [TestCategory("Persistence 4")]1773 [TestCategory("PersistenceNew")] 1755 1774 [TestProperty("Time", "short")] 1756 1775 public void TestStringSplit() { … … 1776 1795 1777 1796 [TestMethod] 1778 [TestCategory("Persistence 4")]1797 [TestCategory("PersistenceNew")] 1779 1798 [TestProperty("Time", "short")] 1780 1799 public void TestHashSetSerializer() { … … 1797 1816 1798 1817 [TestMethod] 1799 [TestCategory("Persistence 4")]1818 [TestCategory("PersistenceNew")] 1800 1819 [TestProperty("Time", "short")] 1801 1820 public void TestConcreteDictionarySerializer() { … … 1838 1857 1839 1858 [TestMethod] 1840 [TestCategory("Persistence 4")]1859 [TestCategory("PersistenceNew")] 1841 1860 [TestProperty("Time", "short")] 1842 1861 public void TestReadOnlyFail() { … … 1861 1880 1862 1881 [TestMethod] 1863 [TestCategory("Persistence 4")]1882 [TestCategory("PersistenceNew")] 1864 1883 [TestProperty("Time", "short")] 1865 1884 public void TestWriteOnlyFail() { … … 1874 1893 } 1875 1894 1876 [StorableType("8052D9E3-6DDD-4AE1-9B5B-67C6D5436512")]1877 public class OneWayTest {1878 public OneWayTest() { this.value = "default"; }1879 public string value;1880 [Storable(AllowOneWay = true)]1881 public string ReadOnly {1882 get { return "ReadOnly"; }1883 1884 [Storable(AllowOneWay = true)]1885 public string WriteOnly {1886 set { this.value = value; }1887 1888 }1889 1890 //TODO 1891 / *[TestMethod]1892 [TestCategory("Persistence4")]1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 }*/1908 1909 [TestMethod] 1910 [TestCategory("Persistence 4")]1895 // TODO 1896 //[StorableType("8052D9E3-6DDD-4AE1-9B5B-67C6D5436512")] 1897 //public class OneWayTest { 1898 // public OneWayTest() { this.value = "default"; } 1899 // public string value; 1900 // [Storable(AllowOneWay = true)] 1901 // public string ReadOnly { 1902 // get { return "ReadOnly"; } 1903 // } 1904 // [Storable(AllowOneWay = true)] 1905 // public string WriteOnly { 1906 // set { this.value = value; } 1907 // } 1908 //} 1909 1910 //[TestMethod] 1911 //[TestCategory("PersistenceNew")] 1912 //[TestProperty("Time", "short")] 1913 //public void TestTypeCacheExport() { 1914 // ProtoBufSerializer serializer = new ProtoBufSerializer(); 1915 // var test = new List<List<int>>(); 1916 // test.Add(new List<int>() { 1, 2, 3 }); 1917 // IEnumerable<Type> types; 1918 // using (var stream = new MemoryStream()) { 1919 // XmlGenerator.Serialize(test, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types); 1920 // } 1921 // List<Type> t = new List<Type>(types); 1922 // // Assert.IsTrue(t.Contains(typeof(int))); not serialized as an int list is directly transformed into a string 1923 // Assert.IsTrue(t.Contains(typeof(List<int>))); 1924 // Assert.IsTrue(t.Contains(typeof(List<List<int>>))); 1925 // Assert.AreEqual(t.Count, 2); 1926 //} 1927 1928 [TestMethod] 1929 [TestCategory("PersistenceNew")] 1911 1930 [TestProperty("Time", "short")] 1912 1931 public void TupleTest() { … … 1922 1941 1923 1942 [TestMethod] 1924 [TestCategory("Persistence 4")]1943 [TestCategory("PersistenceNew")] 1925 1944 [TestProperty("Time", "short")] 1926 1945 public void FontTest() { … … 1941 1960 1942 1961 [TestMethod] 1943 [TestCategory("Persistence 4")]1962 [TestCategory("PersistenceNew")] 1944 1963 [TestProperty("Time", "medium")] 1945 1964 public void ConcurrencyTest() { … … 1960 1979 1961 1980 [TestMethod] 1962 [TestCategory("Persistence 4")]1981 [TestCategory("PersistenceNew")] 1963 1982 [TestProperty("Time", "medium")] 1964 1983 public void ConcurrentBitmapTest() { … … 1992 2011 } 1993 2012 1994 1995 [TestMethod] 1996 [TestCategory("Persistence4")] 2013 [TestMethod] 2014 [TestCategory("PersistenceNew")] 1997 2015 [TestProperty("Time", "short")] 1998 2016 public void TestSpecialCharacters() { … … 2005 2023 2006 2024 [TestMethod] 2007 [TestCategory("Persistence 4")]2025 [TestCategory("PersistenceNew")] 2008 2026 [TestProperty("Time", "short")] 2009 2027 public void TestByteArray() { … … 2019 2037 2020 2038 [TestMethod] 2021 [TestCategory("Persistence 4")]2039 [TestCategory("PersistenceNew")] 2022 2040 [TestProperty("Time", "short")] 2023 2041 public void TestOptionalNumberEnumerable() { … … 2030 2048 2031 2049 [TestMethod] 2032 [TestCategory("Persistence 4")]2050 [TestCategory("PersistenceNew")] 2033 2051 [TestProperty("Time", "short")] 2034 2052 public void TestOptionalDateTimeEnumerable() { … … 2042 2060 2043 2061 [TestMethod] 2044 [TestCategory("Persistence 4")]2062 [TestCategory("PersistenceNew")] 2045 2063 [TestProperty("Time", "short")] 2046 2064 public void TestStringEnumerable() { … … 2053 2071 2054 2072 [TestMethod] 2055 [TestCategory("Persistence 4")]2073 [TestCategory("PersistenceNew")] 2056 2074 [TestProperty("Time", "short")] 2057 2075 public void TestUnicodeCharArray() { … … 2064 2082 2065 2083 [TestMethod] 2066 [TestCategory("Persistence 4")]2084 [TestCategory("PersistenceNew")] 2067 2085 [TestProperty("Time", "short")] 2068 2086 public void TestUnicode() { … … 2075 2093 2076 2094 [TestMethod] 2077 [TestCategory("Persistence 4")]2095 [TestCategory("PersistenceNew")] 2078 2096 [TestProperty("Time", "short")] 2079 2097 public void TestQueue() { … … 2086 2104 #endregion 2087 2105 2106 #region New Persistence Tests 2088 2107 [StorableType("6075F1E8-948A-4AD8-8F5A-942B777852EC")] 2089 2108 public class A { … … 2106 2125 2107 2126 [TestMethod] 2108 [TestCategory("Persistence 4")]2127 [TestCategory("PersistenceNew")] 2109 2128 [TestProperty("Time", "short")] 2110 2129 public void TestCyclicReferencesWithTuple() { … … 2248 2267 2249 2268 [TestMethod] 2250 [TestCategory("Persistence 4")]2269 [TestCategory("PersistenceNew")] 2251 2270 [TestProperty("Time", "short")] 2252 2271 public void TestConversion() { … … 2266 2285 var old = test(); 2267 2286 serializer.Serialize(old, tempFile); 2268 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid); 2269 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V2)).Guid); 2270 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V3)).Guid); 2271 Mapper.StaticCache.RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid, typeof(V3)); 2272 2273 var typeInfosField = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance); 2274 var typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosField.GetValue(Mapper.StaticCache); 2275 2276 var guidPI = typeof(StorableTypeAttribute).GetProperty("Guid"); 2277 var convPI = typeof(Persistence.TypeInfo).GetProperty("ConversionMethods"); 2278 2279 var oldBInfo = typeInfos[typeof(V1)]; 2280 var newBInfo = Mapper.StaticCache.GetTypeInfo(typeof(V3)); 2281 guidPI.SetValue(newBInfo.StorableTypeAttribute, oldBInfo.StorableTypeAttribute.Guid); 2282 //convPI.SetValue(newBInfo, oldBInfo.ConversionMethods); 2283 typeInfos.Remove(typeof(V1)); 2287 2288 DeregisterType(typeof(V1)); 2289 DeregisterType(typeof(V2)); 2290 DeregisterType(typeof(V3)); 2291 2292 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid, typeof(V3)); 2293 SetTypeGuid(typeof(V3), GetTypeGuid(typeof(V1))); 2294 RemoveTypeInfo(typeof(V1)); 2284 2295 2285 2296 object o = serializer.Deserialize(tempFile); … … 2291 2302 Assert.AreSame(restored, restored.mySelf); 2292 2303 Assert.AreEqual(restored.PublicString, old.s); 2293 //string msg = Profile(test);2294 //Console.WriteLine(msg);2295 2304 } 2296 2305 … … 2298 2307 2299 2308 [TestMethod] 2300 [TestCategory("Persistence 4")]2309 [TestCategory("PersistenceNew")] 2301 2310 [TestProperty("Time", "short")] 2302 2311 public void TestGASerializeDeserializeExecute() { … … 2326 2335 2327 2336 [TestMethod] 2328 [TestCategory("Persistence 4")]2337 [TestCategory("PersistenceNew")] 2329 2338 [TestProperty("Time", "short")] 2330 2339 public void TestLoadingSamples() { … … 2413 2422 2414 2423 [TestMethod] 2415 [TestCategory("Persistence 4")]2424 [TestCategory("PersistenceNew")] 2416 2425 [TestProperty("Time", "short")] 2417 2426 public void TestConversionCase1() { … … 2423 2432 var old = test(); 2424 2433 serializer.Serialize(old, tempFile); 2425 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid); 2426 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionBNew)).Guid); 2427 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid); 2428 Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionANew)).Guid); 2429 Mapper.StaticCache.RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid, typeof(ConversionBNew)); 2430 Mapper.StaticCache.RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid, typeof(ConversionANew)); 2431 2432 var typeInfosField = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance); 2433 var typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosField.GetValue(Mapper.StaticCache); 2434 2435 var guidPI = typeof(StorableTypeAttribute).GetProperty("Guid"); 2436 var convPI = typeof(Persistence.TypeInfo).GetProperty("ConversionMethods"); 2437 2438 var oldAInfo = typeInfos[typeof(ConversionA)]; 2439 var newAInfo = Mapper.StaticCache.GetTypeInfo(typeof(ConversionANew)); 2440 guidPI.SetValue(newAInfo.StorableTypeAttribute, oldAInfo.StorableTypeAttribute.Guid); 2441 //convPI.SetValue(newAInfo, oldAInfo.ConversionMethods); 2442 typeInfos.Remove(typeof(ConversionA)); 2443 2444 var oldBInfo = typeInfos[typeof(ConversionB)]; 2445 var newBInfo = Mapper.StaticCache.GetTypeInfo(typeof(ConversionBNew)); 2446 guidPI.SetValue(newBInfo.StorableTypeAttribute, oldBInfo.StorableTypeAttribute.Guid); 2447 //convPI.SetValue(newBInfo, oldBInfo.ConversionMethods); 2448 typeInfos.Remove(typeof(ConversionB)); 2434 2435 DeregisterType(typeof(ConversionB)); 2436 DeregisterType(typeof(ConversionBNew)); 2437 DeregisterType(typeof(ConversionA)); 2438 DeregisterType(typeof(ConversionANew)); 2439 2440 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid, typeof(ConversionANew)); 2441 SetTypeGuid(typeof(ConversionANew), GetTypeGuid(typeof(ConversionA))); 2442 RemoveTypeInfo(typeof(ConversionA)); 2443 2444 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid, typeof(ConversionBNew)); 2445 SetTypeGuid(typeof(ConversionBNew), GetTypeGuid(typeof(ConversionB))); 2446 RemoveTypeInfo(typeof(ConversionB)); 2449 2447 2450 2448 object o = serializer.Deserialize(tempFile); … … 2453 2451 Assert.AreEqual(restored.BaseG, old.BaseF); 2454 2452 } 2453 2454 [StorableType("90470973-4559-428E-AF28-DD95866B0A84")] 2455 private class A0 { 2456 [Storable] 2457 public int x; 2458 } 2459 2460 [StorableType("00000000-0000-0000-0000-0000000000A1", 2)] 2461 private class A1 { 2462 [Storable] 2463 public int y; 2464 } 2465 2466 [StorableType("847DD840-3EE3-4A01-AC60-FD7E71ED05F8")] 2467 private class B0 { 2468 [Storable] 2469 public int x; 2470 } 2471 2472 [StorableType("00000000-0000-0000-0000-0000000000B1", 2)] 2473 private class B1 : A0 { } 2474 2475 [StorableType("00000000-0000-0000-0000-0000000000B2", 3)] 2476 private class B2 { 2477 [Storable] 2478 public int x; 2479 } 2480 2481 private static class ConversionsA2A_B2B { 2482 [StorableConversion("847DD840-3EE3-4A01-AC60-FD7E71ED05F8", 1, baseGuid: "90470973-4559-428E-AF28-DD95866B0A84", baseVersion: 1)] 2483 private static Dictionary<string, object> ConvertB0_B1(Dictionary<string, object> values) { 2484 var newValues = new Dictionary<string, object>(); 2485 newValues["90470973-4559-428E-AF28-DD95866B0A84.x"] = values["847DD840-3EE3-4A01-AC60-FD7E71ED05F8.x"]; 2486 return newValues; 2487 } 2488 2489 [StorableConversion("90470973-4559-428E-AF28-DD95866B0A84", 1)] 2490 private static Dictionary<string, object> ConvertA0_A1(Dictionary<string, object> values) { 2491 var newValues = new Dictionary<string, object>(); 2492 newValues["90470973-4559-428E-AF28-DD95866B0A84.y"] = values["90470973-4559-428E-AF28-DD95866B0A84.x"]; 2493 return newValues; 2494 } 2495 2496 [StorableConversion("847DD840-3EE3-4A01-AC60-FD7E71ED05F8", 2)] 2497 private static Dictionary<string, object> ConvertB1_B2(Dictionary<string, object> values) { 2498 var newValues = new Dictionary<string, object>(); 2499 newValues["847DD840-3EE3-4A01-AC60-FD7E71ED05F8.x"] = values["90470973-4559-428E-AF28-DD95866B0A84.y"]; 2500 return newValues; 2501 } 2502 } 2503 2504 [TestMethod] 2505 [TestCategory("PersistenceNew")] 2506 [TestProperty("Time", "short")] 2507 public void TestConversionCase2() { 2508 var test = new Func<B0>(() => { 2509 return new B0() { x = 17 }; 2510 }); 2511 2512 ProtoBufSerializer serializer = new ProtoBufSerializer(); 2513 var old = test(); 2514 serializer.Serialize(old, tempFile); 2515 2516 DeregisterType(typeof(B0)); 2517 DeregisterType(typeof(B1)); 2518 DeregisterType(typeof(B2)); 2519 DeregisterType(typeof(A0)); 2520 DeregisterType(typeof(A1)); 2521 2522 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(B0)).Guid, typeof(B2)); 2523 SetTypeGuid(typeof(B2), GetTypeGuid(typeof(B0))); 2524 RemoveTypeInfo(typeof(B0)); 2525 2526 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(A0)).Guid, typeof(A1)); 2527 SetTypeGuid(typeof(A1), GetTypeGuid(typeof(A0))); 2528 RemoveTypeInfo(typeof(A0)); 2529 2530 object o = serializer.Deserialize(tempFile); 2531 var restored = (B2)o; 2532 Assert.AreEqual(restored.x, old.x); 2533 } 2534 2535 #region Inheritance Chain Test 2536 [StorableType("C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95")] 2537 private class InheritanceA0 { 2538 [Storable] 2539 public int x; 2540 } 2541 2542 [StorableType("00000000-0000-0000-0000-0000000001A1", 2)] 2543 private class InheritanceA1 { 2544 [Storable] 2545 public int y; 2546 } 2547 2548 [StorableType("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1)] 2549 private class InheritanceC0 { 2550 [Storable] 2551 public int x; 2552 } 2553 2554 [StorableType("00000000-0000-0000-0000-0000000001C1", 2)] 2555 private class InheritanceC1 { 2556 [Storable] 2557 public int x; 2558 } 2559 2560 [StorableType("41108958-227D-43C4-B049-80AD0D3DB7F6")] 2561 private class InheritanceB0 : InheritanceA0 { 2562 //[Storable] 2563 //public int x; 2564 } 2565 2566 [StorableType("00000000-0000-0000-0000-0000000001B1", 2)] 2567 private class InheritanceB1 : InheritanceC1 { } 2568 2569 private static class InheritanceConversionsA2A_B2B { 2570 [StorableConversion("C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95", 1)] 2571 private static Dictionary<string, object> ConvertA0_A1(Dictionary<string, object> values) { 2572 var newValues = new Dictionary<string, object>(); 2573 newValues["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.x"]; 2574 return newValues; 2575 } 2576 2577 [StorableConversion("41108958-227D-43C4-B049-80AD0D3DB7F6", 1, baseGuid: "C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95", baseVersion: 2)] 2578 private static Dictionary<string, object> ConvertB0_B1(Dictionary<string, object> values, out List<Tuple<string, uint>> typeChain) { 2579 typeChain = new List<Tuple<string, uint>> { 2580 Tuple.Create("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1u) 2581 }; 2582 2583 var newValues = new Dictionary<string, object>(); 2584 newValues["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"]; 2585 newValues["28A5F6B8-49AF-4C6A-AF0E-F92EB4511722.x"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"]; 2586 return newValues; 2587 } 2588 2589 [StorableConversion("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1)] 2590 private static Dictionary<string, object> ConvertC0_C1(Dictionary<string, object> values) { 2591 var newValues = new Dictionary<string, object>(); 2592 newValues["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] = (int)values["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] * 2; 2593 return newValues; 2594 } 2595 } 2596 2597 [TestMethod] 2598 [TestCategory("PersistenceNew")] 2599 [TestProperty("Time", "short")] 2600 public void TestInheritanceConversionCase1() { 2601 var test = new Func<InheritanceB0>(() => { 2602 return new InheritanceB0() { x = 17 }; 2603 }); 2604 2605 ProtoBufSerializer serializer = new ProtoBufSerializer(); 2606 var old = test(); 2607 serializer.Serialize(old, tempFile); 2608 2609 DeregisterType(typeof(InheritanceB0)); 2610 DeregisterType(typeof(InheritanceB1)); 2611 DeregisterType(typeof(InheritanceA0)); 2612 DeregisterType(typeof(InheritanceA1)); 2613 DeregisterType(typeof(InheritanceC0)); 2614 DeregisterType(typeof(InheritanceC1)); 2615 2616 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceA0)).Guid, typeof(InheritanceA1)); 2617 SetTypeGuid(typeof(InheritanceA1), GetTypeGuid(typeof(InheritanceA0))); 2618 RemoveTypeInfo(typeof(InheritanceA0)); 2619 2620 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceB0)).Guid, typeof(InheritanceB1)); 2621 SetTypeGuid(typeof(InheritanceB1), GetTypeGuid(typeof(InheritanceB0))); 2622 RemoveTypeInfo(typeof(InheritanceB0)); 2623 2624 RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceC0)).Guid, typeof(InheritanceC1)); 2625 SetTypeGuid(typeof(InheritanceC1), GetTypeGuid(typeof(InheritanceC0))); 2626 RemoveTypeInfo(typeof(InheritanceC0)); 2627 2628 object o = serializer.Deserialize(tempFile); 2629 var restoredC1 = (InheritanceC1)o; 2630 var restoredB1 = (InheritanceB1)o; 2631 Assert.AreEqual(old.x, restoredB1.x); 2632 Assert.AreEqual(old.x * 2, restoredC1.x); 2633 } 2634 #endregion 2635 #endregion 2455 2636 } 2456 2637 }
Note: See TracChangeset
for help on using the changeset viewer.