Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/29/09 15:32:59 (16 years ago)
Author:
epitzer
Message:

Check for default constructor in all decomposers to ensure failure during serialization instead of deserialization. (#606)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs

    r1701 r1705  
    3838  }
    3939
     40  public class NonDefaultConstructorClass {
     41    [Storable]
     42    int value;
     43    public NonDefaultConstructorClass(int value) {
     44      this.value = value;
     45    }
     46  }
     47
    4048  public class IntWrapper {
    4149
     
    100108    [Storable]
    101109    public int[] i = new[] { 3, 4, 5, 6 };
    102     [Storable(Name="Test String")]
     110    [Storable(Name = "Test String")]
    103111    public string s;
    104112    [Storable]
     
    178186
    179187    [TestCleanup()]
    180     public void ClearTempFile() {     
     188    public void ClearTempFile() {
    181189      StreamReader reader = new StreamReader(tempFile);
    182190      string s = reader.ReadToEnd();
     
    210218      Assert.AreEqual(
    211219        DebugStringGenerator.Serialize(r),
    212         DebugStringGenerator.Serialize(newR));     
     220        DebugStringGenerator.Serialize(newR));
    213221      Assert.AreSame(newR, newR.selfReferences[0]);
    214222      Assert.AreNotSame(r, newR);
     
    223231      Assert.AreEqual(r.intList[0], 9);
    224232      Assert.AreEqual(r.intList[1], 8);
    225       Assert.AreEqual(r.intList[2], 7);     
     233      Assert.AreEqual(r.intList[2], 7);
    226234      Assert.AreEqual(r.multiDimArray[0, 0], 5);
    227235      Assert.AreEqual(r.multiDimArray[0, 1], 4);
     
    231239      Assert.AreEqual(r.multiDimArray[1, 2], 6);
    232240      Assert.IsFalse(r.boolean);
    233       Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10);     
     241      Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10);
    234242      Assert.AreEqual(r.kvp.Key, "string key");
    235243      Assert.AreEqual(r.kvp.Value, 321);
     
    486494    }
    487495
     496    [TestMethod]
     497    public void NonDefaultConstructorTest() {
     498      NonDefaultConstructorClass c = new NonDefaultConstructorClass(1);
     499      try {
     500        XmlGenerator.Serialize(c, tempFile);
     501        Assert.Fail("Exception not thrown");
     502      } catch (PersistenceException) {
     503      }
     504    }
     505
    488506    [ClassInitialize]
    489507    public static void Initialize(TestContext testContext) {
Note: See TracChangeset for help on using the changeset viewer.