Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/UnitTests/StorableAttributeTests.cs @ 1614

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

Transform console tests into unit tests (#593)

File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Persistence.Core;
4using Microsoft.VisualStudio.TestTools.UnitTesting;
5
6namespace 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.