Skip to content

Commit

Permalink
Initial failing test for INPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Feb 19, 2021
1 parent 7469980 commit a175171
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Models;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Diagnostics;
using Xunit;
Expand Down Expand Up @@ -119,6 +120,19 @@ public void Updates_Cells_For_Clear()
AssertCells(target.Cells, data);
}

[Fact]
public void Updates_Cells_On_Property_Change()
{
var data = CreateData();
var target = CreateTarget(data);

Assert.Equal("Row 0", target.Cells[1, 0].Value);

data[0].Caption = "Modified";

Assert.Equal("Modified", target.Cells[1, 0].Value);
}

[Fact]
public void Disposing_Releases_Listeners_On_Items()
{
Expand Down Expand Up @@ -278,7 +292,6 @@ private static void AssertCells(ICells cells, IList<Row> data)
}
}


private static FlatTreeDataGridSource<Row> CreateTarget(IEnumerable<Row> rows)
{
return new FlatTreeDataGridSource<Row>(rows)
Expand Down Expand Up @@ -311,10 +324,22 @@ private static void AssertCells(ICells cells, IList<Row> data)
}
}

private class Row
private class Row : NotifyingBase
{
public int Id { get; set; }
public string? Caption { get; set; }
private int _id;
private string? _caption;

public int Id
{
get => _id;
set => RaiseAndSetIfChanged(ref _id, value);
}

public string? Caption
{
get => _caption;
set => RaiseAndSetIfChanged(ref _caption, value);
}
}
}
}

0 comments on commit a175171

Please sign in to comment.