csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.4 KiB
71 lines
2.4 KiB
// Copyright (c) The Perspex Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using Perspex.Controls;
|
|
using Perspex.Logging;
|
|
using Perspex.UnitTests;
|
|
using Xunit;
|
|
|
|
namespace Perspex.Markup.Xaml.UnitTests.Xaml
|
|
{
|
|
public class ControlBindingTests
|
|
{
|
|
[Fact]
|
|
public void Binding_ProgressBar_Value_To_Invalid_Value_Uses_FallbackValue()
|
|
{
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
{
|
|
var xaml = @"
|
|
<Window xmlns='https://github.com/perspex'>
|
|
<ProgressBar Maximum='10' Value='{Binding Value, FallbackValue=3}'/>
|
|
</Window>";
|
|
var loader = new PerspexXamlLoader();
|
|
var window = (Window)loader.Load(xaml);
|
|
var progressBar = (ProgressBar)window.Content;
|
|
|
|
window.DataContext = new { Value = "foo" };
|
|
window.ApplyTemplate();
|
|
|
|
Assert.Equal(3, progressBar.Value);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Invalid_FallbackValue_Logs_Error()
|
|
{
|
|
var called = false;
|
|
|
|
LogCallback checkLogMessage = (level, area, src, mt, pv) =>
|
|
{
|
|
if (level == LogEventLevel.Error &&
|
|
area == LogArea.Binding &&
|
|
mt == "Error binding to {Target}.{Property}: {Message}" &&
|
|
pv.Length == 3 &&
|
|
pv[0] is ProgressBar &&
|
|
object.ReferenceEquals(pv[1], ProgressBar.ValueProperty) &&
|
|
(string)pv[2] == "Could not convert FallbackValue 'bar' to 'System.Double'")
|
|
{
|
|
called = true;
|
|
}
|
|
};
|
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
using (TestLogSink.Start(checkLogMessage))
|
|
{
|
|
var xaml = @"
|
|
<Window xmlns='https://github.com/perspex'>
|
|
<ProgressBar Maximum='10' Value='{Binding Value, FallbackValue=bar}'/>
|
|
</Window>";
|
|
var loader = new PerspexXamlLoader();
|
|
var window = (Window)loader.Load(xaml);
|
|
var progressBar = (ProgressBar)window.Content;
|
|
|
|
window.DataContext = new { Value = "foo" };
|
|
window.ApplyTemplate();
|
|
|
|
Assert.Equal(0, progressBar.Value);
|
|
Assert.True(called);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|