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.
69 lines
2.1 KiB
69 lines
2.1 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.Reactive.Linq;
|
|
using System.Reactive.Subjects;
|
|
using Perspex.Markup.Data;
|
|
using Perspex.UnitTests;
|
|
using Xunit;
|
|
|
|
namespace Perspex.Markup.UnitTests.Data
|
|
{
|
|
public class ExpressionObserverTests_Observable
|
|
{
|
|
[Fact]
|
|
public void Should_Get_Simple_Observable_Value()
|
|
{
|
|
using (var sync = UnitTestSynchronizationContext.Begin())
|
|
{
|
|
var source = new BehaviorSubject<string>("foo");
|
|
var data = new { Foo = source };
|
|
var target = new ExpressionObserver(data, "Foo");
|
|
var result = new List<object>();
|
|
|
|
var sub = target.Subscribe(x => result.Add(x));
|
|
source.OnNext("bar");
|
|
sync.ExecutePostedCallbacks();
|
|
|
|
Assert.Equal(new[] { PerspexProperty.UnsetValue, "foo", "bar" }, result);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Get_Property_Value_From_Observable()
|
|
{
|
|
using (var sync = UnitTestSynchronizationContext.Begin())
|
|
{
|
|
var data = new Class1();
|
|
var target = new ExpressionObserver(data, "Next.Foo");
|
|
var result = new List<object>();
|
|
|
|
var sub = target.Subscribe(x => result.Add(x));
|
|
data.Next.OnNext(new Class2("foo"));
|
|
sync.ExecutePostedCallbacks();
|
|
|
|
Assert.Equal(new[] { PerspexProperty.UnsetValue, "foo" }, result);
|
|
|
|
sub.Dispose();
|
|
Assert.Equal(0, data.SubscriptionCount);
|
|
}
|
|
}
|
|
|
|
private class Class1 : NotifyingBase
|
|
{
|
|
public Subject<Class2> Next { get; } = new Subject<Class2>();
|
|
}
|
|
|
|
private class Class2 : NotifyingBase
|
|
{
|
|
public Class2(string foo)
|
|
{
|
|
Foo = foo;
|
|
}
|
|
|
|
public string Foo { get; }
|
|
}
|
|
}
|
|
}
|
|
|