예제 #1
0
        private static void ObjectComparerInternalSorted <T>(
            Table table,
            IEnumerable <T> dataList,
            Action <TableRow, T> postCompareActions,
            IEnumerable <ColumnToActionContainer <IComparerColumnAction> > columnOverrides)
        {
            var compareTableResult = new CompareTableResult();

            compareTableResult.InitCompare(table, dataList.Count());

            // hold which column maps to which property
            var columnActions = ColumnActionFactory.GetActionsFromColumns(
                table, typeof(T), columnOverrides);

            var actualData = dataList.ToList();

            // flip through each row
            for (var tableRowIndex = 0; tableRowIndex < table.RowCount; tableRowIndex++)
            {
                var row = table.Rows[tableRowIndex];

                // Test for null
                if (tableRowIndex >= actualData.Count)
                {
                    var noRowCompareRowResult = ObjectComparerInternalRow(columnActions, row);
                    compareTableResult.AddRowResult(
                        tableRowIndex, int.MaxValue, noRowCompareRowResult, false);
                    continue;
                }

                var dataItem = actualData.ElementAt(tableRowIndex);

                // Compare It
                var compareRowResult = ObjectComparerInternalRow <T>(columnActions, row, dataItem);
                compareTableResult.AddRowResult(tableRowIndex, tableRowIndex, compareRowResult, true);

                if (compareRowResult.totalErrors == 0)
                {
                    if (postCompareActions != null)
                    {
                        postCompareActions(table.Rows[tableRowIndex], dataItem);
                    }
                }
            }

            for (var dataIndex = table.RowCount; dataIndex < dataList.Count(); dataIndex++)
            {
                var dataItem         = dataList.ElementAt(dataIndex);
                var compareRowResult = ObjectComparerInternalRow(columnActions, dataItem);
                compareTableResult.AddRowResult(int.MaxValue, dataIndex, compareRowResult, false);
            }

            compareTableResult.FinalAnalyst();

            // Perform Printing
            Console.WriteLine(compareTableResult.PrintMeSpecflowStyle());

            compareTableResult.TheAssert();
        }
예제 #2
0
        private static void ObjectComparerWithFinderInternal <T>(
            Table table,
            Func <TableRow, T> objectFinder,
            Action <TableRow, T> postCompareActions,
            IEnumerable <ColumnToActionContainer <IComparerColumnAction> > columnOverrides)
        {
            var compareTableResult = new CompareTableResult();

            compareTableResult.InitCompare(table, table.RowCount);

            // hold which column maps to which property
            var columnActions = ColumnActionFactory.GetActionsFromColumns(
                table, typeof(T), columnOverrides);

            // flip through each row
            for (var tableRowIndex = 0; tableRowIndex < table.RowCount; tableRowIndex++)
            {
                var row = table.Rows[tableRowIndex];

                var dataItem = objectFinder(row);

                // can't set anything on null anyway.
                if (dataItem == null)
                {
                    throw new AssertFailedException("Object Not found in Row " + tableRowIndex);
                }

                // Compare It
                var compareRowResult = ObjectComparerInternalRow <T>(columnActions, row, dataItem);
                compareTableResult.AddRowResult(tableRowIndex, tableRowIndex, compareRowResult, true);

                if (compareRowResult.totalErrors == 0)
                {
                    if (postCompareActions != null)
                    {
                        postCompareActions(table.Rows[tableRowIndex], dataItem);
                    }
                }
            }

            compareTableResult.FinalAnalyst();

            // Perform Printing
            Console.WriteLine(compareTableResult.PrintMeSpecflowStyle());

            compareTableResult.TheAssert();
        }
예제 #3
0
        private static void ObjectComparerInternalOne <T>(
            Table verticalOrHorizontalTable,
            T dataItem,
            Action <TableRow, T> postCompareActions,
            IEnumerable <ColumnToActionContainer <IComparerColumnAction> > columnOverrides)
        {
            var table = VerticalToHorizonal(verticalOrHorizontalTable);

            if (table.RowCount != 1)
            {
                Assert.Fail("A direct compare requires one and only one Specflow Row.");
            }

            var compareTableResult = new CompareTableResult();

            compareTableResult.InitCompare(table, 1);

            // hold which column maps to which property
            var columnActions = ColumnActionFactory.GetActionsFromColumns(
                table, typeof(T), columnOverrides);

            var row = table.Rows[0];
            var compareRowResult = ObjectComparerInternalRow <T>(columnActions, row, dataItem);

            compareTableResult.AddRowResult(0, 0, compareRowResult, true);

            compareTableResult.FinalAnalyst();

            // Perform Printing
            Console.WriteLine(compareTableResult.PrintMeSpecflowStyle());

            compareTableResult.TheAssert();

            // trigger postAction if needed.
            if (compareRowResult.totalErrors == 0)
            {
                if (postCompareActions != null)
                {
                    postCompareActions(table.Rows[0], dataItem);
                }
            }
        }
예제 #4
0
        private static void ObjectComparerInternal <T>(
            Table table,
            IEnumerable <T> dataList,
            Action <TableRow, T> postCompareActions,
            IEnumerable <ColumnToActionContainer <IComparerColumnAction> > columnOverrides)
        {
            if (dataList == null)
            {
                throw new Exception("Actual is Null.  TableAid can't compare a table against null.");
            }

            var compareTableResult = new CompareTableResult();

            compareTableResult.InitCompare(table, dataList.Count());

            // hold which column maps to which property
            var columnActions = ColumnActionFactory.GetActionsFromColumns(
                table, typeof(T), columnOverrides);

            // flip through each row
            for (var tableRowIndex = 0; tableRowIndex < table.RowCount; tableRowIndex++)
            {
                var isMatch = false;

                // And each data
                for (var dataIndex = 0; dataIndex < dataList.Count(); dataIndex++)
                {
                    // Has a match Happened
                    if (compareTableResult.DoesDataHaveMatch(dataIndex))
                    {
                        continue;
                    }

                    // Ready the Compare
                    var row      = table.Rows[tableRowIndex];
                    var dataItem = dataList.ElementAt(dataIndex);

                    // Compare It
                    var compareRowResult = ObjectComparerInternalRow <T>(columnActions, row, dataItem);

                    isMatch = (compareRowResult.totalErrors == 0);

                    // This makes the Match Happen
                    compareTableResult.AddRowResult(
                        tableRowIndex, dataIndex, compareRowResult, isMatch);

                    if (compareRowResult.totalErrors == 0)
                    {
                        if (postCompareActions != null)
                        {
                            postCompareActions(table.Rows[tableRowIndex], dataItem);
                        }

                        break; // We have a match.  Stop looping data.
                    }
                }

                // Add the missing Table Records
                if (isMatch == false)
                {
                    var row = table.Rows[tableRowIndex];
                    var compareRowResult = ObjectComparerInternalRow(columnActions, row);
                    compareTableResult.AddRowResult(
                        tableRowIndex, int.MaxValue, compareRowResult, false);
                }
            }

            // Add the missing Data Records
            for (var dataIndex = 0; dataIndex < dataList.Count(); dataIndex++)
            {
                // Has a match Happened
                if (compareTableResult.DoesDataHaveMatch(dataIndex))
                {
                    continue;
                }

                // No?  Well add a blank to the compare.
                var dataItem         = dataList.ElementAt(dataIndex);
                var compareRowResult = ObjectComparerInternalRow(columnActions, dataItem);
                compareTableResult.AddRowResult(int.MaxValue, dataIndex, compareRowResult, false);
            }

            compareTableResult.FinalAnalyst();

            // Perform Printing
            Console.WriteLine(compareTableResult.PrintMeSpecflowStyle());

            compareTableResult.TheAssert();
        }