Changeset 5324 for trunk/sources/HeuristicLab.Persistence/3.3/Tests
- Timestamp:
- 01/18/11 15:50:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r5290 r5324 31 31 using HeuristicLab.Persistence.Auxiliary; 32 32 using HeuristicLab.Persistence.Core; 33 using HeuristicLab.Persistence.Core.Tokens; 33 34 using HeuristicLab.Persistence.Default.CompositeSerializers; 34 35 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 606 607 XmlGenerator.Serialize(c, tempFile); 607 608 Assert.Fail("Exception not thrown"); 608 } 609 catch (PersistenceException) { 609 } catch (PersistenceException) { 610 610 } 611 611 } … … 619 619 XmlGenerator.Serialize(s, tempFile); 620 620 Assert.Fail("Exception expected"); 621 } 622 catch (PersistenceException) { } 621 } catch (PersistenceException) { } 623 622 List<int> newList = (List<int>)XmlParser.Deserialize(tempFile); 624 623 Assert.AreEqual(list[0], newList[0]); … … 659 658 } 660 659 Assert.Fail("Exception expected"); 661 } 662 catch (PersistenceException px) { 660 } catch (PersistenceException px) { 663 661 Assert.AreEqual(3, px.Data.Count); 664 662 } … … 688 686 d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(newTypeString))); 689 687 Assert.Fail("Exception expected"); 690 } 691 catch (PersistenceException x) { 688 } catch (PersistenceException x) { 692 689 Assert.IsTrue(x.Message.Contains("incompatible")); 693 690 } … … 698 695 d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(newTypeString))); 699 696 Assert.Fail("Exception expected"); 700 } 701 catch (PersistenceException x) { 697 } catch (PersistenceException x) { 702 698 Assert.IsTrue(x.Message.Contains("newer")); 703 699 } … … 866 862 ExplodingDefaultConstructor newX = (ExplodingDefaultConstructor)XmlParser.Deserialize(tempFile); 867 863 Assert.Fail("Exception expected"); 868 } 869 catch (PersistenceException pe) { 864 } catch (PersistenceException pe) { 870 865 Assert.AreEqual(pe.InnerException.Message, "this constructor will always fail"); 871 866 } … … 878 873 XmlGenerator.Serialize(ns, tempFile); 879 874 Assert.Fail("PersistenceException expected"); 880 } 881 catch (PersistenceException x) { 875 } catch (PersistenceException x) { 882 876 Assert.IsTrue(x.Message.Contains(new StorableSerializer().JustifyRejection(typeof(NonSerializable)))); 883 877 } … … 1161 1155 } 1162 1156 1157 [StorableClass] 1158 public class ReadOnlyFail { 1159 [Storable] 1160 public string ReadOnly { 1161 get { return "fail"; } 1162 } 1163 } 1164 1165 [TestMethod] 1166 public void TestReadOnlyFail() { 1167 try { 1168 XmlGenerator.Serialize(new ReadOnlyFail(), tempFile); 1169 Assert.Fail("Exception expected"); 1170 } catch (PersistenceException) { 1171 } catch { 1172 Assert.Fail("PersistenceException expected"); 1173 } 1174 } 1175 1176 1177 [StorableClass] 1178 public class WriteOnlyFail { 1179 [Storable] 1180 public string WriteOnly { 1181 set { throw new InvalidOperationException("this property should never be set."); } 1182 } 1183 } 1184 1185 [TestMethod] 1186 public void TestWriteOnlyFail() { 1187 try { 1188 XmlGenerator.Serialize(new WriteOnlyFail(), tempFile); 1189 Assert.Fail("Exception expected"); 1190 } catch (PersistenceException) { 1191 } catch { 1192 Assert.Fail("PersistenceException expected."); 1193 } 1194 } 1195 1196 [StorableClass] 1197 public class OneWayTest { 1198 public OneWayTest() { this.value = "default"; } 1199 public string value; 1200 [Storable(AllowOneWay=true)] 1201 public string ReadOnly { 1202 get { return "ReadOnly"; } 1203 } 1204 [Storable(AllowOneWay=true)] 1205 public string WriteOnly { 1206 set { this.value = value; } 1207 } 1208 } 1209 1210 [TestMethod] 1211 public void TestOneWaySerialization() { 1212 var test = new OneWayTest(); 1213 var serializer = new Serializer(test, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 1214 var it = serializer.GetEnumerator(); 1215 it.MoveNext(); 1216 Assert.AreEqual("ROOT", ((BeginToken)it.Current).Name); it.MoveNext(); 1217 Assert.AreEqual("ReadOnly", ((PrimitiveToken)it.Current).Name); it.MoveNext(); 1218 Assert.AreEqual("ROOT", ((EndToken)it.Current).Name); it.MoveNext(); 1219 var deserializer = new Deserializer(new[] { 1220 new TypeMapping(0, typeof(OneWayTest).AssemblyQualifiedName, typeof(StorableSerializer).AssemblyQualifiedName), 1221 new TypeMapping(1, typeof(string).AssemblyQualifiedName, typeof(String2XmlSerializer).AssemblyQualifiedName) }); 1222 var newTest = (OneWayTest)deserializer.Deserialize(new ISerializationToken[] { 1223 new BeginToken("ROOT", 0, 0), 1224 new PrimitiveToken("WriteOnly", 1, 1, new XmlString("<![CDATA[serial data]]>")), 1225 new EndToken("ROOT", 0, 0) 1226 }); 1227 Assert.AreEqual("serial data", newTest.value); 1228 } 1229 1230 1231 1163 1232 [ClassInitialize] 1164 1233 public static void Initialize(TestContext testContext) {
Note: See TracChangeset
for help on using the changeset viewer.