Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/09 16:09:29 (15 years ago)
Author:
epitzer
Message:

Store full version information with serialized data, only fall back to version invariant format if loading fails with full version. Also check, that loaded version is newer than requested version if possible. (#613)

File:
1 edited

Legend:

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

    r1779 r1780  
    1515using HeuristicLab.Persistence.Default.Decomposers;
    1616using HeuristicLab.Persistence.Auxiliary;
     17using System.Text.RegularExpressions;
    1718
    1819namespace HeuristicLab.Persistence.UnitTest {
     
    510511
    511512    [TestMethod]
    512     public void TestSavingException() {     
     513    public void TestSavingException() {
    513514      List<int> list = new List<int> { 1, 2, 3 };
    514515      XmlGenerator.Serialize(list, tempFile);
     
    528529      string shortName =
    529530        "System.Collections.Generic.List`1[[System.Int32, mscorlib]][], mscorlib";
    530       Assert.AreEqual(name, TypeNameParser.Parse(name).ToString());       
     531      Assert.AreEqual(name, TypeNameParser.Parse(name).ToString());
    531532      Assert.AreEqual(shortName, TypeNameParser.Parse(name).ToString(false));
    532533      Assert.AreEqual(shortName, typeof(List<int>[]).VersionInvariantName());
     534    }
     535
     536    [TestMethod]
     537    public void TestAssemblyVersionCheck() {
     538      IntWrapper i = new IntWrapper(1);
     539      Serializer s = new Serializer(i, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));
     540      XmlGenerator g = new XmlGenerator();
     541      StringBuilder dataString = new StringBuilder();
     542      foreach (var token in s) {
     543        dataString.Append(g.Format(token));
     544      }
     545      StringBuilder typeString = new StringBuilder();
     546      foreach (var line in g.Format(s.TypeCache))
     547        typeString.Append(line);
     548      Deserializer d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(typeString.ToString())));
     549      XmlParser p = new XmlParser(new StringReader(dataString.ToString()));
     550      IntWrapper newI = (IntWrapper)d.Deserialize(p);
     551      Assert.AreEqual(i.Value, newI.Value);
     552      string newTypeString = Regex.Replace(typeString.ToString(),
     553        "Version=(\\d+\\.\\d+\\.\\d+\\.\\d+)",
     554        "Version=9999.9999.9999.9999");
     555      try {
     556        d = new Deserializer(XmlParser.ParseTypeCache(new StringReader(newTypeString)));
     557        Assert.Fail("Exception expected");
     558      } catch (PersistenceException) {
     559        // EXPECTED
     560      }
    533561    }
    534562
     
    536564    public static void Initialize(TestContext testContext) {
    537565      ConfigurationService.Instance.Reset();
    538     }   
    539   } 
     566    }
     567  }
    540568}
Note: See TracChangeset for help on using the changeset viewer.