Example #1
0
        public void Given_EmptyDataTable_When_Calculate_ThenNoCalculation()
        {
            CarSalesViewModel salesUnderTest = new CarSalesViewModel
            {
                SalesResultTable = new DataTable()
            };

            Assert.IsNull(salesUnderTest.GetCalculationRow("Total"));
        }
Example #2
0
        public void Given_DataTable_HasThreeSalesPerState_When_Calculate_Median_ReturnMedianForAllColumns()
        {
            CarSalesViewModel salesUnderTest = new CarSalesViewModel();
            DataTable         tableUnderTest = new DataTable();

            tableUnderTest.Columns.Add(new DataColumn()
            {
                Caption = "test", ColumnName = "Month"
            });
            tableUnderTest.Columns.Add(new DataColumn()
            {
                Caption = "test", ColumnName = "test"
            });
            tableUnderTest.Columns.Add(new DataColumn()
            {
                Caption = "test2", ColumnName = "test2"
            });
            DataRow row = tableUnderTest.NewRow();

            row[0] = "January";
            row[1] = 356;
            row[2] = 100;
            DataRow row1 = tableUnderTest.NewRow();

            row1[0] = "February";
            row1[1] = 234;
            row1[2] = 123;
            DataRow row2 = tableUnderTest.NewRow();

            row2[0] = "March";
            row2[1] = 125;
            row2[2] = 316;
            tableUnderTest.Rows.Add(row);
            tableUnderTest.Rows.Add(row1);
            tableUnderTest.Rows.Add(row2);

            salesUnderTest.SalesResultTable        = tableUnderTest;
            salesUnderTest.SelectedStateCollection = new ObservableCollection <string> {
                "test", "test2"
            };

            DataRow calculatedResult = salesUnderTest.GetCalculationRow("Med.");

            Assert.AreEqual("Med.:", calculatedResult[0]);
            Assert.AreEqual("234.00", calculatedResult[1]);
            Assert.AreEqual("123.00", calculatedResult[2]);
        }
Example #3
0
        public void Given_DataTable_HasMultipleSales_When_Calculate_Avg_ReturnAverageForAllColumns()
        {
            CarSalesViewModel salesUnderTest = new CarSalesViewModel();
            DataTable         tableUnderTest = new DataTable();

            tableUnderTest.Columns.Add(new DataColumn()
            {
                Caption = "test", ColumnName = "Month"
            });
            tableUnderTest.Columns.Add(new DataColumn()
            {
                Caption = "test", ColumnName = "test"
            });
            tableUnderTest.Columns.Add(new DataColumn()
            {
                Caption = "test2", ColumnName = "test2"
            });
            DataRow row = tableUnderTest.NewRow();

            row[0] = "January";
            row[1] = 200;
            row[2] = 100;
            DataRow row1 = tableUnderTest.NewRow();

            row1[0] = "February";
            row1[1] = 300;
            row1[2] = 320;
            tableUnderTest.Rows.Add(row);
            tableUnderTest.Rows.Add(row1);
            salesUnderTest.SalesResultTable        = tableUnderTest;
            salesUnderTest.SelectedStateCollection = new ObservableCollection <string> {
                "test", "test2"
            };

            DataRow calculatedResult = salesUnderTest.GetCalculationRow("Avg.");

            Assert.AreEqual("Avg.:", calculatedResult[0]);
            Assert.AreEqual("250.00", calculatedResult[1]);
            Assert.AreEqual("210.00", calculatedResult[2]);
        }