-
Notifications
You must be signed in to change notification settings - Fork 29
/
Interface_method_attributes.cs
222 lines (201 loc) · 7.02 KB
/
Interface_method_attributes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using PublicApiGenerator;
using PublicApiGeneratorTests.Examples;
using Xunit;
namespace PublicApiGeneratorTests
{
public class Interface_method_attributes : ApiGeneratorTestsBase
{
[Fact]
public void Should_add_attribute_with_no_parameters()
{
AssertPublicApi<IMethodWithSimpleAttribute>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodWithSimpleAttribute
{
[PublicApiGeneratorTests.Examples.Simple]
void Method();
}
}");
}
[Fact]
public void Should_add_attribute_with_positional_parameters()
{
AssertPublicApi<IMethodsWithAttributeWithPositionalParameters>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodsWithAttributeWithPositionalParameters
{
[PublicApiGeneratorTests.Examples.AttributeWithPositionalParameters1(""Hello"")]
void Method1();
[PublicApiGeneratorTests.Examples.AttributeWithPositionalParameters2(42)]
void Method2();
[PublicApiGeneratorTests.Examples.AttributeWithMultiplePositionalParameters(42, ""Hello world"")]
void Method3();
}
}");
}
[Fact]
public void Should_add_attribute_with_named_parameters()
{
AssertPublicApi<IMethodsWithAttributeWithNamedParameters>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodsWithAttributeWithNamedParameters
{
[PublicApiGeneratorTests.Examples.AttributeWithNamedParameter(StringValue=""Hello"")]
void Method1();
[PublicApiGeneratorTests.Examples.AttributeWithNamedParameter(IntValue=42)]
void Method2();
}
}");
}
[Fact]
public void Should_add_multiple_named_parameters_in_alphabetical_order()
{
AssertPublicApi<IMethodWithAttributeWithMultipleNamedParameters>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodWithAttributeWithMultipleNamedParameters
{
[PublicApiGeneratorTests.Examples.AttributeWithNamedParameter(IntValue=42, StringValue=""Hello world"")]
void Method();
}
}");
}
[Fact]
public void Should_add_attribute_with_both_named_and_positional_parameters()
{
AssertPublicApi<IMethodWithAttributeWithBothNamedAndPositionalParameters>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodWithAttributeWithBothNamedAndPositionalParameters
{
[PublicApiGeneratorTests.Examples.AttributeWithNamedAndPositionalParameter(42, ""Hello world"", IntValue=13, StringValue=""Thingy"")]
void Method();
}
}");
}
[Fact]
public void Should_expand_enum_flags()
{
AssertPublicApi<IMethodWithAttributeWithEnumFlags>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodWithAttributeWithEnumFlags
{
[PublicApiGeneratorTests.Examples.AttributeWithEnumFlags(PublicApiGeneratorTests.Examples.EnumWithFlags.One | PublicApiGeneratorTests.Examples.EnumWithFlags.Two | PublicApiGeneratorTests.Examples.EnumWithFlags.Three)]
void Method();
}
}");
}
[Fact]
public void Should_handle_typeof_argument()
{
AssertPublicApi<IMethodWithAttributeWithType>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodWithAttributeWithType
{
[PublicApiGeneratorTests.Examples.AttributeWithTypeParameter(typeof(string))]
void Method1();
[PublicApiGeneratorTests.Examples.AttributeWithTypeParameter(typeof(PublicApiGeneratorTests.Examples.ComplexType))]
void Method2();
[PublicApiGeneratorTests.Examples.AttributeWithTypeParameter(typeof(PublicApiGeneratorTests.Examples.GenericType<PublicApiGeneratorTests.Examples.ComplexType>))]
void Method3();
}
}");
}
[Fact]
public void Should_add_multiple_attributes_in_alphabetical_order()
{
AssertPublicApi<IMethodWithMultipleAttributes>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodWithMultipleAttributes
{
[PublicApiGeneratorTests.Examples.Attribute_AA]
[PublicApiGeneratorTests.Examples.Attribute_MM]
[PublicApiGeneratorTests.Examples.Attribute_ZZ]
void Method();
}
}");
}
[Fact]
public void Should_skip_excluded_attribute()
{
var options = new DefaultApiGeneratorOptions
{
ExcludeAttributes = new[] { "PublicApiGeneratorTests.Examples.AttributeWithNamedParameterAttribute" }
};
AssertPublicApi<IMethodsWithAttributeWithNamedParameters>(
@"namespace PublicApiGeneratorTests.Examples
{
public interface IMethodsWithAttributeWithNamedParameters
{
void Method1();
void Method2();
}
}", options);
}
}
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Examples
{
public interface IMethodWithSimpleAttribute
{
[SimpleAttribute]
void Method();
}
public interface IMethodsWithAttributeWithPositionalParameters
{
[AttributeWithPositionalParameters1("Hello")]
void Method1();
[AttributeWithPositionalParameters2(42)]
void Method2();
[AttributeWithMultiplePositionalParameters(42, "Hello world")]
void Method3();
}
public interface IMethodsWithAttributeWithNamedParameters
{
[AttributeWithNamedParameter(StringValue = "Hello")]
void Method1();
[AttributeWithNamedParameter(IntValue = 42)]
void Method2();
}
public interface IMethodWithAttributeWithMultipleNamedParameters
{
[AttributeWithNamedParameter(StringValue = "Hello world", IntValue = 42)]
void Method();
}
public interface IMethodWithAttributeWithBothNamedAndPositionalParameters
{
[AttributeWithNamedAndPositionalParameter(42, "Hello world", StringValue = "Thingy", IntValue = 13)]
void Method();
}
public interface IMethodWithAttributeWithEnumFlags
{
[AttributeWithEnumFlags(EnumWithFlags.One | EnumWithFlags.Two | EnumWithFlags.Three)]
void Method();
}
public interface IMethodWithAttributeWithType
{
[AttributeWithTypeParameterAttribute(typeof(string))]
void Method1();
[AttributeWithTypeParameterAttribute(typeof(ComplexType))]
void Method2();
[AttributeWithTypeParameterAttribute(typeof(GenericType<ComplexType>))]
void Method3();
}
public interface IMethodWithMultipleAttributes
{
[Attribute_ZZ]
[Attribute_MM]
[Attribute_AA]
void Method();
}
}
// ReSharper restore ClassNeverInstantiated.Global
// ReSharper restore UnusedMember.Global
}