2 // DynamicRecordTests.cs
5 // Jérémie "garuma" Laval <jeremie.laval@gmail.com>
7 // Copyright (c) 2011 Novell
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
29 using System.Collections.Generic;
33 using NUnit.Framework;
35 namespace MonoTests.WebMatrix.Data
37 [TestFixtureAttribute]
38 public class DynamicRecordTests
45 var fields = new Dictionary<string, object> () {
48 { "foobar", "foobar" }
50 record = new DynamicRecord (fields);
54 public void ColumnsTest ()
56 var columns = record.Columns;
57 Assert.AreEqual (3, columns.Count);
59 Assert.AreEqual ("foo", columns[0]);
60 Assert.AreEqual ("bar", columns[1]);
61 Assert.AreEqual ("foobar", columns[2]);
65 public void AccessByNameTest ()
67 Assert.AreEqual (1, record["foo"]);
68 Assert.AreEqual (4.1f, record["bar"]);
69 Assert.AreEqual ("foobar", record["foobar"]);
73 public void AccessByIndexTest ()
75 Assert.AreEqual (1, record[0]);
76 Assert.AreEqual (4.1f, record[1]);
77 Assert.AreEqual ("foobar", record[2]);
81 public void AccesByDynamicTest ()
85 Assert.AreEqual (1, r.foo);
86 Assert.AreEqual (4.1f, r.bar);
87 Assert.AreEqual ("foobar", r.foobar);
91 public void GetDynamicMemberNamesTest ()
93 var expected = new string[] { "foo", "bar", "foobar" };
94 CollectionAssert.AreEquivalent (expected, record.GetDynamicMemberNames ());