[6846] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6846] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 23 |
|
---|
| 24 | namespace HeuristicLab.Persistence_33.Tests {
|
---|
| 25 |
|
---|
| 26 | [StorableClass]
|
---|
| 27 | class DemoClass {
|
---|
| 28 |
|
---|
| 29 | [Storable(Name = "TestProperty", DefaultValue = 12)]
|
---|
| 30 | public object o = null;
|
---|
| 31 |
|
---|
| 32 | [Storable]
|
---|
| 33 | public int x = 2;
|
---|
| 34 |
|
---|
| 35 | public int y = 0;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | [StorableClass]
|
---|
| 39 | class Base {
|
---|
| 40 | public string baseName;
|
---|
| 41 | [Storable]
|
---|
| 42 | public virtual string Name {
|
---|
| 43 | get { return "Base"; }
|
---|
| 44 | set { baseName = value; }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | [StorableClass]
|
---|
| 49 | class Override : Base {
|
---|
| 50 | [Storable]
|
---|
| 51 | public override string Name {
|
---|
| 52 | get { return "Override"; }
|
---|
| 53 | set { base.Name = value; }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | [StorableClass]
|
---|
| 58 | class Intermediate : Override {
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | [StorableClass]
|
---|
| 62 | class New : Intermediate {
|
---|
| 63 | public string newName;
|
---|
| 64 | [Storable]
|
---|
| 65 | public new string Name {
|
---|
| 66 | get { return "New"; }
|
---|
| 67 | set { newName = value; }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /* [TestClass]
|
---|
| 72 | public class AttributeTest {
|
---|
| 73 |
|
---|
| 74 | [TestMethod]
|
---|
| 75 | public void SimpleStorableAttributeTest() {
|
---|
| 76 | DemoClass t = new DemoClass();
|
---|
| 77 | IEnumerable<DataMemberAccessor> accessorList = StorableAttribute.GetStorableAccessors(t);
|
---|
| 78 | Dictionary<string, DataMemberAccessor> accessors = new Dictionary<string, DataMemberAccessor>();
|
---|
| 79 | foreach (var a in accessorList)
|
---|
| 80 | accessors.Add(a.Name, a);
|
---|
| 81 | Assert.IsTrue(accessors.ContainsKey("TestProperty"));
|
---|
| 82 | Assert.IsTrue(accessors.ContainsKey("x"));
|
---|
| 83 | Assert.IsFalse(accessors.ContainsKey("y"));
|
---|
| 84 | object o = new object();
|
---|
| 85 | t.o = o;
|
---|
| 86 | Assert.AreSame(accessors["TestProperty"].Get(), o);
|
---|
| 87 | t.x = 12;
|
---|
| 88 | Assert.AreEqual(accessors["x"].Get(), 12);
|
---|
| 89 | t.y = 312890;
|
---|
| 90 | accessors["TestProperty"].Set(null);
|
---|
| 91 | Assert.IsNull(t.o);
|
---|
| 92 | accessors["x"].Set(123);
|
---|
| 93 | Assert.AreEqual(t.x, 123);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | [TestMethod]
|
---|
| 97 | public void TestInheritance() {
|
---|
| 98 | New n = new New();
|
---|
| 99 | var accessors = StorableAttribute.GetStorableAccessors(n);
|
---|
| 100 | var accessDict = new Dictionary<string, DataMemberAccessor>();
|
---|
| 101 | foreach (var accessor in accessors) // assert uniqueness
|
---|
| 102 | accessDict.Add(accessor.Name, accessor);
|
---|
| 103 | Assert.IsTrue(accessDict.ContainsKey(typeof(New).FullName + ".Name"));
|
---|
| 104 | Assert.IsTrue(accessDict.ContainsKey(typeof(Override).FullName + ".Name"));
|
---|
| 105 | Assert.AreEqual("New", accessDict[typeof(New).FullName + ".Name"].Get());
|
---|
| 106 | Assert.AreEqual("Override", accessDict[typeof(Override).FullName + ".Name"].Get());
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | }*/
|
---|
| 110 |
|
---|
| 111 | }
|
---|