|
|
@ -5,8 +5,13 @@ using System; |
|
|
using System.Collections; |
|
|
using System.Collections; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.ComponentModel; |
|
|
using System.ComponentModel; |
|
|
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
|
|
using Avalonia.Data; |
|
|
using Avalonia.Markup.Xaml.Data; |
|
|
using Avalonia.Markup.Xaml.Data; |
|
|
|
|
|
using Avalonia.Platform; |
|
|
using Avalonia.UnitTests; |
|
|
using Avalonia.UnitTests; |
|
|
|
|
|
using Moq; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
namespace Avalonia.Controls.UnitTests |
|
|
namespace Avalonia.Controls.UnitTests |
|
|
@ -14,63 +19,44 @@ namespace Avalonia.Controls.UnitTests |
|
|
public class TextBoxTests_ValidationState |
|
|
public class TextBoxTests_ValidationState |
|
|
{ |
|
|
{ |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Setter_Exceptions_Should_Set_ValidationState() |
|
|
public void Setter_Exceptions_Should_Set_Error_Pseudoclass() |
|
|
{ |
|
|
{ |
|
|
using (UnitTestApplication.Start(TestServices.MockThreadingInterface)) |
|
|
using (UnitTestApplication.Start(Services)) |
|
|
{ |
|
|
{ |
|
|
var target = new TextBox(); |
|
|
var target = new TextBox |
|
|
var binding = new Binding(nameof(ExceptionTest.LessThan10)); |
|
|
{ |
|
|
binding.Source = new ExceptionTest(); |
|
|
DataContext = new ExceptionTest(), |
|
|
////binding.EnableValidation = true;
|
|
|
[!TextBox.TextProperty] = new Binding(nameof(ExceptionTest.LessThan10), BindingMode.TwoWay), |
|
|
target.Bind(TextBox.TextProperty, binding); |
|
|
Template = CreateTemplate(), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Assert.True(false); |
|
|
target.ApplyTemplate(); |
|
|
//Assert.True(target.ValidationStatus.IsValid);
|
|
|
|
|
|
//target.Text = "20";
|
|
|
|
|
|
//Assert.False(target.ValidationStatus.IsValid);
|
|
|
|
|
|
//target.Text = "1";
|
|
|
|
|
|
//Assert.True(target.ValidationStatus.IsValid);
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact(Skip = "TODO: Not yet passing")] |
|
|
Assert.False(target.Classes.Contains(":error")); |
|
|
public void Unconvertable_Value_Should_Set_ValidationState() |
|
|
target.Text = "20"; |
|
|
{ |
|
|
Assert.True(target.Classes.Contains(":error")); |
|
|
using (UnitTestApplication.Start(TestServices.MockThreadingInterface)) |
|
|
target.Text = "1"; |
|
|
{ |
|
|
Assert.False(target.Classes.Contains(":error")); |
|
|
var target = new TextBox(); |
|
|
|
|
|
var binding = new Binding(nameof(ExceptionTest.LessThan10)); |
|
|
|
|
|
binding.Source = new ExceptionTest(); |
|
|
|
|
|
////binding.EnableValidation = true;
|
|
|
|
|
|
target.Bind(TextBox.TextProperty, binding); |
|
|
|
|
|
|
|
|
|
|
|
Assert.True(false); |
|
|
|
|
|
//Assert.True(target.ValidationStatus.IsValid);
|
|
|
|
|
|
//target.Text = "foo";
|
|
|
|
|
|
//Assert.False(target.ValidationStatus.IsValid);
|
|
|
|
|
|
//target.Text = "1";
|
|
|
|
|
|
//Assert.True(target.ValidationStatus.IsValid);
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
private static TestServices Services => TestServices.MockThreadingInterface.With( |
|
|
public void Indei_Should_Set_ValidationState() |
|
|
standardCursorFactory: Mock.Of<IStandardCursorFactory>()); |
|
|
{ |
|
|
|
|
|
using (UnitTestApplication.Start(TestServices.MockThreadingInterface)) |
|
|
|
|
|
{ |
|
|
|
|
|
var target = new TextBox(); |
|
|
|
|
|
var binding = new Binding(nameof(ExceptionTest.LessThan10)); |
|
|
|
|
|
binding.Source = new IndeiTest(); |
|
|
|
|
|
////binding.EnableValidation = true;
|
|
|
|
|
|
target.Bind(TextBox.TextProperty, binding); |
|
|
|
|
|
|
|
|
|
|
|
Assert.True(false); |
|
|
private IControlTemplate CreateTemplate() |
|
|
//Assert.True(target.ValidationStatus.IsValid);
|
|
|
{ |
|
|
//target.Text = "20";
|
|
|
return new FuncControlTemplate<TextBox>(control => |
|
|
//Assert.False(target.ValidationStatus.IsValid);
|
|
|
new TextPresenter |
|
|
//target.Text = "1";
|
|
|
{ |
|
|
//Assert.True(target.ValidationStatus.IsValid);
|
|
|
Name = "PART_TextPresenter", |
|
|
} |
|
|
[!!TextPresenter.TextProperty] = new Binding |
|
|
|
|
|
{ |
|
|
|
|
|
Path = "Text", |
|
|
|
|
|
Mode = BindingMode.TwoWay, |
|
|
|
|
|
Priority = BindingPriority.TemplatedParent, |
|
|
|
|
|
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent), |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private class ExceptionTest |
|
|
private class ExceptionTest |
|
|
|