ExpressionObserverTests_PerspexProperty.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Reactive.Linq;
  6. using Perspex.Markup.Data;
  7. using Xunit;
  8. namespace Perspex.Markup.UnitTests.Data
  9. {
  10. public class ExpressionObserverTests_PerspexProperty
  11. {
  12. public ExpressionObserverTests_PerspexProperty()
  13. {
  14. var foo = Class1.FooProperty;
  15. }
  16. [Fact]
  17. public async void Should_Get_Simple_Property_Value()
  18. {
  19. var data = new Class1();
  20. var target = new ExpressionObserver(data, "Foo");
  21. var result = await target.Take(1);
  22. Assert.Equal("foo", result);
  23. }
  24. [Fact]
  25. public void Should_Track_Simple_Property_Value()
  26. {
  27. var data = new Class1();
  28. var target = new ExpressionObserver(data, "Foo");
  29. var result = new List<object>();
  30. var sub = target.Subscribe(x => result.Add(x));
  31. data.SetValue(Class1.FooProperty, "bar");
  32. Assert.Equal(new[] { "foo", "bar" }, result);
  33. sub.Dispose();
  34. }
  35. private class Class1 : PerspexObject
  36. {
  37. public static readonly PerspexProperty<string> FooProperty =
  38. PerspexProperty.Register<Class1, string>("Foo", defaultValue: "foo");
  39. }
  40. }
  41. }