Merge pull request #1909 from esdrubal/reflection
[mono.git] / mcs / class / WebMatrix.Data / Test / WebMatrix.Data / DynamicRecordTests.cs
1 // 
2 // DynamicRecordTests.cs
3 //  
4 // Author:
5 //       Jérémie "garuma" Laval <jeremie.laval@gmail.com>
6 // 
7 // Copyright (c) 2011 Novell
8 // 
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27
28 using System;
29 using System.Collections.Generic;
30
31 using WebMatrix.Data;
32
33 using NUnit.Framework;
34
35 namespace MonoTests.WebMatrix.Data
36 {
37         [TestFixtureAttribute]
38         public class DynamicRecordTests
39         {
40                 DynamicRecord record;
41
42                 [SetUp]
43                 public void Setup ()
44                 {
45                         var fields = new Dictionary<string, object> () {
46                                 { "foo", 1 },
47                                 { "bar", 4.1f },
48                                 { "foobar", "foobar" }
49                         };
50                         record = new DynamicRecord (fields);
51                 }
52
53                 [Test]
54                 public void ColumnsTest ()
55                 {
56                         var columns = record.Columns;
57                         Assert.AreEqual (3, columns.Count);
58
59                         Assert.AreEqual ("foo", columns[0]);
60                         Assert.AreEqual ("bar", columns[1]);
61                         Assert.AreEqual ("foobar", columns[2]);
62                 }
63
64                 [Test]
65                 public void AccessByNameTest ()
66                 {
67                         Assert.AreEqual (1, record["foo"]);
68                         Assert.AreEqual (4.1f, record["bar"]);
69                         Assert.AreEqual ("foobar", record["foobar"]);
70                 }
71
72                 [Test]
73                 public void AccessByIndexTest ()
74                 {
75                         Assert.AreEqual (1, record[0]);
76                         Assert.AreEqual (4.1f, record[1]);
77                         Assert.AreEqual ("foobar", record[2]);
78                 }
79
80                 [Test]
81                 public void AccesByDynamicTest ()
82                 {
83                         dynamic r = record;
84
85                         Assert.AreEqual (1, r.foo);
86                         Assert.AreEqual (4.1f, r.bar);
87                         Assert.AreEqual ("foobar", r.foobar);
88                 }
89
90                 [Test]
91                 public void GetDynamicMemberNamesTest ()
92                 {
93                         var expected = new string[] { "foo", "bar", "foobar" };
94                         CollectionAssert.AreEquivalent (expected, record.GetDynamicMemberNames ());
95                 }
96         }
97 }