Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Tests/StorableAttributeTests.cs @ 3188

Last change on this file since 3188 was 3057, checked in by epitzer, 15 years ago

Fix warnings (#915)

File size: 2.7 KB
RevLine 
[1614]1using System;
2using System.Collections.Generic;
3using HeuristicLab.Persistence.Core;
4using Microsoft.VisualStudio.TestTools.UnitTesting;
[1823]5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[1938]6using System.Reflection;
[1614]7
[2951]8namespace HeuristicLab.Persistence_33.Tests {
[1614]9
[3017]10  [StorableClass]
[1614]11  class DemoClass {
12
13    [Storable(Name = "TestProperty", DefaultValue = 12)]
[3057]14    public object o = null;
[1614]15
16    [Storable]
17    public int x = 2;
18
[3057]19    public int y = 0;
[1614]20  }
21
[3017]22  [StorableClass]
[1938]23  class Base {
24    public string baseName;
25    [Storable]
26    public virtual string Name {
27      get { return "Base"; }
28      set { baseName = value; }
29    }
30  }
31
[3017]32  [StorableClass]
[1938]33  class Override : Base {
34    [Storable]
35    public override string Name {
36      get { return "Override"; }
37      set { base.Name = value; }
38    }
39  }
40
[3017]41  [StorableClass]
[1938]42  class Intermediate : Override {
43  }
44
[3017]45  [StorableClass]
[1938]46  class New : Intermediate {
47    public string newName;
48    [Storable]
49    public new string Name {
50      get { return "New"; }
51      set { newName = value; }
52    }
53  }
54
[3025]55/*  [TestClass]
[1614]56  public class AttributeTest {
57
58    [TestMethod]
59    public void SimpleStorableAttributeTest() {
60      DemoClass t = new DemoClass();
[1960]61      IEnumerable<DataMemberAccessor> accessorList = StorableAttribute.GetStorableAccessors(t);
62      Dictionary<string, DataMemberAccessor> accessors = new Dictionary<string, DataMemberAccessor>();
63      foreach (var a in accessorList)
64        accessors.Add(a.Name, a);
[1938]65      Assert.IsTrue(accessors.ContainsKey("TestProperty"));
[1614]66      Assert.IsTrue(accessors.ContainsKey("x"));
67      Assert.IsFalse(accessors.ContainsKey("y"));
68      object o = new object();
69      t.o = o;
[1938]70      Assert.AreSame(accessors["TestProperty"].Get(), o);
[1614]71      t.x = 12;
72      Assert.AreEqual(accessors["x"].Get(), 12);
73      t.y = 312890;
[1938]74      accessors["TestProperty"].Set(null);
[1614]75      Assert.IsNull(t.o);
76      accessors["x"].Set(123);
77      Assert.AreEqual(t.x, 123);
78    }
79
[1938]80    [TestMethod]
81    public void TestInheritance() {
82      New n = new New();
83      var accessors = StorableAttribute.GetStorableAccessors(n);
84      var accessDict = new Dictionary<string, DataMemberAccessor>();
85      foreach (var accessor in accessors) // assert uniqueness
[1960]86        accessDict.Add(accessor.Name, accessor);
[1938]87      Assert.IsTrue(accessDict.ContainsKey(typeof(New).FullName + ".Name"));
88      Assert.IsTrue(accessDict.ContainsKey(typeof(Override).FullName + ".Name"));
89      Assert.AreEqual("New", accessDict[typeof(New).FullName + ".Name"].Get());
90      Assert.AreEqual("Override", accessDict[typeof(Override).FullName + ".Name"].Get());
91    }
92
[3025]93  }*/
[1614]94
95}
Note: See TracBrowser for help on using the repository browser.