- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.4k
Fix register/unregister issues of WeakReferenceMessenger #4082
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
Changes from all commits
04977e1
              05d95f8
              928fc47
              0927e56
              805438c
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -511,6 +511,32 @@ void Test() | |
| messenger.Cleanup(); | ||
| } | ||
|  | ||
| // See https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/4081 | ||
| [TestCategory("Mvvm")] | ||
|         
                  steinhilber marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| [TestMethod] | ||
| [DataRow(typeof(StrongReferenceMessenger))] | ||
| [DataRow(typeof(WeakReferenceMessenger))] | ||
| public void Test_Messenger_RegisterMultiple_UnregisterSingle(Type type) | ||
| { | ||
| var messenger = (IMessenger)Activator.CreateInstance(type); | ||
|  | ||
| var recipient1 = new object(); | ||
| var recipient2 = new object(); | ||
|  | ||
| int handler1CalledCount = 0; | ||
| int handler2CalledCount = 0; | ||
|  | ||
| messenger.Register<object, MessageA>(recipient1, (r, m) => { handler1CalledCount++; }); | ||
| messenger.Register<object, MessageA>(recipient2, (r, m) => { handler2CalledCount++; }); | ||
|  | ||
| messenger.UnregisterAll(recipient2); | ||
|  | ||
| messenger.Send(new MessageA()); | ||
|  | ||
| Assert.AreEqual(1, handler1CalledCount); | ||
| Assert.AreEqual(0, handler2CalledCount); | ||
| } | ||
|  | ||
| public sealed class RecipientWithNoMessages | ||
| { | ||
| public int Number { get; set; } | ||
|  | @@ -550,4 +576,4 @@ public sealed class MessageB | |
| { | ||
| } | ||
| } | ||
| } | ||
| } | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michael-hawker Just a note: this is the same issue you had raised as well while reviewing #3893: without some automated process to either fix the formatting or at least validate that the state is kept consistent, it's really really easy to reintroduce differences in whitespace formatting while making changes (especially because VS sometimes applies these changes automatically) and still end up with the same situation we had before. As in, the changes in #3893 aren't really that easily maintainable in the long term right now without still ending up with some inconsistencies here and there by accident 🤔 | ||
Uh oh!
There was an error while loading. Please reload this page.