Exemplo n.º 1
0
        public void AddTable_Adds_New_Existing_Table()
        {
            Tables tables = new Tables();
            List <Dictionary <string, string> > values   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         tableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            values.Add(tableRow);

            List <Dictionary <string, string> > otherValues   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         otherTableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            otherValues.Add(otherTableRow);

            Assert.IsTrue(tables.AddTable("Foo", values));
            Assert.IsFalse(tables.AddTable("Foo", otherValues));
            Assert.IsTrue(tables.AddTable("Bar", otherValues));
        }
Exemplo n.º 2
0
        public void GenerateModelFromTables_Of_Unsupported_Table_Throws_Exception()
        {
            Tables tables = new Tables();
            List <Dictionary <string, string> > values   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         tableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            values.Add(tableRow);
            tables.AddTable("Foo", values);

            List <Dictionary <string, string> > otherValues   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         otherTableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            otherValues.Add(otherTableRow);
            tables.AddTable("Bar", otherValues);

            Assert.That(() => tables.GenerateModelFromTables(new SAP2000Adaptor()),
                        Throws.Exception
                        .TypeOf <CSiException>()
                        .With.Property("Message")
                        .EqualTo("Table Foo not currently supported."));
        }
Exemplo n.º 3
0
        public void RemoveTable_Sets_HasTable_To_False_When_Removing_Last_Table()
        {
            Tables tables = new Tables();
            List <Dictionary <string, string> > values   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         tableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            values.Add(tableRow);
            tables.AddTable("Foo", values);

            List <Dictionary <string, string> > otherValues   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         otherTableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            otherValues.Add(otherTableRow);
            tables.AddTable("Bar", otherValues);

            Assert.IsTrue(tables.RemoveTable("Foo"));
            Assert.IsTrue(tables.RemoveTable("Bar"));
            Assert.IsFalse(tables.HasTables);
        }
Exemplo n.º 4
0
        public void RemoveTable_Does_Not_Remove_Nonexisting_Table()
        {
            Tables tables = new Tables();
            List <Dictionary <string, string> > values   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         tableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            values.Add(tableRow);
            tables.AddTable("Foo", values);

            List <Dictionary <string, string> > otherValues   = new List <Dictionary <string, string> >();
            Dictionary <string, string>         otherTableRow = new Dictionary <string, string>
            {
                ["Foo"] = "Bar",
                ["Moo"] = "Nar"
            };

            otherValues.Add(otherTableRow);
            tables.AddTable("Bar", otherValues);

            Assert.IsFalse(tables.RemoveTable("Moo"));
        }
Exemplo n.º 5
0
        public void AddTable_Does_Not_Add_Null()
        {
            Tables tables = new Tables();
            List <Dictionary <string, string> > values = null;

            Assert.IsFalse(tables.AddTable(null, null));
            Assert.IsFalse(tables.AddTable("Foo", null));

            values = new List <Dictionary <string, string> >();
            Assert.IsFalse(tables.AddTable("Foo", values));
        }
Exemplo n.º 6
0
        public NumbersDataContext()
        {
            Tables.AddTable(Numbers = Number.CreateTable());
            Tables.AddTable(Powers  = PowersRow.CreateTable());

            for (int i = 1; i <= 20; i++)
            {
                var number = new Number {
                    Value = i
                };
                Numbers.Rows.Add(number);

                for (int j = 0; j < 10; j++)
                {
                    Powers.Rows.Add(new PowersRow {
                        Base = number, Exponent = j
                    });
                }
            }
        }
Exemplo n.º 7
0
        public Tables ReadFile(Tables tables, IEnumerable <string> lines)
        {
            string tableName = string.Empty;
            List <Dictionary <string, string> > tableKeyValues = new List <Dictionary <string, string> >();

            foreach (string line in lines)
            {
                if (lineHasTableName(line))
                {
                    tableName = parseTableName(line);
                }
                else if (lineIsEndOfTable(line, tableName))
                {
                    tables.AddTable(tableName, tableKeyValues);
                    tableName      = string.Empty;
                    tableKeyValues = new List <Dictionary <string, string> >();
                }
                else if (!string.IsNullOrWhiteSpace(tableName))
                { // TODO: May be program specific
                    string[] lineKeyValues = System.Text.RegularExpressions.Regex.Split(line, @"\s{3,3}");
                    Dictionary <string, string> keyValue = new Dictionary <string, string>();
                    foreach (var lineKeyValue in lineKeyValues)
                    {
                        string[] keyValues = lineKeyValue.Split('=');
                        if (keyValues.Length != 2)
                        {
                            continue;
                        }

                        keyValue[keyValues[0]] = keyValues[1];
                    }
                    tableKeyValues.Add(keyValue);
                }
            }

            return(tables);
        }
Exemplo n.º 8
0
 public NumbersPowersContext()
 {
     Tables.AddTable(Numbers = Number.CreateTable());
     Tables.AddTable(Powers  = PowersRow.CreateTable());
 }