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.
80 lines
2.5 KiB
80 lines
2.5 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 System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Reactive.Linq;
|
|
using Moq;
|
|
using Perspex.Controls;
|
|
using Perspex.Markup.Xaml.Data;
|
|
using Xunit;
|
|
|
|
namespace Perspex.Markup.Xaml.UnitTests.Data
|
|
{
|
|
public class MultiBindingTests
|
|
{
|
|
[Fact]
|
|
public async void OneWay_Binding_Should_Be_Set_Up()
|
|
{
|
|
var source = new { A = 1, B = 2, C = 3 };
|
|
var binding = new MultiBinding
|
|
{
|
|
Converter = new ConcatConverter(),
|
|
Bindings = new[]
|
|
{
|
|
new Binding { Path = "A" },
|
|
new Binding { Path = "B" },
|
|
new Binding { Path = "C" },
|
|
}
|
|
};
|
|
|
|
var target = new Mock<IPerspexObject>();
|
|
target.Setup(x => x.GetValue(Control.DataContextProperty)).Returns(source);
|
|
|
|
var subject = binding.CreateSubject(target.Object, null);
|
|
var result = await subject.Take(1);
|
|
|
|
Assert.Equal("1,2,3", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Return_FallbackValue_When_Converter_Returns_UnsetValue()
|
|
{
|
|
var target = new TextBlock();
|
|
var source = new { A = 1, B = 2, C = 3 };
|
|
var binding = new MultiBinding
|
|
{
|
|
Converter = new UnsetValueConverter(),
|
|
Bindings = new[]
|
|
{
|
|
new Binding { Path = "A" },
|
|
new Binding { Path = "B" },
|
|
new Binding { Path = "C" },
|
|
},
|
|
FallbackValue = "fallback",
|
|
};
|
|
|
|
target.Bind(TextBlock.TextProperty, binding);
|
|
|
|
Assert.Equal("fallback", target.Text);
|
|
}
|
|
|
|
private class ConcatConverter : IMultiValueConverter
|
|
{
|
|
public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return string.Join(",", values);
|
|
}
|
|
}
|
|
|
|
private class UnsetValueConverter : IMultiValueConverter
|
|
{
|
|
public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return PerspexProperty.UnsetValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|