|
1 |
| -//#pragma warning disable IDE0058 // Expression value is never used |
2 |
| - |
3 |
| -//namespace UnitTests; |
4 |
| - |
5 |
| -//public class EventsTests |
6 |
| -//{ |
7 |
| -// private const string SnapshotsDirectory = "Snapshots/Events"; |
8 |
| - |
9 |
| -// [Fact] |
10 |
| -// public async Task SimpleEvents_AssertResults() |
11 |
| -// { |
12 |
| -// var source = """ |
13 |
| -// using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
14 |
| -// namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
15 |
| - |
16 |
| -// [GenerateInterfaceAttribute] |
17 |
| -// public class MyClass : IMyClass |
18 |
| -// { |
19 |
| -// public event EventHandler? MyEvent; |
20 |
| - |
21 |
| -// public void HandEvents() |
22 |
| -// { |
23 |
| -// MyEvent?.Invoke(this, EventArgs.Empty); |
24 |
| -// } |
25 |
| -// } |
26 |
| -// """; |
27 |
| - |
28 |
| -// await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
29 |
| -// } |
30 |
| - |
31 |
| -// [Fact] |
32 |
| -// public async Task ActionEvents_AssertResults() |
33 |
| -// { |
34 |
| -// var source = """ |
35 |
| -// using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
36 |
| -// namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
37 |
| - |
38 |
| -// [GenerateInterfaceAttribute] |
39 |
| -// public class MyClass : IMyClass |
40 |
| -// { |
41 |
| -// public event Action<int>? MyEvent1; |
42 |
| -// public event Action<int, string, double, float, NonDemoClass1>? MyEvent2; |
43 |
| - |
44 |
| -// public void HandEvents() |
45 |
| -// { |
46 |
| -// MyEvent1?.Invoke(1); |
47 |
| -// MyEvent2?.Invoke(1, "2", 3.0, 4.0f, new NonDemoClass1()); |
48 |
| -// } |
49 |
| -// } |
50 |
| -// """; |
51 |
| - |
52 |
| -// await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
53 |
| -// } |
54 |
| - |
55 |
| -// [Fact] |
56 |
| -// public async Task CustomEvents_AssertResults() |
57 |
| -// { |
58 |
| -// var source = """ |
59 |
| -// using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
60 |
| -// namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
61 |
| - |
62 |
| -// public delegate void MyEventDelegate(object sender, EventArgs e); |
| 1 | +#pragma warning disable IDE0058 // Expression value is never used |
| 2 | + |
| 3 | +namespace UnitTests; |
| 4 | + |
| 5 | +public class EventsTests |
| 6 | +{ |
| 7 | + private const string SnapshotsDirectory = "Snapshots/Events"; |
| 8 | + |
| 9 | + [Fact] |
| 10 | + public async Task SimpleEvents_AssertResults() |
| 11 | + { |
| 12 | + var source = """ |
| 13 | + using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
| 14 | + namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
| 15 | +
|
| 16 | + [GenerateInterfaceAttribute] |
| 17 | + public class MyClass : IMyClass |
| 18 | + { |
| 19 | + public event EventHandler? MyEvent; |
| 20 | +
|
| 21 | + public void HandEvents() |
| 22 | + { |
| 23 | + MyEvent?.Invoke(this, EventArgs.Empty); |
| 24 | + } |
| 25 | + } |
| 26 | + """; |
| 27 | + |
| 28 | + await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public async Task ActionEvents_AssertResults() |
| 33 | + { |
| 34 | + var source = """ |
| 35 | + using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
| 36 | + namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
| 37 | +
|
| 38 | + [GenerateInterfaceAttribute] |
| 39 | + public class MyClass : IMyClass |
| 40 | + { |
| 41 | + public event Action<int>? MyEvent1; |
| 42 | + public event Action<int, string, double, float, NonDemoClass1>? MyEvent2; |
| 43 | +
|
| 44 | + public void HandEvents() |
| 45 | + { |
| 46 | + MyEvent1?.Invoke(1); |
| 47 | + MyEvent2?.Invoke(1, "2", 3.0, 4.0f, new NonDemoClass1()); |
| 48 | + } |
| 49 | + } |
| 50 | + """; |
| 51 | + |
| 52 | + await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
| 53 | + } |
| 54 | + |
| 55 | + [Fact] |
| 56 | + public async Task CustomEvents_AssertResults() |
| 57 | + { |
| 58 | + var source = """ |
| 59 | + using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
| 60 | + namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
| 61 | +
|
| 62 | + public delegate void MyEventDelegate(object sender, EventArgs e); |
63 | 63 |
|
64 |
| -// [GenerateInterfaceAttribute] |
65 |
| -// public class MyClass : IMyClass |
66 |
| -// { |
67 |
| -// public event MyEventDelegate MyEvent; |
| 64 | + [GenerateInterfaceAttribute] |
| 65 | + public class MyClass : IMyClass |
| 66 | + { |
| 67 | + public event MyEventDelegate MyEvent; |
68 | 68 |
|
69 |
| -// public void HandEvents() |
70 |
| -// { |
71 |
| -// MyEvent?.Invoke(this, EventArgs.Empty); |
72 |
| -// } |
73 |
| -// } |
74 |
| -// """; |
75 |
| - |
76 |
| -// await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
77 |
| -// } |
78 |
| - |
79 |
| - |
80 |
| -// [Fact] |
81 |
| -// public async Task WithExcludedEvents_AssertResults() |
82 |
| -// { |
83 |
| -// var source = """ |
84 |
| -// using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
85 |
| -// namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
86 |
| - |
87 |
| -// [GenerateInterfaceAttribute] |
88 |
| -// public class MyClass : IMyClass |
89 |
| -// { |
90 |
| -// public event EventHandler? MyEvent; |
| 69 | + public void HandEvents() |
| 70 | + { |
| 71 | + MyEvent?.Invoke(this, EventArgs.Empty); |
| 72 | + } |
| 73 | + } |
| 74 | + """; |
| 75 | + |
| 76 | + await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
| 77 | + } |
| 78 | + |
| 79 | + [Fact] |
| 80 | + public async Task WithExcludedEvents_AssertResults() |
| 81 | + { |
| 82 | + var source = """ |
| 83 | + using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
| 84 | + namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
| 85 | +
|
| 86 | + [GenerateInterfaceAttribute] |
| 87 | + public class MyClass : IMyClass |
| 88 | + { |
| 89 | + public event EventHandler? MyEvent; |
91 | 90 |
|
92 |
| -// [ExcludeFromGeneratedInterface] |
93 |
| -// public event EventHandler? MyEvent2; |
| 91 | + [ExcludeFromGeneratedInterface] |
| 92 | + public event EventHandler? MyEvent2; |
94 | 93 |
|
95 |
| -// [ExcludeFromGeneratedInterfaceAttribute] |
96 |
| -// public event EventHandler? MyEvent3; |
97 |
| - |
98 |
| -// public void HandEvents() |
99 |
| -// { |
100 |
| -// MyEvent?.Invoke(this, EventArgs.Empty); |
101 |
| -// MyEvent2?.Invoke(this, EventArgs.Empty); |
102 |
| -// MyEvent3?.Invoke(this, EventArgs.Empty); |
103 |
| -// } |
104 |
| -// } |
105 |
| -// """; |
106 |
| - |
107 |
| -// await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
108 |
| -// } |
109 |
| - |
110 |
| -// [Fact] |
111 |
| -// public async Task EventWithComments_AssertCommentsAppearInGeneratedInterfaceEvents() |
112 |
| -// { |
113 |
| -// var source = """ |
114 |
| -// using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
115 |
| -// namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
116 |
| - |
117 |
| -// [GenerateInterfaceAttribute] |
118 |
| -// public class MyClass : IMyClass |
119 |
| -// { |
120 |
| -// /// <summary> |
121 |
| -// /// Some comments for my event |
122 |
| -// /// </summary> |
123 |
| -// public event EventHandler? MyEvent; |
124 |
| - |
125 |
| -// /// Single line tripple comment that will appear in generated interface |
126 |
| -// public event EventHandler? MyEvent2; |
127 |
| - |
128 |
| -// //Single line comment that won't appear in generated interface |
129 |
| -// public event EventHandler? MyEvent3; |
| 94 | + [ExcludeFromGeneratedInterfaceAttribute] |
| 95 | + public event EventHandler? MyEvent3; |
| 96 | +
|
| 97 | + public void HandEvents() |
| 98 | + { |
| 99 | + MyEvent?.Invoke(this, EventArgs.Empty); |
| 100 | + MyEvent2?.Invoke(this, EventArgs.Empty); |
| 101 | + MyEvent3?.Invoke(this, EventArgs.Empty); |
| 102 | + } |
| 103 | + } |
| 104 | + """; |
| 105 | + |
| 106 | + await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
| 107 | + } |
| 108 | + |
| 109 | + [Fact] |
| 110 | + public async Task EventWithComments_AssertCommentsAppearInGeneratedInterfaceEvents() |
| 111 | + { |
| 112 | + var source = """ |
| 113 | + using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
| 114 | + namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
| 115 | +
|
| 116 | + [GenerateInterfaceAttribute] |
| 117 | + public class MyClass : IMyClass |
| 118 | + { |
| 119 | + /// <summary> |
| 120 | + /// Some comments for my event |
| 121 | + /// </summary> |
| 122 | + public event EventHandler? MyEvent; |
| 123 | +
|
| 124 | + /// Single line tripple comment that will appear in generated interface |
| 125 | + public event EventHandler? MyEvent2; |
| 126 | +
|
| 127 | + //Single line comment that won't appear in generated interface |
| 128 | + public event EventHandler? MyEvent3; |
130 | 129 |
|
131 |
| -// public void HandEvents() |
132 |
| -// { |
133 |
| -// MyEvent?.Invoke(this, EventArgs.Empty); |
134 |
| -// MyEvent2?.Invoke(this, EventArgs.Empty); |
135 |
| -// } |
136 |
| -// } |
137 |
| -// """; |
138 |
| - |
139 |
| -// await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
140 |
| -// } |
141 |
| - |
142 |
| -// [Fact] |
143 |
| -// public async Task ImplementsInterfaceEvent_AssertEventNotInGeneratedInterface() |
144 |
| -// { |
145 |
| -// var source = """ |
146 |
| -// using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
147 |
| -// namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
148 |
| - |
149 |
| -// public interface IMyInterface |
150 |
| -// { |
151 |
| -// event EventHandler? MyInterfaceEvent; |
152 |
| -// } |
153 |
| - |
154 |
| -// [GenerateInterfaceAttribute] |
155 |
| -// public class MyClass : IMyClass, IMyInterface |
156 |
| -// { |
157 |
| -// public event EventHandler? MyInterfaceEvent; |
158 |
| -// public event EventHandler? MyEvent; |
159 |
| - |
160 |
| -// public void HandEvents() |
161 |
| -// { |
162 |
| -// MyEvent?.Invoke(this, EventArgs.Empty); |
163 |
| -// } |
164 |
| -// } |
165 |
| -// """; |
166 |
| - |
167 |
| -// await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
168 |
| -// } |
169 |
| -//} |
170 |
| -//#pragma warning restore IDE0058 // Expression value is never used |
| 130 | + public void HandEvents() |
| 131 | + { |
| 132 | + MyEvent?.Invoke(this, EventArgs.Empty); |
| 133 | + MyEvent2?.Invoke(this, EventArgs.Empty); |
| 134 | + } |
| 135 | + } |
| 136 | + """; |
| 137 | + |
| 138 | + await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
| 139 | + } |
| 140 | + |
| 141 | + [Fact] |
| 142 | + public async Task ImplementsInterfaceEvent_AssertEventNotInGeneratedInterface() |
| 143 | + { |
| 144 | + var source = """ |
| 145 | + using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes; |
| 146 | + namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.SampleClasses; |
| 147 | +
|
| 148 | + public interface IMyInterface |
| 149 | + { |
| 150 | + event EventHandler? MyInterfaceEvent; |
| 151 | + } |
| 152 | +
|
| 153 | + [GenerateInterfaceAttribute] |
| 154 | + public class MyClass : IMyClass, IMyInterface |
| 155 | + { |
| 156 | + public event EventHandler? MyInterfaceEvent; |
| 157 | + public event EventHandler? MyEvent; |
| 158 | +
|
| 159 | + public void HandEvents() |
| 160 | + { |
| 161 | + MyEvent?.Invoke(this, EventArgs.Empty); |
| 162 | + } |
| 163 | + } |
| 164 | + """; |
| 165 | + |
| 166 | + await TestHelper.VerifyAsync(source, SnapshotsDirectory); |
| 167 | + } |
| 168 | +} |
| 169 | +#pragma warning restore IDE0058 // Expression value is never used |
0 commit comments