Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3046 was 3025, checked in by epitzer, 15 years ago

Move attribute discovery from attribute classes to StorableSerializer (in preparation for unified discovery and handling of AllFields, AllProperties, ...) (#548)

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