Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4047 was 3742, checked in by gkronber, 15 years ago

Fixed GPL license headers and deleted files which are not referenced by projects. #893

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Persistence.Core;
25using Microsoft.VisualStudio.TestTools.UnitTesting;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using System.Reflection;
28
29namespace HeuristicLab.Persistence_33.Tests {
30
31  [StorableClass]
32  class DemoClass {
33
34    [Storable(Name = "TestProperty", DefaultValue = 12)]
35    public object o = null;
36
37    [Storable]
38    public int x = 2;
39
40    public int y = 0;
41  }
42
43  [StorableClass]
44  class Base {
45    public string baseName;
46    [Storable]
47    public virtual string Name {
48      get { return "Base"; }
49      set { baseName = value; }
50    }
51  }
52
53  [StorableClass]
54  class Override : Base {
55    [Storable]
56    public override string Name {
57      get { return "Override"; }
58      set { base.Name = value; }
59    }
60  }
61
62  [StorableClass]
63  class Intermediate : Override {
64  }
65
66  [StorableClass]
67  class New : Intermediate {
68    public string newName;
69    [Storable]
70    public new string Name {
71      get { return "New"; }
72      set { newName = value; }
73    }
74  }
75
76/*  [TestClass]
77  public class AttributeTest {
78
79    [TestMethod]
80    public void SimpleStorableAttributeTest() {
81      DemoClass t = new DemoClass();
82      IEnumerable<DataMemberAccessor> accessorList = StorableAttribute.GetStorableAccessors(t);
83      Dictionary<string, DataMemberAccessor> accessors = new Dictionary<string, DataMemberAccessor>();
84      foreach (var a in accessorList)
85        accessors.Add(a.Name, a);
86      Assert.IsTrue(accessors.ContainsKey("TestProperty"));
87      Assert.IsTrue(accessors.ContainsKey("x"));
88      Assert.IsFalse(accessors.ContainsKey("y"));
89      object o = new object();
90      t.o = o;
91      Assert.AreSame(accessors["TestProperty"].Get(), o);
92      t.x = 12;
93      Assert.AreEqual(accessors["x"].Get(), 12);
94      t.y = 312890;
95      accessors["TestProperty"].Set(null);
96      Assert.IsNull(t.o);
97      accessors["x"].Set(123);
98      Assert.AreEqual(t.x, 123);
99    }
100
101    [TestMethod]
102    public void TestInheritance() {
103      New n = new New();
104      var accessors = StorableAttribute.GetStorableAccessors(n);
105      var accessDict = new Dictionary<string, DataMemberAccessor>();
106      foreach (var accessor in accessors) // assert uniqueness
107        accessDict.Add(accessor.Name, accessor);
108      Assert.IsTrue(accessDict.ContainsKey(typeof(New).FullName + ".Name"));
109      Assert.IsTrue(accessDict.ContainsKey(typeof(Override).FullName + ".Name"));
110      Assert.AreEqual("New", accessDict[typeof(New).FullName + ".Name"].Get());
111      Assert.AreEqual("Override", accessDict[typeof(Override).FullName + ".Name"].Get());
112    }
113
114  }*/
115
116}
Note: See TracBrowser for help on using the repository browser.