-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for ObservableExtensions
- Loading branch information
1 parent
fe74aac
commit 82be71c
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/Avalonia/Prism.Avalonia.Tests/Interactivity/ObservableBehaviorFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Avalonia; | ||
using Xunit; | ||
using Prism.Extensions; | ||
|
||
namespace Prism.Avalonia.Tests.Interactivity | ||
{ | ||
public class ObservableBehaviorFixture | ||
{ | ||
[Fact] | ||
public void SubscribeWorksOnIObservableWithLambda() | ||
{ | ||
var targetUIElement = new TestAvaloniaObject(); | ||
targetUIElement.Test = "123"; | ||
|
||
Assert.Equal("123", targetUIElement.OutTest); | ||
} | ||
} | ||
|
||
class TestAvaloniaObject : AvaloniaObject | ||
{ | ||
/// <summary> | ||
/// The property to subscribe on. | ||
/// </summary> | ||
public static readonly StyledProperty<string> TestProperty = | ||
AvaloniaProperty.Register<TestAvaloniaObject, string>("Test"); | ||
|
||
/// <summary> | ||
/// Gets or sets a value to the TestProperty. | ||
/// </summary> | ||
public string Test | ||
{ | ||
get { return (string)GetValue(TestProperty); } | ||
set { SetValue(TestProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// The out test property to check after TestProperty change | ||
/// </summary> | ||
public string OutTest { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="TestAvaloniaObject"/>. | ||
/// </summary> | ||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
public TestAvaloniaObject() | ||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
{ | ||
TestProperty.Changed.Subscribe(args => OnPropertyChanged(args)); | ||
} | ||
|
||
private void OnPropertyChanged(AvaloniaPropertyChangedEventArgs<string> args) | ||
{ | ||
OutTest = args.NewValue.Value; | ||
} | ||
} | ||
} |