Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Persistence.Core;
|
---|
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Persistence.Test {
|
---|
7 |
|
---|
8 | class DemoClass {
|
---|
9 |
|
---|
10 | [Storable(Name = "TestProperty", DefaultValue = 12)]
|
---|
11 | public object o;
|
---|
12 |
|
---|
13 | [Storable]
|
---|
14 | public int x = 2;
|
---|
15 |
|
---|
16 | public int y;
|
---|
17 |
|
---|
18 | }
|
---|
19 |
|
---|
20 | [TestClass]
|
---|
21 | public class AttributeTest {
|
---|
22 |
|
---|
23 | [TestMethod]
|
---|
24 | public void SimpleStorableAttributeTest() {
|
---|
25 | DemoClass t = new DemoClass();
|
---|
26 | Dictionary<string, DataMemberAccessor> accessors = StorableAttribute.GetStorableAccessors(t);
|
---|
27 | Assert.IsTrue(accessors.ContainsKey("o"));
|
---|
28 | Assert.IsTrue(accessors.ContainsKey("x"));
|
---|
29 | Assert.IsFalse(accessors.ContainsKey("y"));
|
---|
30 | object o = new object();
|
---|
31 | t.o = o;
|
---|
32 | Assert.AreSame(accessors["o"].Get(), o);
|
---|
33 | t.x = 12;
|
---|
34 | Assert.AreEqual(accessors["x"].Get(), 12);
|
---|
35 | t.y = 312890;
|
---|
36 | accessors["o"].Set(null);
|
---|
37 | Assert.IsNull(t.o);
|
---|
38 | accessors["x"].Set(123);
|
---|
39 | Assert.AreEqual(t.x, 123);
|
---|
40 | }
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.