Exemplo n.º 1
0
        public void WriteATableOfDataWithUnits()
        {
            DataTable data = new DataTable("Report");

            data.Columns.Add("Col1", typeof(int));
            data.Columns.Add("Col2", typeof(int));
            DataRow row = data.NewRow();

            row["Col1"] = 10;
            row["Col2"] = 20;
            data.Rows.Add(row);
            row         = data.NewRow();
            row["Col1"] = 11;
            row["Col2"] = 21;
            data.Rows.Add(row);

            DataStoreWriter writer = new DataStoreWriter(database);

            writer.WriteTable(data);
            writer.AddUnits("Report", new string[] { "Col1" }, new string[] { "g" });
            writer.Stop();

            Assert.AreEqual(Utilities.TableToString(database, "Report"),
                            $"CheckpointID,Col1,Col2{Environment.NewLine}" +
                            $"           1,  10,  20{Environment.NewLine}" +
                            $"           1,  11,  21{Environment.NewLine}");

            // Make sure units were extracted from the column names and written.
            Assert.AreEqual(Utilities.TableToString(database, "_Units"),
                            $"TableName,ColumnHeading,Units{Environment.NewLine}" +
                            $"   Report,         Col1,    g{Environment.NewLine}");
        }
Exemplo n.º 2
0
        public void WriteATableOfDataWithUnits()
        {
            DataTable data = new DataTable("Report");

            data.Columns.Add("Col1", typeof(int));
            data.Columns.Add("Col2", typeof(int));
            DataRow row = data.NewRow();

            row["Col1"] = 10;
            row["Col2"] = 20;
            data.Rows.Add(row);
            row         = data.NewRow();
            row["Col1"] = 11;
            row["Col2"] = 21;
            data.Rows.Add(row);

            DataStoreWriter writer = new DataStoreWriter(database);

            writer.WriteTable(data);
            writer.AddUnits("Report", new string[] { "Col1" }, new string[] { "g" });
            writer.Stop();

            Assert.IsTrue(
                Utilities.CreateTable(new string[] { "CheckpointID", "Col1", "Col2" },
                                      new List <object[]> {
                new object[] { 1, 10, 20 },
                new object[] { 1, 11, 21 }
            })
                .IsSame(Utilities.GetTableFromDatabase(database, "Report")));

            Assert.IsTrue(
                Utilities.CreateTable(new string[] { "TableName", "ColumnHeading", "Units" },
                                      new List <object[]> {
                new object[] { "Report", "Col1", "g" }
            })
                .IsSame(Utilities.GetTableFromDatabase(database, "_Units")));
        }