|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 |
| -using System.Linq; |
| 3 | +using System.Globalization; |
4 | 4 | using System.Reactive.Subjects;
|
5 |
| -using System.Text; |
6 |
| -using System.Threading.Tasks; |
7 | 5 | using Avalonia.Controls.Models.TreeDataGrid;
|
8 | 6 | using Avalonia.Data;
|
9 | 7 | using Avalonia.Headless.XUnit;
|
10 |
| -using Avalonia.Media; |
11 | 8 | using Xunit;
|
12 | 9 |
|
13 | 10 | namespace Avalonia.Controls.TreeDataGridTests.Models
|
@@ -95,5 +92,38 @@ public void Modified_Value_Is_Not_Written_To_Binding_On_CancelEdit()
|
95 | 92 | Assert.Equal("initial", target.Value);
|
96 | 93 | Assert.Equal(new[] { "initial" }, result);
|
97 | 94 | }
|
| 95 | + |
| 96 | + [AvaloniaFact(Timeout = 10000)] |
| 97 | + public void Setting_Text_Does_Not_Change_ReadOnly_Value() |
| 98 | + { |
| 99 | + var binding = new BehaviorSubject<BindingValue<CustomValueObject>>(value: new CustomValueObject(100)); |
| 100 | + var target = new TextCell<CustomValueObject>(binding, isReadOnly: true); |
| 101 | + |
| 102 | + Assert.Equal(100, target.Value.Value); |
| 103 | + |
| 104 | + // simulating TreeDataGridTextCell.OnModelPropertyChanged |
| 105 | + target.PropertyChanged += (sender, args) => |
| 106 | + { |
| 107 | + if (args.PropertyName == nameof(ITextCell.Value)) |
| 108 | + target.Text = target.Value.ToString(); |
| 109 | + }; |
| 110 | + |
| 111 | + target.Value = new CustomValueObject(42); |
| 112 | + Assert.Equal(42, target.Value.Value); |
| 113 | + } |
| 114 | + |
| 115 | + private readonly struct CustomValueObject |
| 116 | + { |
| 117 | + private readonly int _value; |
| 118 | + |
| 119 | + public CustomValueObject(int value) |
| 120 | + { |
| 121 | + _value = value; |
| 122 | + } |
| 123 | + |
| 124 | + public int Value => _value; |
| 125 | + |
| 126 | + public override string ToString() => _value.ToString(CultureInfo.InvariantCulture); |
| 127 | + } |
98 | 128 | }
|
99 | 129 | }
|
0 commit comments