Skip to content

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackAndDie committed Feb 14, 2024
1 parent fe74aac commit 9ef26ec
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Prism.Avalonia/Extensions/ObservableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Prism.Extensions
{
internal static class ObservableExtensions
public static class ObservableExtensions
{
/// <summary>
/// Subscribes an element handler to an observable sequence.
Expand Down
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;
}
}
}

0 comments on commit 9ef26ec

Please sign in to comment.