-
Notifications
You must be signed in to change notification settings - Fork 496
Enable developers to inherit from BaseBehavior and BaseConverter again #2573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bijington
merged 9 commits into
main
from
feature/sl-open-up-converters-and-behavior-base-classes
Mar 21, 2025
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
126eda2
Enable developers to inherit from BaseBehavior and BaseConverter again
bijington ad0c252
Merge branch 'main' into feature/sl-open-up-converters-and-behavior-b…
bijington 05fa6a8
Merge branch 'main' into feature/sl-open-up-converters-and-behavior-b…
TheCodeTraveler cc6a599
Introduce some unit tests to cover BaseConverter and BaseConverterOneWay
bijington 317b249
Merge branch 'feature/sl-open-up-converters-and-behavior-base-classes…
bijington edc5c5c
Merge branch 'main' into feature/sl-open-up-converters-and-behavior-b…
bijington 4e7194a
Merge branch 'main' into feature/sl-open-up-converters-and-behavior-b…
bijington 573c774
Add some convert back tests
bijington 86b0ad7
Merge branch 'main' into feature/sl-open-up-converters-and-behavior-b…
bijington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/CommunityToolkit.Maui.UnitTests/Behaviors/BaseBehaviorTests.cs
This file contains hidden or 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,47 @@ | ||
| using CommunityToolkit.Maui.UnitTests.Mocks; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace CommunityToolkit.Maui.UnitTests.Behaviors; | ||
|
|
||
| public class BaseBehaviorTests | ||
| { | ||
| [Fact] | ||
| public void AttachAndDetachCallsShouldCorrectlyAssignView() | ||
| { | ||
| var label = new Label(); | ||
| var mockBehavior = new MockBehavior(); | ||
|
|
||
| mockBehavior.AssertViewIsNull(); | ||
| mockBehavior.IsAttached.Should().BeFalse(); | ||
|
|
||
| label.Behaviors.Add(mockBehavior); | ||
|
|
||
| mockBehavior.AssertViewIsEqual(label); | ||
| mockBehavior.IsAttached.Should().BeTrue(); | ||
|
|
||
| label.Behaviors.Remove(mockBehavior); | ||
|
|
||
| mockBehavior.AssertViewIsNull(); | ||
| mockBehavior.IsAttached.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ViewPropertyChangesShouldBeHandledWithinBehavior() | ||
| { | ||
| var label = new Label(); | ||
| var mockBehavior = new MockBehavior(); | ||
|
|
||
| label.Behaviors.Add(mockBehavior); | ||
|
|
||
| mockBehavior.PropertyChanges.Should().BeEmpty(); | ||
|
|
||
| label.Text = "Text"; | ||
|
|
||
| mockBehavior.PropertyChanges.Should().ContainSingle(); | ||
| var change = mockBehavior.PropertyChanges.Single(); | ||
|
|
||
| change.Should().NotBeNull(); | ||
| change.PropertyName.Should().Be(nameof(Label.Text)); | ||
| } | ||
| } |
This file contains hidden or 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,35 @@ | ||
| using System.ComponentModel; | ||
| using CommunityToolkit.Maui.Behaviors; | ||
| using FluentAssertions; | ||
|
|
||
| namespace CommunityToolkit.Maui.UnitTests.Mocks; | ||
|
|
||
| public class MockBehavior : BaseBehavior<Label> | ||
| { | ||
| internal bool IsAttached { get; private set; } | ||
|
|
||
| protected override void OnAttachedTo(Label bindable) | ||
| { | ||
| base.OnAttachedTo(bindable); | ||
| IsAttached = true; | ||
| } | ||
|
|
||
| protected override void OnDetachingFrom(Label bindable) | ||
| { | ||
| base.OnDetachingFrom(bindable); | ||
| IsAttached = false; | ||
| } | ||
|
|
||
| internal void AssertViewIsEqual(Label label) => View.Should().Be(label); | ||
|
|
||
| internal void AssertViewIsNull() => View.Should().BeNull(); | ||
|
|
||
| protected override void OnViewPropertyChanged(Label sender, PropertyChangedEventArgs e) | ||
| { | ||
| base.OnViewPropertyChanged(sender, e); | ||
|
|
||
| PropertyChanges.Add(e); | ||
| } | ||
|
|
||
| internal List<PropertyChangedEventArgs> PropertyChanges { get; } = []; | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.