Beispiel #1
0
        public void RemovingRows()
        {
            TableTwo table1 = _relay.GetTable("Table1");

            Assert.AreEqual(2, table1.GetIndexesOfPopulatedRows().Length);
            Assert.IsNotNull(table1.GetRow(_rowIndex0));
            table1.RemoveRowAt(_rowIndex0);
            Assert.AreEqual(1, table1.GetIndexesOfPopulatedRows().Length);
            Assert.Throws <RelayException>(() =>
            {
                table1.GetRow(_rowIndex0);
            });
            table1.RemoveRowAt(_rowIndex1);
            Assert.AreEqual(0, table1.GetIndexesOfPopulatedRows().Length);
        }
Beispiel #2
0
        public void GetListOfRowIdsInTable()
        {
            RelayTwo relay = new RelayTwo();
            TableTwo table = relay.CreateTable("Table");

            table.CreateRow();
            table.CreateRow();
            table.CreateRow();

            int[] allObjectIds = table.GetIndexesOfPopulatedRows();

            Assert.AreEqual(3, allObjectIds.Length);
            CollectionAssert.AllItemsAreUnique(allObjectIds);
        }
Beispiel #3
0
        public void LoadFromSeveralPartialDatabases()
        {
            {
                RelayTwo r1 = new RelayTwo();
                TableTwo t  = r1.CreateTable("Table");

                t.AddField <string>("animal");
                t.AddField <int>("age");

                TableRow row0 = t.CreateRow();
                row0.Set("animal", "rabbit");
                row0.Set("age", 5);

                TableRow row1 = t.CreateRow();
                row1.Set("animal", "salmon");
                row1.Set("age", 10);

                TableRow row2 = t.CreateRow();
                row2.Set("animal", "spider");
                row2.Set("age", 1);

                r1.SaveAll("r1.json");
            }

            {
                RelayTwo r2 = new RelayTwo();
                TableTwo t  = r2.CreateTable("Table");

                t.AddField <string>("animal");
                t.AddField <bool>("carnivore");

                TableRow row0 = t.CreateRow();
                row0.Set("animal", "mouse");
                row0.Set("carnivore", false);

                TableRow row1 = t.CreateRow();
                row1.Set("animal", "fox");
                row1.Set("carnivore", true);

                r2.SaveAll("r2.json");
            }

            {
                RelayTwo combined = new RelayTwo();
                combined.AppendTables("r1.json");
                combined.AppendTables("r2.json");

                Assert.AreEqual(1, combined.tables.Count);

                TableTwo t = combined.GetTable("Table");
                Assert.AreEqual(3, t.fieldNames.Length);

                Console.WriteLine("The merged table contains the following rows: ");
                foreach (int rowIndex in t.GetIndexesOfPopulatedRows())
                {
                    TableRow row = t[rowIndex];
                    Console.WriteLine("Values in row " + rowIndex);
                    foreach (string s in row.valuesAsStrings)
                    {
                        Console.Write(s + ", ");
                    }
                    Console.WriteLine("\n");
                }
                Assert.AreEqual(5, t.GetIndexesOfPopulatedRows().Length);

                TableRow rabbit = t[0];
                TableRow salmon = t[1];
                TableRow spider = t[2];
                TableRow mouse  = t[3];
                TableRow fox    = t[4];

                Assert.AreEqual("rabbit", rabbit.Get <string>("animal"));
                Assert.AreEqual("salmon", salmon.Get <string>("animal"));
                Assert.AreEqual("spider", spider.Get <string>("animal"));
                Assert.AreEqual("mouse", mouse.Get <string>("animal"));
                Assert.AreEqual("fox", fox.Get <string>("animal"));

                Assert.AreEqual(5, rabbit.Get <int>("age"));
                Assert.AreEqual(10, salmon.Get <int>("age"));
                Assert.AreEqual(1, spider.Get <int>("age"));
                Assert.Throws <RelayException>(() =>
                {
                    Assert.AreEqual(0, mouse.Get <int>("age"));
                });
                Assert.Throws <RelayException>(() =>
                {
                    Assert.AreEqual(0, fox.Get <int>("age"));
                });
                Assert.AreEqual(true, fox.Get <bool>("carnivore"));
            }
        }