ExpressionObserverTests_Negation.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) The Avalonia 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.Reactive.Linq;
  5. using System.Threading.Tasks;
  6. using Avalonia.Data;
  7. using Avalonia.Data.Core;
  8. using Avalonia.Markup.Parsers;
  9. using Xunit;
  10. namespace Avalonia.Base.UnitTests.Data.Core
  11. {
  12. public class ExpressionObserverTests_Negation
  13. {
  14. [Fact]
  15. public async Task Should_Negate_Boolean_Value()
  16. {
  17. var data = new { Foo = true };
  18. var target = ExpressionObserver.Create(data, o => !o.Foo);
  19. var result = await target.Take(1);
  20. Assert.False((bool)result);
  21. GC.KeepAlive(data);
  22. }
  23. [Fact]
  24. public void Can_SetValue_For_Valid_Value()
  25. {
  26. var data = new Test { Foo = true };
  27. var target = ExpressionObserver.Create(data, o => !o.Foo);
  28. target.Subscribe(_ => { });
  29. Assert.True(target.SetValue(true));
  30. Assert.False(data.Foo);
  31. }
  32. private class Test
  33. {
  34. public bool Foo { get; set; }
  35. }
  36. }
  37. }