|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
5 | 5 | using System;
|
| 6 | +using System.Linq; |
| 7 | +using System.Reflection; |
6 | 8 | using CommunityToolkit.Mvvm.Messaging;
|
7 | 9 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
8 | 10 |
|
@@ -52,9 +54,20 @@ public void Test_IRecipientGenerator_TypeWithMultipleClassDeclarations()
|
52 | 54 | _ = Messaging.__Internals.__IMessengerExtensions.CreateAllMessagesRegistratorWithToken<int>(recipient);
|
53 | 55 | }
|
54 | 56 |
|
55 |
| - public sealed class RecipientWithSomeMessages : |
56 |
| - IRecipient<MessageA>, |
57 |
| - IRecipient<MessageB> |
| 57 | + [TestMethod] |
| 58 | + public void Test_IRecipientGenerator_AbstractTypesDoNotTriggerCodeGeneration() |
| 59 | + { |
| 60 | + MethodInfo? createAllPropertiesValidatorMethod = typeof(Messaging.__Internals.__IMessengerExtensions) |
| 61 | + .GetMethods(BindingFlags.Static | BindingFlags.Public) |
| 62 | + .Where(static m => m.Name == "CreateAllMessagesRegistratorWithToken") |
| 63 | + .Where(static m => m.GetParameters() is { Length: 1 } parameters && parameters[0].ParameterType == typeof(AbstractModelWithValidatablePropertyIRecipientInterfaces)) |
| 64 | + .FirstOrDefault(); |
| 65 | + |
| 66 | + // We need to validate that no methods are generated for abstract types, so we just check this method doesn't exist |
| 67 | + Assert.IsNull(createAllPropertiesValidatorMethod); |
| 68 | + } |
| 69 | + |
| 70 | + public sealed class RecipientWithSomeMessages : IRecipient<MessageA>, IRecipient<MessageB> |
58 | 71 | {
|
59 | 72 | public MessageA? A { get; private set; }
|
60 | 73 |
|
@@ -91,4 +104,14 @@ public void Receive(MessageA message)
|
91 | 104 | partial class RecipientWithMultipleClassDeclarations
|
92 | 105 | {
|
93 | 106 | }
|
| 107 | + |
| 108 | + public abstract class AbstractModelWithValidatablePropertyIRecipientInterfaces : IRecipient<MessageA>, IRecipient<MessageB> |
| 109 | + { |
| 110 | + public abstract void Receive(MessageA message); |
| 111 | + |
| 112 | + public void Receive(MessageB message) |
| 113 | + { |
| 114 | + |
| 115 | + } |
| 116 | + } |
94 | 117 | }
|
0 commit comments