Merge pull request #268 from pcc/menudeactivate
[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 #if NET_4_0
28
29 using System;
30 using System.Collections.Generic;
31
32 using WebMatrix.Data;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.WebMatrix.Data
37 {
38         [TestFixtureAttribute]
39         public class DynamicRecordTests
40         {
41                 DynamicRecord record;
42
43                 [SetUp]
44                 public void Setup ()
45                 {
46                         var fields = new Dictionary<string, object> () {
47                                 { "foo", 1 },
48                                 { "bar", 4.1f },
49                                 { "foobar", "foobar" }
50                         };
51                         record = new DynamicRecord (fields);
52                 }
53
54                 [Test]
55                 public void ColumnsTest ()
56                 {
57                         var columns = record.Columns;
58                         Assert.AreEqual (3, columns.Count);
59
60                         Assert.AreEqual ("foo", columns[0]);
61                         Assert.AreEqual ("bar", columns[1]);
62                         Assert.AreEqual ("foobar", columns[2]);
63                 }
64
65                 [Test]
66                 public void AccessByNameTest ()
67                 {
68                         Assert.AreEqual (1, record["foo"]);
69                         Assert.AreEqual (4.1f, record["bar"]);
70                         Assert.AreEqual ("foobar", record["foobar"]);
71                 }
72
73                 [Test]
74                 public void AccessByIndexTest ()
75                 {
76                         Assert.AreEqual (1, record[0]);
77                         Assert.AreEqual (4.1f, record[1]);
78                         Assert.AreEqual ("foobar", record[2]);
79                 }
80
81                 [Test]
82                 public void AccesByDynamicTest ()
83                 {
84                         dynamic r = record;
85
86                         Assert.AreEqual (1, r.foo);
87                         Assert.AreEqual (4.1f, r.bar);
88                         Assert.AreEqual ("foobar", r.foobar);
89                 }
90
91                 [Test]
92                 public void GetDynamicMemberNamesTest ()
93                 {
94                         var expected = new string[] { "foo", "bar", "foobar" };
95                         CollectionAssert.AreEquivalent (expected, record.GetDynamicMemberNames ());
96                 }
97         }
98 }
99 #endif