1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System . Drawing ;
55using System . Reflection . Metadata ;
6- using System . Text . RegularExpressions ;
76using System . Windows . Forms . TestUtilities ;
87using Com = Windows . Win32 . System . Com ;
98
109namespace System . Windows . Forms . Tests ;
1110
1211public unsafe partial class NativeToWinFormsAdapterTests
1312{
14- [ GeneratedRegex ( @"{[0-9]}" ) ]
15- private static partial Regex PlaceholdersPattern ( ) ;
16-
17- private static string InvalidTypeFormatCombinationMessage =>
18- PlaceholdersPattern ( ) . Replace ( SR . ClipboardOrDragDrop_InvalidFormatTypeCombination , "*" ) ;
19- private static string TypeRequiresResolverMessage => PlaceholdersPattern ( ) . Replace ( SR . ClipboardOrDragDrop_InvalidType , "*" ) ;
20- private static string UseTryGetDataWithResolver => PlaceholdersPattern ( ) . Replace ( SR . ClipboardOrDragDrop_UseTypedAPI , "*" ) ;
21-
2213 private const string FormatterDisabledMessage =
2314 "BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information." ;
2415
@@ -58,7 +49,7 @@ public void TryGetData_AsObject_Primitive_RequiresResolver(string format)
5849 DataObject dataObject = new ( comDataObject . Value ) ;
5950
6051 Action tryGetData = ( ) => dataObject . TryGetData ( format , out object ? value ) ;
61- tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : TypeRequiresResolverMessage ) ;
52+ tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : ResourceStrings . TypeRequiresResolver ) ;
6253
6354 dataObject . TryGetData ( format , Resolver , autoConvert : false , out object ? value ) . Should ( ) . BeTrue ( ) ;
6455 value . Should ( ) . Be ( 1 ) ;
@@ -79,7 +70,7 @@ public void TryGetData_AsObject_Primitive_InvalidTypeFormatCombination(string fo
7970 // Throw when validating arguments, as these formats allow exactly strings or bitmaps only.
8071 Action tryGetData = ( ) => dataObject . TryGetData ( format , out object ? _ ) ;
8172 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
82- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
73+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
8374 }
8475
8576 private static ( DataObject dataObject , TestData value ) SetDataObject ( string format )
@@ -101,7 +92,7 @@ public void TryGetData_AsObject_Custom_RequiresResolver(string format)
10192 ( DataObject dataObject , TestData _ ) = SetDataObject ( format ) ;
10293 Action tryGetData = ( ) => dataObject . TryGetData ( format , out object ? _ ) ;
10394
104- tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : TypeRequiresResolverMessage ) ;
95+ tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : ResourceStrings . TypeRequiresResolver ) ;
10596 }
10697
10798 [ WinFormsTheory ]
@@ -114,7 +105,7 @@ public void TryGetData_AsObject_Custom_FormatterEnabled_RequiresResolver(string
114105 using BinaryFormatterScope scope = new ( enable : true ) ;
115106 using BinaryFormatterInClipboardDragDropScope clipboardScope = new ( enable : true ) ;
116107
117- tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : TypeRequiresResolverMessage ) ;
108+ tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : ResourceStrings . TypeRequiresResolver ) ;
118109 }
119110
120111 [ WinFormsTheory ]
@@ -127,7 +118,7 @@ public void TryGetData_AsObject_Custom_InvalidTypeFormatCombination(string forma
127118
128119 // Type-Format combination is validated before the we attempt to serialize data.
129120 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
130- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
121+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
131122 }
132123
133124 [ WinFormsTheory ]
@@ -180,7 +171,7 @@ public void TryGetData_AsInterface_ListOfPrimitives_RequiresResolver(string form
180171 // Theoretically we don't require a resolver here, but this is an exception. In the more common cases resolver
181172 // is required to instantiate non-concrete types.
182173 Action tryGetData = ( ) => dataObject . TryGetData ( format , out IList < int > ? _ ) ;
183- tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : TypeRequiresResolverMessage ) ;
174+ tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : ResourceStrings . TypeRequiresResolver ) ;
184175 }
185176
186177 [ WinFormsTheory ]
@@ -196,7 +187,7 @@ public void TryGetData_AsInterface_ListOfPrimitives_InvalidTypeFormatCombination
196187
197188 Action tryGetData = ( ) => dataObject . TryGetData ( format , out IList < int > ? _ ) ;
198189 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
199- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
190+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
200191 }
201192
202193 [ WinFormsTheory ]
@@ -227,7 +218,7 @@ public void TryGetData_AsConcreteType_ListOfPrimitives_InvalidTypeFormatCombinat
227218
228219 Action tryGetData = ( ) => dataObject . TryGetData ( format , out List < int > ? _ ) ;
229220 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
230- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
221+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
231222 }
232223
233224 [ WinFormsTheory ]
@@ -277,7 +268,7 @@ public void TryGetData_AsConcreteType_Custom_InvalidTypeFormatCombination(string
277268
278269 Action tryGetData = ( ) => dataObject . TryGetData ( format , out TestData ? _ ) ;
279270 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
280- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
271+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
281272 }
282273
283274 [ WinFormsTheory ]
@@ -302,7 +293,7 @@ public void TryGetData_WithResolver_AsConcreteType_Custom_InvalidTypeFormatCombi
302293 Action tryGetData = ( ) => dataObject . TryGetData ( format , TestData . Resolver , autoConvert : true , out TestData ? _ ) ;
303294
304295 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
305- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
296+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
306297 }
307298
308299 [ WinFormsTheory ]
@@ -317,7 +308,7 @@ public void TryGetData_WithResolver_AsConcreteType_Custom_FormatterEnabled_Inval
317308 using BinaryFormatterInClipboardDragDropScope clipboardScope = new ( enable : true ) ;
318309
319310 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
320- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
311+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
321312 }
322313
323314 [ WinFormsTheory ]
@@ -354,7 +345,7 @@ public void TryGetData_AsAbstract_Custom_InvalidTypeFormatCombination(string for
354345
355346 Action tryGetData = ( ) => dataObject . TryGetData ( format , out AbstractBase ? _ ) ;
356347 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
357- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
348+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
358349 }
359350
360351 [ WinFormsTheory ]
@@ -364,7 +355,7 @@ public void TryGetData_AsAbstract_Custom_RequiresResolver(string format)
364355 ( DataObject dataObject , TestData _ ) = SetDataObject ( format ) ;
365356 Action tryGetData = ( ) => dataObject . TryGetData ( format , out AbstractBase ? _ ) ;
366357
367- tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : TypeRequiresResolverMessage ) ;
358+ tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : ResourceStrings . TypeRequiresResolver ) ;
368359
369360 dataObject . TryGetData ( format , out NotSupportedException ? ex ) . Should ( ) . BeTrue ( ) ;
370361 ex . Should ( ) . BeOfType < NotSupportedException > ( ) . Which . Message . Should ( ) . Be ( FormatterDisabledMessage ) ;
@@ -380,7 +371,7 @@ public void TryGetData_AsAbstract_Custom_FormatterEnabled_RequiresResolver(strin
380371 using BinaryFormatterScope scope = new ( enable : true ) ;
381372 using BinaryFormatterInClipboardDragDropScope clipboardScope = new ( enable : true ) ;
382373
383- tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : TypeRequiresResolverMessage ) ;
374+ tryGetData . Should ( ) . Throw < NotSupportedException > ( ) . WithMessage ( expectedWildcardPattern : ResourceStrings . TypeRequiresResolver ) ;
384375 }
385376
386377 [ WinFormsTheory ]
@@ -420,7 +411,7 @@ public void TryGetData_WithResolver_AsAbstract_Custom_InvalidTypeFormatCombinati
420411 // Nothing is written to HGLOBAL in this test because format-type combination is invalid.
421412 Action tryGetData = ( ) => dataObject . TryGetData ( format , TestData . Resolver , autoConvert : true , out AbstractBase ? _ ) ;
422413 tryGetData . Should ( ) . Throw < NotSupportedException > ( )
423- . WithMessage ( expectedWildcardPattern : InvalidTypeFormatCombinationMessage ) ;
414+ . WithMessage ( expectedWildcardPattern : ResourceStrings . InvalidTypeFormatCombinationMessage ) ;
424415 }
425416
426417 [ WinFormsTheory ]
0 commit comments