#pragma warning disable RCS1175 // Unused this parameter.
        public static void ExactMatch(this Assert assert, List <ISlimRow> rows, List <CaseInsensitiveStringKeyDictionary <object> > referenceRows)
#pragma warning restore RCS1175 // Unused this parameter.
        {
            Assert.AreEqual(referenceRows.Count, rows.Count);
            for (var i = 0; i < referenceRows.Count; i++)
            {
                var referenceRow = referenceRows[i];
                var row          = rows[i];

                foreach (var kvp in referenceRow)
                {
                    var expectedValue = kvp.Value;
                    Assert.AreNotEqual(null, expectedValue, "wrong test data");
                    var value = row[kvp.Key];
                    Assert.IsTrue(DefaultValueComparer.ValuesAreEqual(value, expectedValue));
                }

                foreach (var kvp in row.Values)
                {
                    var expectedValue = kvp.Value;
                    var value         = referenceRow[kvp.Key];
                    Assert.IsTrue(DefaultValueComparer.ValuesAreEqual(value, expectedValue));
                }
            }
        }
        private void ListView_FormatCell(object sender, FormatCellEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Column.Text))
            {
                e.SubItem.ForeColor = Color.DarkGray;
            }

            if (e.Model is ProcessRowModel model && model.PreviousValues != null)
            {
                var columnIndex = e.ColumnIndex - _fixColumnCount;
                if (columnIndex >= 0)
                {
                    var valueIndex = columnIndex / 2;

                    var previousValue = valueIndex < model.PreviousValues.Length ? model.PreviousValues[valueIndex] : null;
                    var newValue      = valueIndex < model.NewValues.Length ? model.NewValues[valueIndex] : null;

                    if (valueIndex % 2 == 0)
                    {
                        if (!DefaultValueComparer.ValuesAreEqual(previousValue, newValue))
                        {
                            e.SubItem.BackColor = Color.LightBlue;
                        }
                    }
                    else if ((previousValue == null != (newValue == null)) ||
                             (previousValue != null && newValue != null && previousValue.GetType() != newValue.GetType()))
                    {
                        e.SubItem.BackColor = Color.LightBlue;
                    }
                }
            }
        }
    public bool Equals(IReadOnlySlimRow leftRow, IReadOnlySlimRow rightRow)
    {
        if (leftRow == rightRow)
        {
            return(true);
        }

        if (leftRow == null || rightRow == null)
        {
            return(false);
        }

        if (Columns != null)
        {
            if (ColumnsToIgnore != null)
            {
                throw new ArgumentException(nameof(ColumnsToIgnore) + " can not be set if " + nameof(Columns) + " is set");
            }

            foreach (var column in Columns)
            {
                if (!DefaultValueComparer.ValuesAreEqual(leftRow[column], rightRow[column]))
                {
                    return(false);
                }
            }
        }
        else
        {
            var columnsToIgnore = ColumnsToIgnore != null
                ? new HashSet <string>(ColumnsToIgnore)
                : null;

            foreach (var kvp in leftRow.Values)
            {
                if (columnsToIgnore?.Contains(kvp.Key) == true)
                {
                    continue;
                }

                if (!DefaultValueComparer.ValuesAreEqual(kvp.Value, rightRow[kvp.Key]))
                {
                    return(false);
                }
            }

            foreach (var kvp in rightRow.Values)
            {
                if (columnsToIgnore?.Contains(kvp.Key) == true)
                {
                    continue;
                }

                if (!DefaultValueComparer.ValuesAreEqual(kvp.Value, leftRow[kvp.Key]))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Exemple #4
0
    private static void AssertValuesAreEqual(object expected, object actual, string key, int row)
    {
        var areEqual = DefaultValueComparer.ValuesAreEqual(actual, expected);

        Assert.IsTrue(areEqual, "AssertValuesAreEqual failed. Expected:<" + expected + ">.Actual:<" + actual + ">, Key: " + key + ", in row " + row + ".");
    }
        public ProcessRowListControl(Control container, TrackedProcessInvocation process, List <TrackedRow> rows)
        {
            Container = container;
            Process   = process;
            Rows      = rows;

            Updater = new ControlUpdater <ProcessRowModel>(null, Container, -1, 10)
            {
                ItemFilter   = ItemFilter,
                ContainsRows = true,
            };

            Updater.CreateSearchBox(10, 10);

            ShowAll = new RadioButton()
            {
                Parent     = container,
                Bounds     = new Rectangle(Updater.SearchBox.Right + 20, Updater.SearchBox.Top, 60, Updater.SearchBox.Height),
                Text       = "All",
                CheckAlign = ContentAlignment.MiddleLeft,
                Checked    = process.Kind != ProcessKind.mutator,
            };

            ShowChanged = new RadioButton()
            {
                Parent     = container,
                Bounds     = new Rectangle(ShowAll.Right + 20, Updater.SearchBox.Top, 75, Updater.SearchBox.Height),
                Text       = "Changed",
                CheckAlign = ContentAlignment.MiddleLeft,
                Checked    = process.Kind == ProcessKind.mutator,
            };

            ShowUnChanged = new RadioButton()
            {
                Parent     = container,
                Bounds     = new Rectangle(ShowChanged.Right + 20, Updater.SearchBox.Top, 100, Updater.SearchBox.Height),
                Text       = "Unchanged",
                CheckAlign = ContentAlignment.MiddleLeft,
                Checked    = false,
            };

            ShowRemoved = new RadioButton()
            {
                Parent     = container,
                Bounds     = new Rectangle(ShowUnChanged.Right + 20, Updater.SearchBox.Top, 75, Updater.SearchBox.Height),
                Text       = "Removed",
                CheckAlign = ContentAlignment.MiddleLeft,
                Checked    = false,
            };

            ShowAll.CheckedChanged       += (s, a) => Updater.RefreshItems(true);
            ShowRemoved.CheckedChanged   += (s, a) => Updater.RefreshItems(true);
            ShowChanged.CheckedChanged   += (s, a) => Updater.RefreshItems(true);
            ShowUnChanged.CheckedChanged += (s, a) => Updater.RefreshItems(true);

            Updater.ListView.Anchor              = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
            Updater.ListView.Bounds              = new Rectangle(Container.ClientRectangle.Left, Container.ClientRectangle.Top + 40, Container.ClientRectangle.Width, Container.ClientRectangle.Height - 40);
            Updater.ListView.FormatCell         += ListView_FormatCell;
            Updater.ListView.UseCellFormatEvents = true;
            Updater.ListView.CellToolTipShowing += ListView_CellToolTipShowing;

            Updater.ListView.AllColumns.Add(new OLVColumn()
            {
                Text         = "ID",
                AspectGetter = x => (x as ProcessRowModel)?.RowUid,
            });

            Updater.ListView.AllColumns.Add(new OLVColumn()
            {
                Text         = "Previous process",
                AspectGetter = x => (x as ProcessRowModel)?.TrackedRow.PreviousProcess?.Name,
            });

            Updater.ListView.AllColumns.Add(new OLVColumn()
            {
                Text         = "Next process",
                AspectGetter = x => (x as ProcessRowModel)?.TrackedRow.NextProcess?.Name,
            });

            Updater.ListView.Columns.AddRange(Updater.ListView.AllColumns.ToArray());

            _fixColumnCount = Updater.ListView.Columns.Count;

            var newColumns = new List <OLVColumn>();
            var items      = new List <ProcessRowModel>();

            foreach (var row in rows)
            {
                foreach (var kvp in row.NewValues)
                {
                    AddColumnByValue(newColumns, kvp);
                }

                if (row.PreviousValues != null)
                {
                    foreach (var kvp in row.PreviousValues)
                    {
                        AddColumnByValue(newColumns, kvp);
                    }
                }

                var item = new ProcessRowModel()
                {
                    TrackedRow     = row,
                    RowUid         = row.Uid,
                    NewValues      = new object[newColumns.Count / 2],
                    NewTypes       = new string[newColumns.Count / 2],
                    PreviousValues = row.PreviousValues != null ? new object[newColumns.Count / 2] : null,
                    PreviousTypes  = row.PreviousValues != null ? new string[newColumns.Count / 2] : null,
                };

                if (row.PreviousValues != null)
                {
                    foreach (var kvp in row.PreviousValues)
                    {
                        var valueIndex = _columnIndexes[kvp.Key] / 2;
                        item.PreviousValues[valueIndex] = kvp.Value;
                        item.PreviousTypes[valueIndex]  = kvp.Value?.GetType().GetFriendlyTypeName();
                    }

                    if (row.NewValues.Count == row.PreviousValues.Count)
                    {
                        foreach (var kvp in row.NewValues)
                        {
                            row.PreviousValues.TryGetValue(kvp.Key, out var previousValue);
                            row.NewValues.TryGetValue(kvp.Key, out var newValue);

                            if (!DefaultValueComparer.ValuesAreEqual(previousValue, newValue))
                            {
                                item.Changed = true;
                            }
                        }
                    }
                    else
                    {
                        item.Changed = true;
                    }
                }

                foreach (var kvp in row.NewValues)
                {
                    var valueIndex = _columnIndexes[kvp.Key] / 2;
                    item.NewValues[valueIndex] = kvp.Value;
                    item.NewTypes[valueIndex]  = kvp.Value?.GetType().GetFriendlyTypeName();
                }

                Updater.AddItem(item);
            }

            Updater.ListView.Columns.AddRange(newColumns.ToArray());

            Updater.Start();
        }