From 65f897bc43dd631fac10cecf0571e3d5db782e4f Mon Sep 17 00:00:00 2001 From: Jeremy Kuhne Date: Tue, 5 Nov 2024 17:30:07 -0800 Subject: [PATCH] Move settings into .editorconfig (#12426) Our code styles were in a number of files. Consolodate into .editorconfig for discoverability. I've also tried to deviate as little as possible in tests. This required fixing a number of analyzer issues in test code. Also add some more build related solution folders for clarity and discoverability. --- .editorconfig | 1968 +++++++++++++++-- Winforms.sln | 35 +- eng/CodeAnalysis.src.globalconfig | 1751 --------------- eng/CodeAnalysis.test.globalconfig | 459 ---- eng/CodeStyle.targets | 16 +- eng/stylecop.json | 9 - .../tests/TestUtilities/CommonTestHelper.cs | 4 +- .../tests/TestUtilities/DebuggerAttributes.cs | 2 +- .../tests/TestUtilities/NativeAssert.cs | 11 + .../tests/TestUtilities/ReflectionHelper.cs | 2 +- .../tests/TestUtilities/TestAccessors.cs | 8 +- .../tests/TestUtilities/XUnit/TestData.cs | 1 - .../System/Windows/Forms/TimeTests.vb | 2 +- .../TestUtilities/VbFileCleanupTestBase.vb | 4 +- .../VisualBasic/Devices/AudioTests.cs | 2 +- .../VisualBasic/Devices/ComputerInfoTests.cs | 2 +- .../Logging/FileLogTraceListenerTests.cs | 2 +- src/System.Drawing.Common/tests/Helpers.cs | 2 +- .../tests/System/Drawing/BitmapTests.cs | 12 +- .../Drawing/BufferedGraphicsContextTests.cs | 4 +- .../System/Drawing/CharacterRangeTests.cs | 2 +- .../System/Drawing/ColorTranslatorTests.cs | 4 +- .../Drawing/Drawing2D/CustomLineCapTests.cs | 2 +- .../Drawing2D/GraphicsPathIteratorTests.cs | 6 +- .../Drawing/Drawing2D/GraphicsPathTests.cs | 72 +- .../Drawing/Drawing2D/HatchBrushTests.cs | 8 +- .../Drawing2D/LinearGradientBrushTests.cs | 20 +- .../System/Drawing/Drawing2D/MatrixTests.cs | 22 +- .../Drawing2D/PathGradientBrushTests.cs | 24 +- .../tests/System/Drawing/FontTests.cs | 4 +- .../tests/System/Drawing/GraphicsTests.cs | 24 +- .../tests/System/Drawing/IconTests.cs | 8 +- .../System/Drawing/Imaging/ColorMapTests.cs | 4 +- .../Drawing/Imaging/ColorMatrixTests.cs | 6 +- .../Drawing/Imaging/Effects/EffectsTests.cs | 2 +- .../Drawing/Imaging/ImageAttributesTests.cs | 18 +- .../Drawing/Imaging/ImageCodecInfoTests.cs | 2 +- .../Drawing/Imaging/ImageFormatTests.cs | 6 +- .../System/Drawing/Imaging/MetafileTests.cs | 10 +- .../Drawing/Imaging/PropertyItemTests.cs | 2 +- .../tests/System/Drawing/PenTests.cs | 6 +- .../System/Drawing/Printing/MarginsTests.cs | 2 +- .../Drawing/Printing/PageSettingsTests.cs | 2 +- .../Drawing/Printing/PaperSourceTests.cs | 2 +- .../Drawing/Printing/PrintDocumentTests.cs | 4 +- .../Printing/PrinterResolutionTests.cs | 2 +- .../Drawing/Printing/PrinterSettingsTests.cs | 2 +- .../Printing/PrinterUnitConvertTests.cs | 2 +- .../tests/System/Drawing/RegionTests.cs | 26 +- .../tests/System/Drawing/SolidBrushTests.cs | 10 +- .../tests/System/Drawing/StringFormatTests.cs | 4 +- .../tests/System/Drawing/SystemFontsTests.cs | 4 +- .../tests/System/Drawing/SystemPensTest.cs | 2 +- .../tests/System/Drawing/TextureBrushTests.cs | 4 +- .../System.Drawing.Imaging/BmpCodecTests.cs | 2 +- .../System.Drawing.Imaging/GifCodecTests.cs | 2 +- .../System.Drawing.Imaging/IconCodecTests.cs | 54 +- .../System.Drawing.Imaging/JpegCodecTests.cs | 4 +- .../System.Drawing.Imaging/PngCodecTests.cs | 4 +- .../System.Drawing.Imaging/TiffCodecTests.cs | 2 +- .../tests/mono/System.Drawing/BitmapTests.cs | 16 +- .../mono/System.Drawing/GraphicsTests.cs | 62 +- .../tests/mono/System.Imaging/MetafileTest.cs | 6 +- .../BinaryFormatWriterTests.cs | 6 +- .../FormattedObject/HashTableTests.cs | 4 +- .../FormatTests/FormattedObject/ListTests.cs | 2 +- .../System/Value/StoringNull.cs | 2 +- .../ProjectFileReaderTests.FontConverter.cs | 38 +- .../tests/UnitTests/TestAdditionalText.cs | 1 - .../ResourceCodeDomSerializer.cs | 8 +- .../Forms/Design/AnchorEditor.AnchorUI.cs | 2 +- ...lboxSnapDragDropEventArgs.SnapDirection.cs | 10 +- .../Windows/Forms/Design/DocumentDesigner.cs | 13 +- .../FolderNameEditor.FolderBrowserStyles.cs | 14 +- ...ageListDesigner.OriginalImageCollection.cs | 4 +- .../tests/UnitTests/CodeDomHelpers.cs | 2 +- .../tests/UnitTests/ControlDesignerTests.cs | 6 +- .../tests/UnitTests/GlobalSuppressions.cs | 6 +- .../tests/UnitTests/Mocks/MockSite.cs | 5 +- .../UnitTests/SplitContainerDesignerTests.cs | 4 +- .../ComponentModel/Design/ArrayEditorTests.cs | 3 +- .../Design/CollectionEditorTests.cs | 10 +- .../Design/ComponentDesignerTests.cs | 8 +- .../Design/DesignSurfaceTests.cs | 4 +- .../Design/DesignerActionMethodItemTests.cs | 8 +- .../Design/DesignerHostTests.cs | 14 +- .../Design/ExceptionCollectionTests.cs | 4 +- ...deDomComponentSerializationServiceTests.cs | 104 +- .../CodeDomSerializerExceptionTests.cs | 2 +- .../DesignerSerializationManagerTests.cs | 2 +- .../System/Drawing/Design/ToolboxItemTests.cs | 2 +- .../Windows/Forms/Design/AxImporterTests.cs | 1 - .../Forms/Design/BaseContextMenuStripTests.cs | 2 +- .../Design/CollectionEditVerbManagerTests.cs | 1 - .../Forms/Design/DesignBindingTests.cs | 12 +- .../Forms/Design/DesignerExtendersTests.cs | 2 +- .../Forms/Design/FormatStringDialogTests.cs | 4 +- .../Design/GroupedContextMenuStripTests.cs | 6 +- .../Forms/Design/ListBoxDesignerTests.cs | 2 +- .../Design/MaskDescriptorComparerTests.cs | 2 +- .../MaskedTextBoxTextEditorDropDownTests.cs | 2 +- .../Forms/Design/PictureBoxActionListTests.cs | 1 - .../Forms/Design/TabControlDesignerTests.cs | 250 +-- .../tests/UnitTests/ToolStripDesignerTests.cs | 2 +- .../ToolStripDropDownItemDesignerTest.cs | 3 +- .../ToolStripMenuItemDesignerTest.cs | 2 +- .../PInvoke.SetThreadDpiAwarenessContext.cs | 2 +- .../Validators/RepeatValidatorTests.cs | 4 +- .../TestUtilities.Tests/PathLengthTests.cs | 10 +- .../Metafiles/EmfValidateHelper.cs | 1 - .../Metafiles/RecordTypes/EMRPOLYPOLY16.cs | 2 +- .../Metafiles/Validators/EmfValidator.cs | 96 +- .../tests/TestUtilities/ModuleInitializer.cs | 2 +- .../PlatformDetection.Windows.cs | 8 +- .../Interop/ComCtl32/MCGRIDINFOTests.cs | 4 +- .../TASKDIALOGCONFIGIconUnionTests.cs | 4 +- .../Interop/ComCtl32/TASKDIALOGCONFIGTests.cs | 6 +- .../ComCtl32/TASKDIALOG_BUTTONTests.cs | 4 +- .../Interop/Comdlg32/PRINTDLGWTests.cs | 4 +- .../Interop/Kernel32/FILETIMETests.cs | 2 +- .../Interop/Kernel32/SYSTEMTIMETests.cs | 4 +- .../UnitTests/Interop/Ole32/CADWORDTests.cs | 2 +- .../Interop/Ole32/CALPOLESTRTests.cs | 2 +- .../UnitTests/Interop/Ole32/IPictureTests.cs | 2 +- .../Interop/Oleaut32/DECIMALTests.cs | 2 +- .../Interop/Oleaut32/ITypeInfoTests.cs | 12 +- .../Interop/Oleaut32/SAFEARRAYTests.cs | 28 +- .../Interop/Oleaut32/VARIANTTests.cs | 106 +- .../Forms/Automation/UiaTextProviderTests.cs | 6 +- .../Forms/Automation/UiaTextRangeTests.cs | 6 +- .../Forms/LocalAppContextSwitchesTest.cs | 2 +- .../Windows/Forms/SinglyLinkedListTests.cs | 8 +- .../System/Resources/ResxFileRef.Converter.cs | 8 +- .../COM2AboutBoxPropertyDescriptor.cs | 2 +- .../Windows/Forms/Control_InvokeAsync.cs | 8 +- .../ListBoxes/ListBox.IntegerCollection.cs | 6 +- .../Forms/Controls/ListView/ListView.cs | 4 +- ...MultiSelectRootGridEntry.PropertyMerger.cs | 2 +- .../TabControl.TabPageCollection.cs | 6 +- .../TaskDialog/TaskDialogProgressBar.cs | 2 +- .../Layout/TableLayout.SorterObjectArray.cs | 4 +- .../tests/AccessibilityTests/Program.cs | 5 +- .../CustomControls/CustomButton.cs | 5 +- .../CustomControls/CustomButtonDesigner.cs | 5 +- .../CustomButtonDesignerActionList.cs | 5 +- .../CustomControls/DesignerActionVerbItem.cs | 5 +- .../MainForm.MyScrollableControl.cs | 5 +- .../DemoConsole/MainForm.MyUserControl.cs | 5 +- .../DesignSurface/DemoConsole/MainForm.cs | 5 +- .../DesignSurface/DemoConsole/Program.cs | 5 +- .../DesignSurfaceExt/DesignSurfaceExt.cs | 7 +- .../DesignerOptionServiceExt.cs | 5 +- .../DesignerSerializationServiceImpl.cs | 5 +- .../DesignSurfaceExt/IDesignSurfaceExt.cs | 5 +- .../NameCreationServiceImp.cs | 5 +- .../Properties/AssemblyInfo.cs | 5 +- .../DesignSurfaceExt/TabOrderHooker.cs | 5 +- .../DesignSurfaceExt/UndoEngineExt.cs | 5 +- .../ScratchProjectWithInternals/Program.cs | 2 +- .../TrimTestBinaryDeserialization/Form1.cs | 3 + .../TrimTestBinaryDeserialization/Program.cs | 5 +- .../UIIntegrationTests/DragDropTests.cs | 2 +- .../FolderNameEditorTests.cs | 1 - .../UIIntegrationTests/GlobalSuppressions.cs | 6 +- .../Infra/ScreenRecordService.cs | 2 +- .../UIIntegrationTests/Input/InputBuilder.cs | 2 +- .../UIIntegrationTests/MenuStripTests.cs | 2 +- .../UIIntegrationTests/OpenFileDialogTests.cs | 2 +- .../UIIntegrationTests/PropertyGridTests.cs | 6 +- .../UIIntegrationTests/RichTextBoxTests.cs | 8 +- .../UIIntegrationTests/TabControlTests.cs | 2 +- .../WinformsControlsTest/ChartControl.cs | 10 +- .../CustomComCtl32Button.cs | 3 +- .../WinformsControlsTest/FormShowInTaskbar.cs | 2 +- .../WinformsControlsTest/ListBoxes.cs | 4 +- .../WinformsControlsTest/Program.cs | 1 - .../WinformsControlsTest/ScrollBars.cs | 8 +- .../ToolStripSeparatorPreferredSize.cs | 35 +- .../WinformsControlsTest/TrackBars.cs | 2 +- .../InteropTests/AccessibleObjectTests.cs | 14 +- .../tests/InteropTests/PropertyGridTests.cs | 2 +- .../tests/TestUtilities/CommonTestHelperEx.cs | 4 +- .../tests/TestUtilities/KeyboardSimulator.cs | 2 +- .../tests/TestUtilities/ResxHelper.cs | 5 +- .../tests/UnitTests/CheckedListBoxTests.cs | 40 +- .../tests/UnitTests/GlobalSuppressions.cs | 6 +- .../tests/UnitTests/MaskedTextBoxTests.cs | 5 +- .../tests/UnitTests/NumericUpDownTests.cs | 2 +- .../tests/UnitTests/SerializableTypesTests.cs | 8 +- .../Resources/ResXResourceReaderTests.cs | 2 +- .../Resources/ResXSerializationBinderTests.cs | 2 +- .../System/Resources/ResxDataNodeTests.cs | 6 +- .../AccessibleObjectTests.cs | 4 +- ...tonBase.ButtonBaseAccessibleObjectTests.cs | 2 +- .../CheckBox.CheckBoxAccessibleObjectTests.cs | 2 +- .../ComboBox.ComboBoxAccessibleObjectTests.cs | 4 +- .../Control.ControlAccessibleObjectTests.cs | 6 +- .../DataGridViewAccessibleObjectTests.cs | 4 +- ...GridViewButtonCellAccessibleObjectTests.cs | 2 +- .../DataGridViewCellAccessibleObjectTests.cs | 2 +- ...idViewCheckBoxCellAccessibleObjectTests.cs | 2 +- ...taGridViewLinkCellAccessibleObjectTests.cs | 2 +- .../DataGridViewRowAccessibleObjectTests.cs | 4 +- ...ker.DateTimePickerAccessibleObjectTests.cs | 2 +- .../ErrorProviderAccessibleObjectTests.cs | 4 +- .../LabelAccessibleObjectTests.cs | 2 +- ...istBox.ListBoxItemAccessibleObjectTests.cs | 1 - .../ListBoxAccessibleObjectTests.cs | 4 +- .../ListVIew.ListViewAccessibleObjectTests.cs | 11 +- ...roup.ListViewGroupAccessibleObjectTests.cs | 8 +- ...wItem.ListViewItemAccessibleObjectTests.cs | 10 +- ...m.ListViewItemBaseAccessibleObjectTests.cs | 18 +- ...tViewItemWithImageAccessibleObjectTests.cs | 8 +- ...em.ListViewSubItemAccessibleObjectTests.cs | 2 +- ...enuStrip.MenuStripAccessibleObjectTests.cs | 2 +- ...endar.CalendarBodyAccessibleObjectTests.cs | 4 +- ....CalendarTodayLinkAccessibleObjectTests.cs | 2 +- ...tureBox.PictureBoxAccessibleObjectTests.cs | 1 - ...sStrip.StatusStripAccessibleObjectTests.cs | 2 +- ...Control.TabControlAccessibleObjectTests.cs | 6 +- .../ToolStripAccessibleObjectTests.cs | 2 +- ...tripDropDownButtonAccessibleObjectTests.cs | 2 +- .../ToolStripItemAccessibleObjectTests.cs | 2 +- ....ToolStripMenuItemAccessibleObjectTests.cs | 4 +- ....ToolStripOverflowAccessibleObjectTests.cs | 2 +- ...rackBarFirstButtonAccessibleObjectTests.cs | 4 +- ...TrackBarLastButtonAccessibleObjectTests.cs | 4 +- .../TreeNode.TreeNodeAccessibleObjectTests.cs | 2 +- .../TreeView.TreeViewAccessibleObjectTests.cs | 2 +- .../System/Windows/Forms/ApplicationTests.cs | 6 +- .../AutoCompleteStringCollectionTests.cs | 43 +- .../Forms/AxHost.PropertyBagStreamTests.cs | 12 +- .../System/Windows/Forms/AxHostTests.cs | 2 +- .../Windows/Forms/AxSystemMonitorTests.cs | 11 +- .../WinFormsBinaryFormattedObjectTests.cs | 12 +- .../Forms/BinaryFormatUtilitiesTests.cs | 48 +- .../Windows/Forms/BindingContextTests.cs | 4 +- .../Windows/Forms/BindingMemberInfoTests.cs | 14 +- .../Windows/Forms/BindingSourceTests.cs | 10 +- ...ckedListBox.CheckedIndexCollectionTests.cs | 2 +- ...eckedListBox.CheckedItemCollectionTests.cs | 2 +- .../System/Windows/Forms/ClipboardTests.cs | 20 +- .../Forms/ColumnHeaderCollectionTests.cs | 2 +- .../ComboBox.ComboBoxUiaTextProviderTests.cs | 10 +- .../System/Windows/Forms/ComboBoxTests.cs | 27 +- .../Forms/Combobox.ObjectCollectionTests.cs | 43 +- .../Com2PropertyDescriptorTests.cs | 6 +- .../Windows/Forms/ControlTests.Methods.cs | 22 +- .../Windows/Forms/ControlTests.Properties.cs | 16 +- .../System/Windows/Forms/DataFormatsTests.cs | 4 +- .../Windows/Forms/DataGridViewCellTests.cs | 14 +- .../DataGridViewColumnCollectionTests.cs | 4 +- ...DataGridViewSelectedCellCollectionTests.cs | 8 +- ...taGridViewSelectedColumnCollectionTests.cs | 8 +- .../DataGridViewSelectedRowCollectionTests.cs | 8 +- .../Forms/DataGridViewTests.Rendering.cs | 12 +- .../System/Windows/Forms/DataGridViewTests.cs | 5 +- .../Forms/DataObjectTests.ClipboardTests.cs | 10 +- .../System/Windows/Forms/DataObjectTests.cs | 32 +- .../Forms/DataObject_BitmapBinderTests.cs | 14 +- .../Windows/Forms/DateTimePickerTests.cs | 8 +- .../Forms/Design/ComponentEditorPageTests.cs | 2 +- .../System/Windows/Forms/DomainUpDownTests.cs | 24 +- .../Windows/Forms/DragDropHelperTests.cs | 2 +- .../System/Windows/Forms/FontDialogTests.cs | 2 +- .../Windows/Forms/GridItemCollectionTests.cs | 2 +- .../System/Windows/Forms/HtmlDocumentTests.cs | 14 +- .../System/Windows/Forms/HtmlElementTests.cs | 20 +- .../Forms/ImageList.ImageCollectionTests.cs | 54 +- .../System/Windows/Forms/ImageListTests.cs | 4 +- .../System/Windows/Forms/LabelTests.cs | 4 +- .../Forms/Layout/TableLayoutSettingsTests.cs | 24 +- .../Windows/Forms/LinkAreaConverterTests.cs | 2 +- .../System/Windows/Forms/LinkAreaTests.cs | 2 +- .../Windows/Forms/ListBindingHelperTests.cs | 2 +- .../Forms/ListBox.IntegerCollectionTests.cs | 230 +- .../Forms/ListBox.ObjectCollectionTests.cs | 328 +-- .../ListBox.SelectedIndexCollectionTests.cs | 8 +- .../ListBox.SelectedObjectCollectionTests.cs | 8 +- .../System/Windows/Forms/ListBoxTests.cs | 32 +- .../Forms/ListViewGroupCollectionTests.cs | 2 +- .../Windows/Forms/ListViewGroupTests.cs | 15 +- .../Forms/ListViewInsertionMarkTests.cs | 2 +- .../ListViewItem.IKeyboardToolTipTests.cs | 6 +- ...stViewItemStateImageIndexConverterTests.cs | 2 +- .../Forms/ListViewSubItemCollectionTests.cs | 4 +- .../System/Windows/Forms/ListViewTests.cs | 76 +- .../Windows/Forms/MdiControlStripTests.cs | 2 +- .../System/Windows/Forms/MenuStripTests.cs | 4 +- .../Mocks/DataBinding/CommandViewModel.cs | 7 +- .../Forms/Mocks/DataBinding/RelayCommand.cs | 5 +- .../Forms/Mocks/DataBinding/ViewModelBase.cs | 5 +- ...thCalendar.SelectionRangeConverterTests.cs | 2 +- .../Windows/Forms/PaddingConverterTests.cs | 2 +- .../System/Windows/Forms/PaddingTests.cs | 2 +- .../System/Windows/Forms/PictureBoxTests.cs | 4 +- ...tPreviewControlAccessibilityObjectTests.cs | 5 +- .../System/Windows/Forms/ProgressBarTests.cs | 2 +- .../System/Windows/Forms/PropertyGridTests.cs | 8 +- .../Windows/Forms/PropertyManagerTests.cs | 4 +- .../Windows/Forms/RadioButtonRendererTests.cs | 2 +- .../System/Windows/Forms/RadioButtonTests.cs | 6 +- .../Forms/ReadOnlyControlCollectionTests.cs | 2 +- .../System/Windows/Forms/RichTextBoxTests.cs | 4 +- .../System/Windows/Forms/ScreenTests.cs | 4 +- .../System/Windows/Forms/ScrollBarTests.cs | 4 +- .../Forms/SpecialFolderEnumConverterTests.cs | 2 + ...litContainerTypedControlCollectionTests.cs | 2 +- .../System/Windows/Forms/StatusStripTests.cs | 2 +- .../Windows/Forms/SystemInformationTests.cs | 4 +- .../TabControl.TabPageCollectionTests.cs | 6 +- .../System/Windows/Forms/TabControlTests.cs | 2 +- .../TableLayoutPanelCellPositionTests.cs | 4 +- .../Windows/Forms/TableLayoutPanelTests.cs | 2 +- .../Forms/TableLayoutStyleCollectionTests.cs | 2 +- ...BoxBase.TextBoxBaseUiaTextProviderTests.cs | 8 +- .../Windows/Forms/TextBoxRendererTests.cs | 6 +- .../System/Windows/Forms/TextRendererTests.cs | 32 +- .../Windows/Forms/ToolStripComboBoxTests.cs | 2 +- .../Forms/ToolStripControlHostTests.cs | 10 +- .../Windows/Forms/ToolStripDropDownTests.cs | 4 +- .../Forms/ToolStripItemCollectionTests.cs | 2 +- .../Windows/Forms/ToolStripItemTests.cs | 4 +- ...ToolStripPanelRowControlCollectionTests.cs | 3 +- .../Forms/ToolStripSplitButtonTests.cs | 8 +- .../System/Windows/Forms/ToolStripTests.cs | 6 +- .../Windows/Forms/ToolStripTextBoxTests.cs | 16 +- .../Windows/Forms/ToolTipBufferTests.cs | 12 +- .../System/Windows/Forms/ToolTipTests.cs | 4 +- .../Forms/TreeNode.IKeyboardToolTipTests.cs | 10 +- .../Windows/Forms/TreeNodeCollectionTests.cs | 6 +- .../System/Windows/Forms/TreeNodeTests.cs | 4 +- .../System/Windows/Forms/TreeViewTests.cs | 42 +- .../Forms/VisualStyles/TextMetricsTests.cs | 2 +- .../System/Windows/Forms/WebBrowserTests.cs | 8 +- .../tests/UnitTests/TextBoxBaseTests.cs | 18 +- .../tests/UnitTests/ThreadContextTests.cs | 2 +- .../UnitTests/ToolStripContainerTests.cs | 2 +- 338 files changed, 3596 insertions(+), 4180 deletions(-) delete mode 100644 eng/CodeAnalysis.src.globalconfig delete mode 100644 eng/CodeAnalysis.test.globalconfig delete mode 100644 eng/stylecop.json create mode 100644 src/Common/tests/TestUtilities/NativeAssert.cs diff --git a/.editorconfig b/.editorconfig index d2bf6dff62b..7ec57abe4f7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -30,300 +30,1841 @@ dotnet_style_qualification_for_field = false:error dotnet_style_qualification_for_property = false:error dotnet_style_qualification_for_method = false:error dotnet_style_qualification_for_event = false:error + # use language keywords instead of BCL types dotnet_style_predefined_type_for_locals_parameters_members = true:warning dotnet_style_predefined_type_for_member_access = true:warning -# name all constant fields using PascalCase -dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style + +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const + +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style + +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static + +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style + +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal + +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# Code style defaults +dotnet_sort_system_directives_first = true + +# Expression-level preferences +dotnet_style_object_initializer = true:warning +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_simplified_boolean_expressions = true:warning +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_namespace_match_folder = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +end_of_line = crlf +dotnet_style_allow_multiple_blank_lines_experimental = true:silent +dotnet_style_allow_statement_immediately_after_block_experimental = true:silent +dotnet_style_prefer_collection_expression = when_types_exactly_match:warning + +# AD0001: Analyzer threw an exception +dotnet_diagnostic.AD0001.severity = suggestion + +# IDE0001: Simplify name +dotnet_diagnostic.IDE0001.severity = suggestion + +# IDE0002: Simplify member access +dotnet_diagnostic.IDE0002.severity = suggestion + +# IDE0003: Remove this or Me qualification +dotnet_diagnostic.IDE0003.severity = suggestion + +# IDE0004: Remove Unnecessary Cast +dotnet_diagnostic.IDE0004.severity = suggestion + +# IDE0005: Using directive is unnecessary. +dotnet_diagnostic.IDE0005.severity = suggestion + +# IDE0007: Use implicit type +dotnet_diagnostic.IDE0007.severity = silent + +# IDE0008: Use explicit type +dotnet_diagnostic.IDE0008.severity = suggestion + +# IDE0009: Add this or Me qualification +dotnet_diagnostic.IDE0009.severity = silent + +# IDE0010: Add missing cases +dotnet_diagnostic.IDE0010.severity = silent + +# IDE0011: Add braces +dotnet_diagnostic.IDE0011.severity = silent + +# IDE0016: Use 'throw' expression +dotnet_diagnostic.IDE0016.severity = silent + +# IDE0017: Simplify object initialization +dotnet_diagnostic.IDE0017.severity = suggestion + +# IDE0018: Inline variable declaration +dotnet_diagnostic.IDE0018.severity = suggestion + +# IDE0019: Use pattern matching to avoid as followed by a null check +dotnet_diagnostic.IDE0019.severity = suggestion + +# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable) +dotnet_diagnostic.IDE0020.severity = warning + +# IDE0021: Use expression body for constructors +dotnet_diagnostic.IDE0021.severity = silent + +# IDE0022: Use expression body for methods +dotnet_diagnostic.IDE0022.severity = silent + +# IDE0023: Use expression body for operators +dotnet_diagnostic.IDE0023.severity = silent + +# IDE0024: Use expression body for operators +dotnet_diagnostic.IDE0024.severity = silent + +# IDE0025: Use expression body for properties +dotnet_diagnostic.IDE0025.severity = silent + +# IDE0026: Use expression body for indexers +dotnet_diagnostic.IDE0026.severity = silent + +# IDE0027: Use expression body for accessors +dotnet_diagnostic.IDE0027.severity = silent + +# IDE0028: Simplify collection initialization +dotnet_diagnostic.IDE0028.severity = suggestion + +# IDE0029: Use coalesce expression +dotnet_diagnostic.IDE0029.severity = warning + +# IDE0030: Use coalesce expression +dotnet_diagnostic.IDE0030.severity = warning + +# IDE0031: Use null propagation +dotnet_diagnostic.IDE0031.severity = warning + +# IDE0032: Use auto property +dotnet_diagnostic.IDE0032.severity = silent + +# IDE0033: Use explicitly provided tuple name +dotnet_diagnostic.IDE0033.severity = suggestion + +# IDE0034: Simplify 'default' expression +dotnet_diagnostic.IDE0034.severity = suggestion + +# IDE0035: Remove unreachable code +dotnet_diagnostic.IDE0035.severity = suggestion + +# IDE0036: Order modifiers +dotnet_diagnostic.IDE0036.severity = warning + +# IDE0037: Use inferred member name +dotnet_diagnostic.IDE0037.severity = silent + +# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable) +dotnet_diagnostic.IDE0038.severity = suggestion + +# IDE0039: Use local function +dotnet_diagnostic.IDE0039.severity = suggestion + +# IDE0040: Add accessibility modifiers +dotnet_diagnostic.IDE0040.severity = error + +# IDE0041: Use 'is null' check +dotnet_diagnostic.IDE0041.severity = warning + +# IDE0042: Deconstruct variable declaration +dotnet_diagnostic.IDE0042.severity = silent + +# IDE0043: Invalid format string +dotnet_diagnostic.IDE0043.severity = warning + +# IDE0044: Add readonly modifier +dotnet_diagnostic.IDE0044.severity = suggestion + +# IDE0045: Use conditional expression for assignment +dotnet_diagnostic.IDE0045.severity = suggestion + +# IDE0046: Use conditional expression for return +dotnet_diagnostic.IDE0046.severity = suggestion + +# IDE0047: Remove unnecessary parentheses +dotnet_diagnostic.IDE0047.severity = silent + +# IDE0048: Add parentheses for clarity +dotnet_diagnostic.IDE0048.severity = silent + +# IDE0049: Use language keywords instead of framework type names for type references +dotnet_diagnostic.IDE0049.severity = warning + +# IDE0051: Remove unused private members +dotnet_diagnostic.IDE0051.severity = suggestion + +# IDE0052: Remove unread private members +dotnet_diagnostic.IDE0052.severity = suggestion + +# IDE0053: Use expression body for lambdas +dotnet_diagnostic.IDE0053.severity = silent + +# IDE0054: Use compound assignment +dotnet_diagnostic.IDE0054.severity = warning + +# IDE0055: Fix formatting +dotnet_diagnostic.IDE0055.severity = suggestion + +# IDE0056: Use index operator +dotnet_diagnostic.IDE0056.severity = suggestion + +# IDE0057: Use range operator +dotnet_diagnostic.IDE0057.severity = suggestion + +# IDE0058: Expression value is never used +dotnet_diagnostic.IDE0058.severity = silent + +# IDE0059: Unnecessary assignment of a value +dotnet_diagnostic.IDE0059.severity = none # TODO: warning + +# IDE0060: Remove unused parameter +dotnet_diagnostic.IDE0060.severity = silent +dotnet_code_quality_unused_parameters = non_public + +# IDE0061: Use expression body for local functions +dotnet_diagnostic.IDE0061.severity = silent + +# IDE0062: Make local function 'static' +dotnet_diagnostic.IDE0062.severity = warning + +# IDE0063: Use simple 'using' statement +dotnet_diagnostic.IDE0063.severity = silent + +# IDE0064: Make readonly fields writable +dotnet_diagnostic.IDE0064.severity = silent + +# IDE0065: Misplaced using directive +dotnet_diagnostic.IDE0065.severity = warning + +# IDE0066: Convert switch statement to expression +dotnet_diagnostic.IDE0066.severity = suggestion + +# IDE0070: Use 'System.HashCode' +dotnet_diagnostic.IDE0070.severity = suggestion + +# IDE0071: Simplify interpolation +dotnet_diagnostic.IDE0071.severity = warning + +# IDE0072: Add missing cases +dotnet_diagnostic.IDE0072.severity = silent + +# IDE0073: The file header is missing or not located at the top of the file +dotnet_diagnostic.IDE0073.severity = warning + +# IDE0074: Use compound assignment +dotnet_diagnostic.IDE0074.severity = warning + +# IDE0075: Simplify conditional expression +dotnet_diagnostic.IDE0075.severity = silent + +# IDE0076: Invalid global 'SuppressMessageAttribute' +dotnet_diagnostic.IDE0076.severity = warning + +# IDE0077: Avoid legacy format target in 'SuppressMessageAttribute' +dotnet_diagnostic.IDE0077.severity = silent + +# IDE0078: Use pattern matching +dotnet_diagnostic.IDE0078.severity = suggestion + +# This one never seems to be right in the IDE. +# IDE0079: Remove unnecessary suppression +dotnet_diagnostic.IDE0079.severity = silent + +# IDE0080: Remove unnecessary suppression operator +dotnet_diagnostic.IDE0080.severity = warning + +# IDE0081: Remove unnecessary suppression operator +dotnet_diagnostic.IDE0081.severity = none + +# IDE0082: 'typeof' can be converted to 'nameof' +dotnet_diagnostic.IDE0082.severity = warning + +# IDE0083: Use pattern matching +dotnet_diagnostic.IDE0083.severity = silent + +# IDE0084: Use pattern matching (IsNot operator) +dotnet_diagnostic.IDE0084.severity = none + +# IDE0090: Use 'new(...)' +dotnet_diagnostic.IDE0090.severity = silent + +# IDE0100: Remove redundant equality +dotnet_diagnostic.IDE0100.severity = warning + +# IDE0110: Remove unnecessary discard +dotnet_diagnostic.IDE0110.severity = warning + +# IDE0120: Simplify LINQ expression +dotnet_diagnostic.IDE0120.severity = none + +# IDE0130: Namespace does not match folder structure +dotnet_diagnostic.IDE0130.severity = silent + +# IDE0140: Simplify object creation +dotnet_diagnostic.IDE0140.severity = none + +# IDE0150: Prefer 'null' check over type check +dotnet_diagnostic.IDE0150.severity = silent + +# IDE0160: Convert to block scoped namespace +dotnet_diagnostic.IDE0160.severity = silent + +# IDE0161: Convert to file-scoped namespace +dotnet_diagnostic.IDE0161.severity = silent + +# IDE0170: Simplify property pattern +dotnet_diagnostic.IDE0170.severity = warning + +# IDE0180: Use tuple swap +dotnet_diagnostic.IDE0180.severity = suggestion + +# IDE0200: Remove unnecessary lambda expression +dotnet_diagnostic.IDE0200.severity = warning + +# IDE0210: Use top-level statements +dotnet_diagnostic.IDE0210.severity = silent + +# IDE0211: Use program main +dotnet_diagnostic.IDE0211.severity = silent + +# IDE0220: foreach cast +dotnet_diagnostic.IDE0220.severity = silent + +# IDE0230: Use UTF8 string literal +dotnet_diagnostic.IDE0230.severity = suggestion + +# IDE1005: Delegate invocation can be simplified. +dotnet_diagnostic.IDE1005.severity = warning + +# IDE1006: Naming styles +# This rule is configured by individual rules in .editorconfig. Do not override the severity here. +#dotnet_diagnostic.IDE1006.severity = silent + +# IDE2000: Allow multiple blank lines +dotnet_diagnostic.IDE2000.severity = silent + +# IDE2001: Embedded statements must be on their own line +dotnet_diagnostic.IDE2001.severity = silent + +# IDE2002: Consecutive braces must not have blank line between them +dotnet_diagnostic.IDE2002.severity = silent + +# IDE2003: Allow statement immediately after block +dotnet_diagnostic.IDE2003.severity = silent + +# IDE2004: Blank line not allowed after constructor initializer colon +dotnet_diagnostic.IDE2004.severity = silent + +# CA1000: Do not declare static members on generic types +dotnet_diagnostic.CA1000.severity = none + +# CA1001: Types that own disposable fields should be disposable +dotnet_diagnostic.CA1001.severity = none + +# CA1002: Do not expose generic lists +dotnet_diagnostic.CA1002.severity = none + +# CA1003: Use generic event handler instances +dotnet_diagnostic.CA1003.severity = none + +# CA1005: Avoid excessive parameters on generic types +dotnet_diagnostic.CA1005.severity = none + +# CA1008: Enums should have zero value +dotnet_diagnostic.CA1008.severity = none + +# CA1010: Generic interface should also be implemented +dotnet_diagnostic.CA1010.severity = none + +# CA1012: Abstract types should not have public constructors +dotnet_diagnostic.CA1012.severity = none + +# CA1014: Mark assemblies with CLSCompliant +dotnet_diagnostic.CA1014.severity = none + +# CA1016: Mark assemblies with assembly version +dotnet_diagnostic.CA1016.severity = none + +# CA1017: Mark assemblies with ComVisible +dotnet_diagnostic.CA1017.severity = none + +# CA1018: Mark attributes with AttributeUsageAttribute +dotnet_diagnostic.CA1018.severity = warning + +# CA1019: Define accessors for attribute arguments +dotnet_diagnostic.CA1019.severity = none + +# CA1021: Avoid out parameters +dotnet_diagnostic.CA1021.severity = none + +# CA1024: Use properties where appropriate +dotnet_diagnostic.CA1024.severity = none + +# CA1027: Mark enums with FlagsAttribute +dotnet_diagnostic.CA1027.severity = none + +# CA1028: Enum Storage should be Int32 +dotnet_diagnostic.CA1028.severity = none + +# CA1030: Use events where appropriate +dotnet_diagnostic.CA1030.severity = none + +# CA1031: Do not catch general exception types +dotnet_diagnostic.CA1031.severity = none + +# CA1032: Implement standard exception constructors +dotnet_diagnostic.CA1032.severity = none + +# CA1033: Interface methods should be callable by child types +dotnet_diagnostic.CA1033.severity = none + +# CA1034: Nested types should not be visible +dotnet_diagnostic.CA1034.severity = none + +# CA1036: Override methods on comparable types +dotnet_diagnostic.CA1036.severity = warning + +# CA1040: Avoid empty interfaces +dotnet_diagnostic.CA1040.severity = none + +# CA1041: Provide ObsoleteAttribute message +dotnet_diagnostic.CA1041.severity = none + +# CA1043: Use Integral Or String Argument For Indexers +dotnet_diagnostic.CA1043.severity = none + +# CA1044: Properties should not be write only +dotnet_diagnostic.CA1044.severity = none + +# CA1045: Do not pass types by reference +dotnet_diagnostic.CA1045.severity = none + +# CA1046: Do not overload equality operator on reference types +dotnet_diagnostic.CA1046.severity = none + +# CA1047: Do not declare protected member in sealed type +dotnet_diagnostic.CA1047.severity = warning + +# CA1050: Declare types in namespaces +dotnet_diagnostic.CA1050.severity = warning + +# CA1051: Do not declare visible instance fields +dotnet_diagnostic.CA1051.severity = error + +# CA1052: Static holder types should be Static or NotInheritable +dotnet_diagnostic.CA1052.severity = warning +dotnet_code_quality.CA1052.api_surface = private, internal + +# CA1054: URI-like parameters should not be strings +dotnet_diagnostic.CA1054.severity = none + +# CA1055: URI-like return values should not be strings +dotnet_diagnostic.CA1055.severity = none + +# CA1056: URI-like properties should not be strings +dotnet_diagnostic.CA1056.severity = none + +# CA1058: Types should not extend certain base types +dotnet_diagnostic.CA1058.severity = none + +# CA1060: Move pinvokes to native methods class +dotnet_diagnostic.CA1060.severity = none + +# CA1061: Do not hide base class methods +dotnet_diagnostic.CA1061.severity = none + +# CA1062: Validate arguments of public methods +dotnet_diagnostic.CA1062.severity = none + +# CA1063: Implement IDisposable Correctly +dotnet_diagnostic.CA1063.severity = none + +# CA1064: Exceptions should be public +dotnet_diagnostic.CA1064.severity = none + +# CA1065: Do not raise exceptions in unexpected locations +dotnet_diagnostic.CA1065.severity = none + +# CA1066: Implement IEquatable when overriding Object.Equals +dotnet_diagnostic.CA1066.severity = warning + +# CA1067: Override Object.Equals(object) when implementing IEquatable +dotnet_diagnostic.CA1067.severity = warning + +# CA1068: CancellationToken parameters must come last +dotnet_diagnostic.CA1068.severity = none + +# CA1069: Enums values should not be duplicated +dotnet_diagnostic.CA1069.severity = none + +# CA1070: Do not declare event fields as virtual +dotnet_diagnostic.CA1070.severity = suggestion + +# CA1200: Avoid using cref tags with a prefix +dotnet_diagnostic.CA1200.severity = suggestion + +# CA1303: Do not pass literals as localized parameters +dotnet_diagnostic.CA1303.severity = none + +# CA1304: Specify CultureInfo +dotnet_diagnostic.CA1304.severity = none + +# CA1305: Specify IFormatProvider +dotnet_diagnostic.CA1305.severity = none + +# CA1307: Specify StringComparison for clarity +dotnet_diagnostic.CA1307.severity = none + +# CA1308: Normalize strings to uppercase +dotnet_diagnostic.CA1308.severity = none + +# CA1309: Use ordinal string comparison +dotnet_diagnostic.CA1309.severity = none + +# CA1310: Specify StringComparison for correctness +dotnet_diagnostic.CA1310.severity = suggestion + +# CA1311: Specify a culture or use an invariant version +dotnet_diagnostic.CA1311.severity = warning + +# CA1401: P/Invokes should not be visible +dotnet_diagnostic.CA1401.severity = warning + +# CA1416: Validate platform compatibility +dotnet_diagnostic.CA1416.severity = warning + +# CA1417: Do not use 'OutAttribute' on string parameters for P/Invokes +dotnet_diagnostic.CA1417.severity = warning + +# CA1418: Use valid platform string +dotnet_diagnostic.CA1418.severity = warning + +# CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle' +dotnet_diagnostic.CA1419.severity = warning + +# CA1420: Property, type, or attribute requires runtime marshalling +dotnet_diagnostic.CA1420.severity = warning + +# CA1421: This method uses runtime marshalling even when the 'DisableRuntimeMarshallingAttribute' is applied +dotnet_diagnostic.CA1421.severity = suggestion + +# CA1501: Avoid excessive inheritance +dotnet_diagnostic.CA1501.severity = none + +# CA1502: Avoid excessive complexity +dotnet_diagnostic.CA1502.severity = none + +# CA1505: Avoid unmaintainable code +dotnet_diagnostic.CA1505.severity = none + +# CA1506: Avoid excessive class coupling +dotnet_diagnostic.CA1506.severity = none + +# CA1507: Use nameof in place of string +dotnet_diagnostic.CA1507.severity = error + +# CA1508: Avoid dead conditional code +dotnet_diagnostic.CA1508.severity = none + +# CA1509: Invalid entry in code metrics rule specification file +dotnet_diagnostic.CA1509.severity = none + +# CA1511: Use ArgumentException throw helper +dotnet_diagnostic.CA1511.severity = error + +# CA1512: Use ArgumentOutOfRangeException throw helper +dotnet_diagnostic.CA1512.severity = error + +# CA1513: Use ObjectDisposedException throw helper +dotnet_diagnostic.CA1513.severity = error + +# CA1700: Do not name enum values 'Reserved' +dotnet_diagnostic.CA1700.severity = none + +# CA1707: Identifiers should not contain underscores +dotnet_diagnostic.CA1707.severity = none + +# CA1708: Identifiers should differ by more than case +dotnet_diagnostic.CA1708.severity = none + +# CA1710: Identifiers should have correct suffix +dotnet_diagnostic.CA1710.severity = none + +# CA1711: Identifiers should not have incorrect suffix +dotnet_diagnostic.CA1711.severity = none + +# CA1712: Do not prefix enum values with type name +dotnet_diagnostic.CA1712.severity = none + +# CA1713: Events should not have 'Before' or 'After' prefix +dotnet_diagnostic.CA1713.severity = none + +# CA1715: Identifiers should have correct prefix +dotnet_diagnostic.CA1715.severity = none + +# CA1716: Identifiers should not match keywords +dotnet_diagnostic.CA1716.severity = none + +# CA1720: Identifier contains type name +dotnet_diagnostic.CA1720.severity = none + +# CA1721: Property names should not match get methods +dotnet_diagnostic.CA1721.severity = none + +# CA1724: Type names should not match namespaces +dotnet_diagnostic.CA1724.severity = none + +# CA1725: Parameter names should match base declaration +dotnet_diagnostic.CA1725.severity = suggestion + +# CA1727: Use PascalCase for named placeholders +dotnet_diagnostic.CA1727.severity = warning + +# CA1802: Use literals where appropriate +dotnet_diagnostic.CA1802.severity = warning +dotnet_code_quality.CA1802.api_surface = private, internal + +# CA1805: Do not initialize unnecessarily +dotnet_diagnostic.CA1805.severity = warning + +# CA1806: Do not ignore method results +dotnet_diagnostic.CA1806.severity = none + +# CA1810: Initialize reference type static fields inline +dotnet_diagnostic.CA1810.severity = warning + +# CA1812: Remove empty finalizers +dotnet_diagnostic.CA1821.severity = error + +# CA1813: Avoid unsealed attributes +dotnet_diagnostic.CA1813.severity = none + +# CA1814: Prefer jagged arrays over multidimensional +dotnet_diagnostic.CA1814.severity = none + +# CA1815: Override equals and operator equals on value types +dotnet_diagnostic.CA1815.severity = warning + +# CA1816: Dispose methods should call SuppressFinalize +dotnet_diagnostic.CA1816.severity = none + +# CA1819: Properties should not return arrays +dotnet_diagnostic.CA1819.severity = none + +# CA1820: Test for empty strings using string length +dotnet_diagnostic.CA1820.severity = none + +# CA1821: Remove empty Finalizers +dotnet_diagnostic.CA1821.severity = none # TODO: warning + +# CA1822: Mark members as static +dotnet_diagnostic.CA1822.severity = warning +dotnet_code_quality.CA1822.api_surface = private, internal + +# CA1823: Avoid unused private fields +dotnet_diagnostic.CA1823.severity = warning + +# CA1824: Mark assemblies with NeutralResourcesLanguageAttribute +dotnet_diagnostic.CA1824.severity = warning + +# CA1825: Avoid zero-length array allocations +dotnet_diagnostic.CA1825.severity = warning + +# CA1825: Avoid zero-length array allocations +dotnet_diagnostic.CA1825.severity = error + +# CA1826: Use property instead of Linq Enumerable method +dotnet_diagnostic.CA1826.severity = error + +# CA1827: Do not use Count()/LongCount() when Any() can be used +dotnet_diagnostic.CA1827.severity = error + +# CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used +dotnet_diagnostic.CA1828.severity = error + +# CA1829: Use Length/Count property instead of Enumerable.Count method +dotnet_diagnostic.CA1829.severity = error + +# CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder +dotnet_diagnostic.CA1830.severity = error + +# CA1831: Use AsSpan instead of Range-based indexers for string when appropriate +dotnet_diagnostic.CA1831.severity = error + +# CA1832: Use AsSpan or AsMemory instead of Range-based indexers for getting ReadOnlySpan or ReadOnlyMemory portion of an array +dotnet_diagnostic.CA1832.severity = error + +# CA1833: Use AsSpan or AsMemory instead of Range-based indexers for getting Span or Memory portion of an array +dotnet_diagnostic.CA1833.severity = error + +# CA1834: Use StringBuilder.Append(char) for single character strings +dotnet_diagnostic.CA1834.severity = error + +# CA1835: Prefer the memory-based overloads of ReadAsync/WriteAsync methods in stream-based classes +dotnet_diagnostic.CA1835.severity = error + +# CA1836: Prefer IsEmpty over Count when available +dotnet_diagnostic.CA1836.severity = error + +# CA1837: Use Environment.ProcessId instead of Process.GetCurrentProcess().Id +dotnet_diagnostic.CA1837.severity = error + +# CA1838: Avoid StringBuilder parameters for P/Invokes +dotnet_diagnostic.CA1838.severity = error + +# CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName +dotnet_diagnostic.CA1839.severity = error + +# CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId +dotnet_diagnostic.CA1840.severity = error + +# CA1841: Prefer Dictionary Contains methods +dotnet_diagnostic.CA1841.severity = error + +# CA1842: Do not use 'WhenAll' with a single task +dotnet_diagnostic.CA1842.severity = error + +# CA1843: Do not use 'WaitAll' with a single task +dotnet_diagnostic.CA1843.severity = error + +# CA1844: Provide memory-based overrides of async methods when subclassing 'Stream' +dotnet_diagnostic.CA1844.severity = error + +# CA1845: Use span-based 'string.Concat' +dotnet_diagnostic.CA1845.severity = warning + +# CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters +dotnet_diagnostic.CA1847.severity = error + +# CA1848: Use the LoggerMessage delegates +dotnet_diagnostic.CA1848.severity = error + +# CA1849: Call async methods when in an async method +dotnet_diagnostic.CA1849.severity = suggestion + +# CA1850: Prefer static HashData method over ComputeHash +dotnet_diagnostic.CA1850.severity = error + +# CA1851: Possible multiple enumerations of IEnumerable collection +dotnet_diagnostic.CA1851.severity = error + +# CA1852: Seal internal types +dotnet_diagnostic.CA1852.severity = error + +# CA1853: Unnecessary call to 'Dictionary.ContainsKey(key)' +dotnet_diagnostic.CA1853.severity = error + +# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method +dotnet_diagnostic.CA1854.severity = error + +# CA1858: Use StartsWith instead of IndexOf +dotnet_diagnostic.CA1858.severity = error + +# CA1860: Avoid using 'Enumerable.Any()' extension method +dotnet_diagnostic.CA1860.severity = error + +# CA2000: Dispose objects before losing scope +dotnet_diagnostic.CA2000.severity = none + +# CA2002: Do not lock on objects with weak identity +dotnet_diagnostic.CA2002.severity = none + +# CA2007: Consider calling ConfigureAwait on the awaited task +dotnet_diagnostic.CA2007.severity = warning + +# CA2008: Do not create tasks without passing a TaskScheduler +dotnet_diagnostic.CA2008.severity = warning + +# CA2009: Do not call ToImmutableCollection on an ImmutableCollection value +dotnet_diagnostic.CA2009.severity = warning + +# CA2011: Do not assign property within its setter +dotnet_diagnostic.CA2011.severity = warning + +# CA2012: Use ValueTasks correctly +dotnet_diagnostic.CA2012.severity = warning + +# CA2013: Do not use ReferenceEquals with value types +dotnet_diagnostic.CA2013.severity = warning + +# CA2014: Do not use stackalloc in loops +dotnet_diagnostic.CA2014.severity = warning + +# CA2015: Do not define finalizers for types derived from MemoryManager +dotnet_diagnostic.CA2015.severity = warning + +# CA2016: Forward the 'CancellationToken' parameter to methods +dotnet_diagnostic.CA2016.severity = warning + +# CA2017: Parameter count mismatch +dotnet_diagnostic.CA2017.severity = warning + +# CA2018: 'Buffer.BlockCopy' expects the number of bytes to be copied for the 'count' argument +dotnet_diagnostic.CA2018.severity = warning + +# CA2019: ThreadStatic fields should not use inline initialization +dotnet_diagnostic.CA2019.severity = warning + +# CA2100: Review SQL queries for security vulnerabilities +dotnet_diagnostic.CA2100.severity = none + +# CA2101: Specify marshaling for P/Invoke string arguments +dotnet_diagnostic.CA2101.severity = none + +# CA2109: Review visible event handlers +dotnet_diagnostic.CA2109.severity = none + +# CA2119: Seal methods that satisfy private interfaces +dotnet_diagnostic.CA2119.severity = none + +# CA2153: Do Not Catch Corrupted State Exceptions +dotnet_diagnostic.CA2153.severity = none + + +# CA2200: Rethrow to preserve stack details +dotnet_diagnostic.CA2200.severity = warning + +# CA2201: Do not raise reserved exception types +dotnet_diagnostic.CA2201.severity = none + +# CA2207: Initialize value type static fields inline +dotnet_diagnostic.CA2207.severity = warning + +# CA2208: Instantiate argument exceptions correctly +dotnet_diagnostic.CA2208.severity = error + +# CA2211: Non-constant fields should not be visible +dotnet_diagnostic.CA2211.severity = error + +# CA2213: Disposable fields should be disposed +dotnet_diagnostic.CA2213.severity = none + +# CA2214: Do not call overridable methods in constructors +dotnet_diagnostic.CA2214.severity = none + +# CA2215: Dispose methods should call base class dispose +dotnet_diagnostic.CA2215.severity = none + +# CA2216: Disposable types should declare finalizer +dotnet_diagnostic.CA2216.severity = none + +# CA2217: Do not mark enums with FlagsAttribute +dotnet_diagnostic.CA2217.severity = none + +# CA2218: Override GetHashCode on overriding Equals +dotnet_diagnostic.CA2218.severity = none + +# CA2219: Do not raise exceptions in finally clauses +dotnet_diagnostic.CA2219.severity = none + +# CA2224: Override Equals on overloading operator equals +dotnet_diagnostic.CA2224.severity = none + +# CA2225: Operator overloads have named alternates +dotnet_diagnostic.CA2225.severity = none + +# CA2226: Operators should have symmetrical overloads +dotnet_diagnostic.CA2226.severity = none + +# CA2227: Collection properties should be read only +dotnet_diagnostic.CA2227.severity = none + +# CA2229: Implement serialization constructors +dotnet_diagnostic.CA2229.severity = warning + +# CA2231: Overload operator equals on overriding value type Equals +dotnet_diagnostic.CA2231.severity = none + +# CA2234: Pass system uri objects instead of strings +dotnet_diagnostic.CA2234.severity = none + +# CA2235: Mark all non-serializable fields +dotnet_diagnostic.CA2235.severity = none + +# CA2237: Mark ISerializable types with serializable +dotnet_diagnostic.CA2237.severity = none + +# CA2241: Provide correct arguments to formatting methods +dotnet_diagnostic.CA2241.severity = error + +# CA2242: Test for NaN correctly +dotnet_diagnostic.CA2242.severity = error + +# CA2243: Attribute string literals should parse correctly +dotnet_diagnostic.CA2243.severity = warning + +# CA2244: Do not duplicate indexed element initializations +dotnet_diagnostic.CA2244.severity = warning + +# CA2245: Do not assign a property to itself +dotnet_diagnostic.CA2245.severity = error + +# CA2246: Assigning symbol and its member in the same statement +dotnet_diagnostic.CA2246.severity = warning + +# CA2247: Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum +dotnet_diagnostic.CA2247.severity = warning + +# CA2248: Provide correct 'enum' argument to 'Enum.HasFlag' +dotnet_diagnostic.CA2248.severity = error + +# CA2249: Consider using 'string.Contains' instead of 'string.IndexOf' +dotnet_diagnostic.CA2249.severity = error + +# CA2250: Use 'ThrowIfCancellationRequested' +dotnet_diagnostic.CA2250.severity = warning + +# CA2251: Use String.Equals over String.Compare +dotnet_diagnostic.CA2251.severity = error + +# CA2252: This API requires opting into preview features +dotnet_diagnostic.CA2252.severity = error + +# CA2253: Named placeholders should not be numeric values +dotnet_diagnostic.CA2253.severity = warning + +# CA2254: Template should be a static expression +dotnet_diagnostic.CA2254.severity = none + +# CA2255: The 'ModuleInitializer' attribute should not be used in libraries +dotnet_diagnostic.CA2255.severity = warning + +# CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface +dotnet_diagnostic.CA2256.severity = warning + +# CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static' +dotnet_diagnostic.CA2257.severity = warning + +# CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported +dotnet_diagnostic.CA2258.severity = warning + +# CA2259: 'ThreadStatic' only affects static fields +dotnet_diagnostic.CA2259.severity = warning + +# CA2201: Do not raise reserved exception types +dotnet_diagnostic.CA2201.severity = error + +# CA2219: Do not raise exceptions in exception clauses +dotnet_diagnostic.CA2219.severity = error + +# CA2300: Do not use insecure deserializer BinaryFormatter +dotnet_diagnostic.CA2300.severity = none + +# CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder +dotnet_diagnostic.CA2301.severity = none + +# CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize +dotnet_diagnostic.CA2302.severity = none + +# CA2305: Do not use insecure deserializer LosFormatter +dotnet_diagnostic.CA2305.severity = none + +# CA2310: Do not use insecure deserializer NetDataContractSerializer +dotnet_diagnostic.CA2310.severity = none + +# CA2311: Do not deserialize without first setting NetDataContractSerializer.Binder +dotnet_diagnostic.CA2311.severity = none + +# CA2312: Ensure NetDataContractSerializer.Binder is set before deserializing +dotnet_diagnostic.CA2312.severity = none + +# CA2315: Do not use insecure deserializer ObjectStateFormatter +dotnet_diagnostic.CA2315.severity = none + +# CA2321: Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver +dotnet_diagnostic.CA2321.severity = none + +# CA2322: Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing +dotnet_diagnostic.CA2322.severity = none + +# CA2326: Do not use TypeNameHandling values other than None +dotnet_diagnostic.CA2326.severity = none + +# CA2327: Do not use insecure JsonSerializerSettings +dotnet_diagnostic.CA2327.severity = none + +# CA2328: Ensure that JsonSerializerSettings are secure +dotnet_diagnostic.CA2328.severity = none + +# CA2329: Do not deserialize with JsonSerializer using an insecure configuration +dotnet_diagnostic.CA2329.severity = none + +# CA2330: Ensure that JsonSerializer has a secure configuration when deserializing +dotnet_diagnostic.CA2330.severity = none + +# CA2350: Do not use DataTable.ReadXml() with untrusted data +dotnet_diagnostic.CA2350.severity = none + +# CA2351: Do not use DataSet.ReadXml() with untrusted data +dotnet_diagnostic.CA2351.severity = none + +# CA2352: Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks +dotnet_diagnostic.CA2352.severity = none + +# CA2353: Unsafe DataSet or DataTable in serializable type +dotnet_diagnostic.CA2353.severity = none + +# CA2354: Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks +dotnet_diagnostic.CA2354.severity = none + +# CA2355: Unsafe DataSet or DataTable type found in deserializable object graph +dotnet_diagnostic.CA2355.severity = none + +# CA2356: Unsafe DataSet or DataTable type in web deserializable object graph +dotnet_diagnostic.CA2356.severity = none + +# CA2361: Ensure auto-generated class containing DataSet.ReadXml() is not used with untrusted data +dotnet_diagnostic.CA2361.severity = none + +# CA2362: Unsafe DataSet or DataTable in auto-generated serializable type can be vulnerable to remote code execution attacks +dotnet_diagnostic.CA2362.severity = none + +# CA3001: Review code for SQL injection vulnerabilities +dotnet_diagnostic.CA3001.severity = none + +# CA3002: Review code for XSS vulnerabilities +dotnet_diagnostic.CA3002.severity = none + +# CA3003: Review code for file path injection vulnerabilities +dotnet_diagnostic.CA3003.severity = none + +# CA3004: Review code for information disclosure vulnerabilities +dotnet_diagnostic.CA3004.severity = none + +# CA3005: Review code for LDAP injection vulnerabilities +dotnet_diagnostic.CA3005.severity = none + +# CA3006: Review code for process command injection vulnerabilities +dotnet_diagnostic.CA3006.severity = none + +# CA3007: Review code for open redirect vulnerabilities +dotnet_diagnostic.CA3007.severity = none + +# CA3008: Review code for XPath injection vulnerabilities +dotnet_diagnostic.CA3008.severity = none + +# CA3009: Review code for XML injection vulnerabilities +dotnet_diagnostic.CA3009.severity = none + +# CA3010: Review code for XAML injection vulnerabilities +dotnet_diagnostic.CA3010.severity = none + +# CA3011: Review code for DLL injection vulnerabilities +dotnet_diagnostic.CA3011.severity = none + +# CA3012: Review code for regex injection vulnerabilities +dotnet_diagnostic.CA3012.severity = none + +# CA3061: Do not add schema by URL +dotnet_diagnostic.CA3061.severity = warning + +# CA3075: Insecure DTD Processing +dotnet_diagnostic.CA3075.severity = warning + +# CA3076: Insecure XSLT Script Execution +dotnet_diagnostic.CA3076.severity = warning + +# CA3077: Insecure Processing in API Design, XML Document and XML Text Reader +dotnet_diagnostic.CA3077.severity = warning + +# CA3147: Mark verb handlers with ValidateAntiForgeryToken +dotnet_diagnostic.CA3147.severity = warning + +# CA5350: Do Not Use Weak Cryptographic Algorithms +dotnet_diagnostic.CA5350.severity = warning + +# CA5351: Do Not Use Broken Cryptographic Algorithms +dotnet_diagnostic.CA5351.severity = warning + +# CA5358: Review cipher mode usage with cryptography experts +dotnet_diagnostic.CA5358.severity = none + +# CA5359: Do not disable certificate validation +dotnet_diagnostic.CA5359.severity = warning + +# CA5360: Do not call dangerous methods in deserialization +dotnet_diagnostic.CA5360.severity = warning + +# CA5361: Do Not Disable SChannel Use of Strong Crypto +dotnet_diagnostic.CA5361.severity = warning + +# CA5362: Potential reference cycle in deserialized object graph +dotnet_diagnostic.CA5362.severity = none + +# CA5363: Do not disable request validation +dotnet_diagnostic.CA5363.severity = warning + +# CA5364: Do not use deprecated security protocols +dotnet_diagnostic.CA5364.severity = warning + +# CA5365: Do Not Disable HTTP Header Checking +dotnet_diagnostic.CA5365.severity = warning + +# CA5366: Use XmlReader For DataSet Read XML +dotnet_diagnostic.CA5366.severity = warning + +# CA5367: Do Not Serialize Types With Pointer Fields +dotnet_diagnostic.CA5367.severity = none + +# CA5368: Set ViewStateUserKey For Classes Derived From Page +dotnet_diagnostic.CA5368.severity = warning + +# CA5369: Use XmlReader for Deserialize +dotnet_diagnostic.CA5369.severity = warning + +# CA5370: Use XmlReader for validating reader +dotnet_diagnostic.CA5370.severity = warning + +# CA5371: Use XmlReader for schema read +dotnet_diagnostic.CA5371.severity = warning + +# CA5372: Use XmlReader for XPathDocument +dotnet_diagnostic.CA5372.severity = warning + +# CA5373: Do not use obsolete key derivation function +dotnet_diagnostic.CA5373.severity = warning + +# CA5374: Do not use XslTransform +dotnet_diagnostic.CA5374.severity = warning + +# CA5375: Do not use account shared access signature +dotnet_diagnostic.CA5379.severity = warning + +# CA5376: Use SharedAccessProtocol HttpsOnly +dotnet_diagnostic.CA5376.severity = warning + +# CA5377: Use Container Level Access Policy +dotnet_diagnostic.CA5377.severity = warning + +# CA5378: Do not disable ServicePointManagerSecurityProtocols +dotnet_diagnostic.CA5378.severity = warning + +# CA5379: Ensure Key Derivation Function algorithm is sufficiently strong +dotnet_diagnostic.CA5379.severity = warning + +# CA5380: Do Not Add Certificates To Root Store +dotnet_diagnostic.CA5380.severity = warning + +# CA5381: Ensure Certificates Are Not Added To Root Store +dotnet_diagnostic.CA5381.severity = warning + +# CA5382: Use Secure Cookies In ASP.NET Core +dotnet_diagnostic.CA5382.severity = none + +# CA5383: Ensure Use Secure Cookies In ASP.NET Core +dotnet_diagnostic.CA5383.severity = none + +# CA5384: Do not use digital signature algorithm (DSA) +dotnet_diagnostic.CA5384.severity = warning + +# CA5385: Use Rivest-Shamir-Adleman (RSA) algorithm with sufficient key size +dotnet_diagnostic.CA5385.severity = warning + +# CA5386: Avoid hardcoding SecurityProtocolType value +dotnet_diagnostic.CA5386.severity = none + +# CA5387: Do not use weak key derivation function with insufficient iteration count +dotnet_diagnostic.CA5397.severity = warning + +# CA5388: Ensure Sufficient Iteration Count When Using Weak Key Derivation Function +dotnet_diagnostic.CA5388.severity = none + +# CA5389: Do Not Add Archive Item's Path To The Target File System Path +dotnet_diagnostic.CA5389.severity = none + +# CA5390: Do not hard-code encryption key +dotnet_diagnostic.CA5390.severity = none + +# CA5391: Use antiforgery tokens in ASP.NET Core MVC controllers +dotnet_diagnostic.CA5391.severity = none + +# CA5392: Use DefaultDllImportSearchPaths attribute for P/Invokes +dotnet_diagnostic.CA5392.severity = none + +# CA5393: Do not use unsafe DllImportSearchPath value +dotnet_diagnostic.CA5393.severity = none + +# CA5394: Do not use insecure randomness +dotnet_diagnostic.CA5394.severity = none + +# CA5395: Miss HttpVerb attribute for action methods +dotnet_diagnostic.CA5395.severity = none + +# CA5396: Set HttpOnly to true for HttpCookie +dotnet_diagnostic.CA5396.severity = none + +# CA5397: Do not use deprecated SslProtocols values +dotnet_diagnostic.CA5397.severity = none + +# CA5398: Avoid hardcoded SslProtocols values +dotnet_diagnostic.CA5398.severity = none + +# CA5399: HttpClients should enable certificate revocation list checks +dotnet_diagnostic.CA5399.severity = none + +# CA5400: Ensure HttpClient certificate revocation list check is not disabled +dotnet_diagnostic.CA5400.severity = none + +# CA5401: Do not use CreateEncryptor with non-default IV +dotnet_diagnostic.CA5401.severity = none + +# CA5402: Use CreateEncryptor with the default IV +dotnet_diagnostic.CA5402.severity = none + +# CA5403: Do not hard-code certificate +dotnet_diagnostic.CA5403.severity = none + +# CA5404: Do not disable token validation checks +dotnet_diagnostic.CA5404.severity = none + +# CA5405: Do not always skip token validation in delegates +dotnet_diagnostic.CA5405.severity = none + +# IL3000: Avoid using accessing Assembly file path when publishing as a single-file +dotnet_diagnostic.IL3000.severity = none # TODO: warning + +# IL3001: Avoid using accessing Assembly file path when publishing as a single-file +dotnet_diagnostic.IL3001.severity = warning + +# IL3002: Using member with RequiresAssemblyFilesAttribute can break functionality when embedded in a single-file app +dotnet_diagnostic.IL3002.severity = warning + +# RS0041: Public members should not use oblivious types +dotnet_diagnostic.RS0041.severity = warning + +# SA0001: XML comments +dotnet_diagnostic.SA0001.severity = none + +# SA0002: Invalid settings file +dotnet_diagnostic.SA0002.severity = none + +# SA1000: Spacing around keywords +# suggestion until https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3478 is resolved +dotnet_diagnostic.SA1000.severity = suggestion + +# SA1001: Commas should not be preceded by whitespace +dotnet_diagnostic.SA1001.severity = warning + +# SA1002: Semicolons should not be preceded by a space +dotnet_diagnostic.SA1002.severity = none + +# SA1003: Operator should not appear at the end of a line +dotnet_diagnostic.SA1003.severity = none + +# SA1004: Documentation line should begin with a space +dotnet_diagnostic.SA1004.severity = none + +# SA1005: Single line comment should begin with a space +dotnet_diagnostic.SA1005.severity = warning + +# SA1006: Preprocessor keywords should not be preceded by space +dotnet_diagnostic.SA1006.severity = none + +# SA1007: Operator keyword should be followed by space +dotnet_diagnostic.SA1007.severity = none + +# SA1008: Opening parenthesis should not be preceded by a space +dotnet_diagnostic.SA1008.severity = none + +# SA1009: Closing parenthesis should not be followed by a space +dotnet_diagnostic.SA1009.severity = none + +# SA1010: Opening square brackets should not be preceded by a space +dotnet_diagnostic.SA1010.severity = none + +# SA1011: Closing square bracket should be followed by a space +dotnet_diagnostic.SA1011.severity = none + +# SA1012: Opening brace should be followed by a space +dotnet_diagnostic.SA1012.severity = none + +# SA1013: Closing brace should be preceded by a space +dotnet_diagnostic.SA1013.severity = none + +# SA1014: Opening generic brackets should not be preceded by a space +dotnet_diagnostic.SA1014.severity = warning + +# SA1015: Closing generic bracket should not be followed by a space +dotnet_diagnostic.SA1015.severity = none + +# SA1016: Opening attribute brackets should be spaced correctly +dotnet_diagnostic.SA1016.severity = none + +# SA1017: Closing attribute brackets should be spaced correctly +dotnet_diagnostic.SA1017.severity = none + +# SA1018: Nullable type symbol should not be preceded by a space +dotnet_diagnostic.SA1018.severity = warning + +# SA1019: Member access symbols should be spaced correctly +dotnet_diagnostic.SA1019.severity = none + +# SA1020: Increment symbol should not be preceded by a space +dotnet_diagnostic.SA1020.severity = warning + +# SA1021: Negative sign should be preceded by a space +dotnet_diagnostic.SA1021.severity = none + +# SA1022: Positive signs should be spaced correctly +dotnet_diagnostic.SA1022.severity = none + +# SA1023: Dereference symbol '*' should not be preceded by a space." +dotnet_diagnostic.SA1023.severity = none + +# SA1024: Colon should be followed by a space +dotnet_diagnostic.SA1024.severity = none + +# SA1025: Code should not contain multiple whitespace characters in a row +dotnet_diagnostic.SA1025.severity = none + +# SA1026: Keyword followed by span or blank line +dotnet_diagnostic.SA1026.severity = warning + +# SA1027: Tabs and spaces should be used correctly +dotnet_diagnostic.SA1027.severity = warning + +# SA1028: Code should not contain trailing whitespace +dotnet_diagnostic.SA1028.severity = warning + +# SA1100: Do not prefix calls with base unless local implementation exists +dotnet_diagnostic.SA1100.severity = none + +# SA1101: Prefix local calls with this +dotnet_diagnostic.SA1101.severity = none + +# SA1102: Query clause should follow previous clause +dotnet_diagnostic.SA1102.severity = warning + +# SA1105: Query clauses spanning multiple lines should begin on own line +dotnet_diagnostic.SA1105.severity = warning + +# SA1104: Query clause should begin on new line when previous clause spans multiple lines +dotnet_diagnostic.SA1104.severity = none + +# SA1105: Query clauses spanning multiple lines should begin on own line +dotnet_diagnostic.SA1105.severity = none + +# SA1106: Code should not contain empty statements +dotnet_diagnostic.SA1106.severity = none + +# SA1107: Code should not contain multiple statements on one line +dotnet_diagnostic.SA1107.severity = none + +# SA1108: Block statements should not contain embedded comments +dotnet_diagnostic.SA1108.severity = none + +# SA1109: Block statements should not contain embedded regions +dotnet_diagnostic.SA1109.severity = none + +# SA1110: Opening parenthesis or bracket should be on declaration line +dotnet_diagnostic.SA1110.severity = none + +# SA1111: Closing parenthesis should be on line of last parameter +dotnet_diagnostic.SA1111.severity = none + +# SA1112: Closing parenthesis should be on line of opening parenthesis +dotnet_diagnostic.SA1112.severity = none + +# SA1113: Comma should be on the same line as previous parameter +dotnet_diagnostic.SA1113.severity = warning + +# SA1114: Parameter list should follow declaration +dotnet_diagnostic.SA1114.severity = none + +# SA1115: Parameter should begin on the line after the previous parameter +dotnet_diagnostic.SA1115.severity = warning + +# SA1116: Split parameters should start on line after declaration +dotnet_diagnostic.SA1116.severity = none + +# SA1117: Parameters should be on same line or separate lines +dotnet_diagnostic.SA1117.severity = none + +# SA1118: Parameter should not span multiple lines +dotnet_diagnostic.SA1118.severity = none + +# SA1119: Statement should not use unnecessary parenthesis +dotnet_diagnostic.SA1119.severity = none + +# SA1120: Comments should contain text +dotnet_diagnostic.SA1120.severity = none + +# SA1121: Use built-in type alias +dotnet_diagnostic.SA1121.severity = warning + +# SA1122: Use string.Empty for empty strings +dotnet_diagnostic.SA1122.severity = none + +# SA1123: Region should not be located within a code element +dotnet_diagnostic.SA1123.severity = none + +# SA1124: Do not use regions +dotnet_diagnostic.SA1124.severity = none + +# SA1125: Use shorthand for nullable types +dotnet_diagnostic.SA1125.severity = none + +# SA1126: Prefix calls correctly +dotnet_diagnostic.SA1126.severity = none + +# SA1127: Generic type constraints should be on their own line +dotnet_diagnostic.SA1127.severity = none + +# SA1128: Put constructor initializers on their own line +dotnet_diagnostic.SA1128.severity = none + +# SA1129: Do not use default value type constructor +dotnet_diagnostic.SA1129.severity = warning + +# SA1130: Use lambda syntax +dotnet_diagnostic.SA1130.severity = none + +# SA1131: Constant values should appear on the right-hand side of comparisons +dotnet_diagnostic.SA1131.severity = warning + +# SA1132: Do not combine fields +dotnet_diagnostic.SA1132.severity = none + +# SA1133: Do not combine attributes +dotnet_diagnostic.SA1133.severity = none -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.required_modifiers = const +# SA1134: Each attribute should be placed on its own line of code +dotnet_diagnostic.SA1134.severity = none -dotnet_naming_style.pascal_case_style.capitalization = pascal_case +# SA1135: Using directive should be qualified +dotnet_diagnostic.SA1135.severity = none -# static fields should have s_ prefix -dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion -dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields -dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +# SA1136: Enum values should be on separate lines +dotnet_diagnostic.SA1136.severity = none -dotnet_naming_symbols.static_fields.applicable_kinds = field -dotnet_naming_symbols.static_fields.required_modifiers = static +# SA1137: Elements should have the same indentation +dotnet_diagnostic.SA1137.severity = none -dotnet_naming_style.static_prefix_style.required_prefix = s_ -dotnet_naming_style.static_prefix_style.capitalization = camel_case +# SA1139: Use literal suffix notation instead of casting +dotnet_diagnostic.SA1139.severity = none -# internal and private fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +# SA1141: Use tuple syntax +dotnet_diagnostic.SA1141.severity = warning -dotnet_naming_symbols.private_internal_fields.applicable_kinds = field -dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +# SA1142: Refer to tuple elements by name +dotnet_diagnostic.SA1142.severity = warning -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case +# SA1200: Using directive should appear within a namespace declaration +dotnet_diagnostic.SA1200.severity = none -# Code style defaults -dotnet_sort_system_directives_first = true +# SA1201: Elements should appear in the correct order +dotnet_diagnostic.SA1201.severity = none -# Expression-level preferences -dotnet_style_object_initializer = true:warning -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:suggestion -dotnet_style_null_propagation = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error -dotnet_style_prefer_auto_properties = true:silent -dotnet_style_prefer_simplified_boolean_expressions = true:warning -dotnet_style_prefer_inferred_tuple_names = true:suggestion -dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion -dotnet_style_prefer_compound_assignment = true:suggestion -dotnet_style_prefer_simplified_interpolation = true:suggestion -dotnet_style_namespace_match_folder = true:suggestion -dotnet_style_operator_placement_when_wrapping = beginning_of_line -tab_width = 4 -end_of_line = crlf -dotnet_style_allow_multiple_blank_lines_experimental = true:silent -dotnet_style_allow_statement_immediately_after_block_experimental = true:silent -dotnet_style_prefer_collection_expression = when_types_exactly_match:warning +# SA1202: Elements should be ordered by access +dotnet_diagnostic.SA1202.severity = none -# IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = error +# SA1203: Constants should appear before fields +dotnet_diagnostic.SA1203.severity = none -# CA1036: Override methods on comparable types -dotnet_diagnostic.CA1036.severity = warning +# SA1204: Static elements should appear before instance elements +dotnet_diagnostic.SA1204.severity = none -# CA1051: Do not declare visible instance fields -dotnet_diagnostic.CA1051.severity = error +# SA1205: Partial elements should declare an access modifier +dotnet_diagnostic.SA1205.severity = warning -# CA1507: Use nameof in place of string -dotnet_diagnostic.CA1507.severity = error +# SA1206: Keyword ordering - TODO Re-enable as warning after https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3527 +dotnet_diagnostic.SA1206.severity = suggestion -# CA1511: Use ArgumentException throw helper -dotnet_diagnostic.CA1511.severity = error +# SA1207: Protected should come before internal +dotnet_diagnostic.SA1207.severity = none -# CA1512: Use ArgumentOutOfRangeException throw helper -dotnet_diagnostic.CA1512.severity = error +# SA1208: Using directive ordering +dotnet_diagnostic.SA1208.severity = none -# CA1513: Use ObjectDisposedException throw helper -dotnet_diagnostic.CA1513.severity = error +# SA1209: Using alias directives should be placed after all using namespace directives +dotnet_diagnostic.SA1209.severity = none -# CA1805: Do not initialize unnecessarily -dotnet_diagnostic.CA1805.severity = warning +# SA1210: Using directives should be ordered alphabetically by the namespaces +dotnet_diagnostic.SA1210.severity = none -# CA1812: Remove empty finalizers -dotnet_diagnostic.CA1821.severity = error +# SA1211: Using alias directive ordering +dotnet_diagnostic.SA1211.severity = none -# CA1825: Avoid zero-length array allocations -dotnet_diagnostic.CA1825.severity = error +# SA1212: A get accessor appears after a set accessor within a property or indexer +dotnet_diagnostic.SA1212.severity = warning -# CA1826: Use property instead of Linq Enumerable method -dotnet_diagnostic.CA1826.severity = error +# SA1213: Event accessors should follow order +dotnet_diagnostic.SA1213.severity = none -# CA1827: Do not use Count()/LongCount() when Any() can be used -dotnet_diagnostic.CA1827.severity = error +# SA1214: Readonly fields should appear before non-readonly fields +dotnet_diagnostic.SA1214.severity = none -# CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used -dotnet_diagnostic.CA1828.severity = error +# SA1216: Using static directives should be placed at the correct location +dotnet_diagnostic.SA1216.severity = none -# CA1829: Use Length/Count property instead of Enumerable.Count method -dotnet_diagnostic.CA1829.severity = error +# SA1217: Using static directives should be ordered alphabetically +dotnet_diagnostic.SA1217.severity = none -# CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder -dotnet_diagnostic.CA1830.severity = error +# SA1300: Element should begin with an uppercase letter +dotnet_diagnostic.SA1300.severity = none -# CA1831: Use AsSpan instead of Range-based indexers for string when appropriate -dotnet_diagnostic.CA1831.severity = error +# SA1301: Element should begin with lower-case letter +dotnet_diagnostic.SA1301.severity = none -# CA1832: Use AsSpan or AsMemory instead of Range-based indexers for getting ReadOnlySpan or ReadOnlyMemory portion of an array -dotnet_diagnostic.CA1832.severity = error +# SA1302: Interface names should begin with I +dotnet_diagnostic.SA1302.severity = none # TODO: warning -# CA1833: Use AsSpan or AsMemory instead of Range-based indexers for getting Span or Memory portion of an array -dotnet_diagnostic.CA1833.severity = error +# SA1303: Const field names should begin with upper-case letter +dotnet_diagnostic.SA1303.severity = none -# CA1834: Use StringBuilder.Append(char) for single character strings -dotnet_diagnostic.CA1834.severity = error +# SA1304: Non-private readonly fields should begin with upper-case letter +dotnet_diagnostic.SA1304.severity = none -# CA1835: Prefer the memory-based overloads of ReadAsync/WriteAsync methods in stream-based classes -dotnet_diagnostic.CA1835.severity = error +# SA1305: Field names should not use Hungarian notation +dotnet_diagnostic.SA1305.severity = none -# CA1836: Prefer IsEmpty over Count when available -dotnet_diagnostic.CA1836.severity = error +# SA1306: Field should begin with lower-case letter +dotnet_diagnostic.SA1306.severity = none -# CA1837: Use Environment.ProcessId instead of Process.GetCurrentProcess().Id -dotnet_diagnostic.CA1837.severity = error +# SA1307: Field should begin with upper-case letter +dotnet_diagnostic.SA1307.severity = none -# CA1838: Avoid StringBuilder parameters for P/Invokes -dotnet_diagnostic.CA1838.severity = error +# SA1308: Field should not begin with the prefix 's_' +dotnet_diagnostic.SA1308.severity = none -# CA1839: Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileName -dotnet_diagnostic.CA1839.severity = error +# SA1309: Field names should not begin with underscore +dotnet_diagnostic.SA1309.severity = none -# CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId -dotnet_diagnostic.CA1840.severity = error +# SA1310: Field should not contain an underscore +dotnet_diagnostic.SA1310.severity = none -# CA1841: Prefer Dictionary Contains methods -dotnet_diagnostic.CA1841.severity = error +# SA1311: Static readonly fields should begin with upper-case letter +dotnet_diagnostic.SA1311.severity = none -# CA1842: Do not use 'WhenAll' with a single task -dotnet_diagnostic.CA1842.severity = error +# SA1312: Variable should begin with lower-case letter +dotnet_diagnostic.SA1312.severity = none -# CA1843: Do not use 'WaitAll' with a single task -dotnet_diagnostic.CA1843.severity = error +# SA1313: Parameter should begin with lower-case letter +dotnet_diagnostic.SA1313.severity = none -# CA1844: Provide memory-based overrides of async methods when subclassing 'Stream' -dotnet_diagnostic.CA1844.severity = error +# SA1314: Type parameter names should begin with T +dotnet_diagnostic.SA1314.severity = none -# CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters -dotnet_diagnostic.CA1847.severity = error +# SA1316: Tuple element names should use correct casing +dotnet_diagnostic.SA1316.severity = none -# CA1848: Use the LoggerMessage delegates -dotnet_diagnostic.CA1848.severity = error +# SA1400: Member should declare an access modifier +dotnet_diagnostic.SA1400.severity = warning -# CA1850: Prefer static HashData method over ComputeHash -dotnet_diagnostic.CA1850.severity = error +# SA1401: Fields should be private +dotnet_diagnostic.SA1401.severity = none -# CA1851: Possible multiple enumerations of IEnumerable collection -dotnet_diagnostic.CA1851.severity = error +# SA1402: File may only contain a single type +dotnet_diagnostic.SA1402.severity = none -# CA1852: Seal internal types -dotnet_diagnostic.CA1852.severity = error +# SA1403: File may only contain a single namespace +dotnet_diagnostic.SA1403.severity = none -# CA1853: Unnecessary call to 'Dictionary.ContainsKey(key)' -dotnet_diagnostic.CA1853.severity = error +# SA1404: Code analysis suppression should have justification +dotnet_diagnostic.SA1404.severity = none # TODO: warning -# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method -dotnet_diagnostic.CA1854.severity = error +# SA1405: Debug.Assert should provide message text +dotnet_diagnostic.SA1405.severity = none -# CA1858: Use StartsWith instead of IndexOf -dotnet_diagnostic.CA1858.severity = error +# SA1406: Debug.Fail should provide message text +dotnet_diagnostic.SA1406.severity = none -# CA1860: Avoid using 'Enumerable.Any()' extension method -dotnet_diagnostic.CA1860.severity = error +# SA1407: Arithmetic expressions should declare precedence +dotnet_diagnostic.SA1407.severity = none -# CA2009: Do not call ToImmutableCollection on an ImmutableCollection value -dotnet_diagnostic.CA2009.severity = warning +# SA1408: Conditional expressions should declare precedence +dotnet_diagnostic.SA1408.severity = warning -# CA2011: Do not assign property within its setter -dotnet_diagnostic.CA2011.severity = warning +# SA1409: Remove unnecessary code +dotnet_diagnostic.SA1409.severity = none -# CA2012: Use ValueTasks correctly -dotnet_diagnostic.CA2012.severity = warning +# SA1410: Remove delegate parens when possible +dotnet_diagnostic.SA1410.severity = warning -# CA2019: ThreadStatic fields should not use inline initialization -dotnet_diagnostic.CA2019.severity = warning +# SA1411: Attribute constructor shouldn't use unnecessary parenthesis +dotnet_diagnostic.SA1411.severity = warning -# CA2208: Instantiate argument exceptions correctly -dotnet_diagnostic.CA2208.severity = error +# SA1412: Store files as UTF-8 with byte order mark +dotnet_diagnostic.SA1412.severity = none -# CA2211: Non-constant fields should not be visible -dotnet_diagnostic.CA2211.severity = error +# SA1413: Use trailing comma in multi-line initializers +dotnet_diagnostic.SA1413.severity = none -# CA2241: Provide correct arguments to formatting methods -dotnet_diagnostic.CA2241.severity = error +# SA1414: Tuple types in signatures should have element names +dotnet_diagnostic.SA1414.severity = none -# CA2245: Do not assign a property to itself -dotnet_diagnostic.CA2245.severity = error +# SA1500: Braces for multi-line statements should not share line +dotnet_diagnostic.SA1500.severity = error -# CA2248: Provide correct enum argument to Enum.HasFlag -dotnet_diagnostic.CA2248.severity = error +# SA1501: Statement should not be on a single line +dotnet_diagnostic.SA1501.severity = none -# CA2249: Consider using String.Contains instead of String.IndexOf -dotnet_diagnostic.CA2249.severity = error +# SA1502: Element should not be on a single line +dotnet_diagnostic.SA1502.severity = none -# CA2242: Test for NaN correctly -dotnet_diagnostic.CA2242.severity = error +# SA1503: Braces should not be omitted +dotnet_diagnostic.SA1503.severity = none -# CA2251: Use String.Equals over String.Compare -dotnet_diagnostic.CA2251.severity = error +# SA1504: All accessors should be single-line or multi-line +dotnet_diagnostic.SA1504.severity = none -# CA2201: Do not raise reserved exception types -dotnet_diagnostic.CA2201.severity = error +# SA1505: An opening brace should not be followed by a blank line +dotnet_diagnostic.SA1505.severity = warning -# CA2219: Do not raise exceptions in exception clauses -dotnet_diagnostic.CA2219.severity = error +# SA1506: Element documentation headers should not be followed by blank line +dotnet_diagnostic.SA1506.severity = none -# CA3061: Do not add schema by URL -dotnet_diagnostic.CA3061.severity = warning +# SA1507: Code should not contain multiple blank lines in a row +dotnet_diagnostic.SA1507.severity = warning -# CA3075: Insecure DTD Processing -dotnet_diagnostic.CA3075.severity = warning +# SA1508: A closing brace should not be preceded by a blank line +dotnet_diagnostic.SA1508.severity = warning -# CA3076: Insecure XSLT Script Execution -dotnet_diagnostic.CA3076.severity = warning +# SA1509: Opening braces should not be preceded by blank line +dotnet_diagnostic.SA1509.severity = warning -# CA3077: Insecure Processing in API Design, XML Document and XML Text Reader -dotnet_diagnostic.CA3077.severity = warning +# SA1510: 'else' statement should not be preceded by a blank line +dotnet_diagnostic.SA1510.severity = none -# CA3147: Mark verb handlers with ValidateAntiForgeryToken -dotnet_diagnostic.CA3147.severity = warning +# SA1511: While-do footer should not be preceded by blank line +dotnet_diagnostic.SA1511.severity = none -# CA5350: Do Not Use Weak Cryptographic Algorithms -dotnet_diagnostic.CA5350.severity = warning +# SA1512: Single-line comments should not be followed by blank line +dotnet_diagnostic.SA1512.severity = none -# CA5351: Do Not Use Broken Cryptographic Algorithms -dotnet_diagnostic.CA5351.severity = warning +# SA1513: Closing brace should be followed by blank line +dotnet_diagnostic.SA1513.severity = error -# CA5359: Do not disable certificate validation -dotnet_diagnostic.CA5359.severity = warning +# SA1514: Element documentation header should be preceded by blank line +dotnet_diagnostic.SA1514.severity = none -# CA5360: Do not call dangerous methods in deserialization -dotnet_diagnostic.CA5360.severity = warning +# SA1515: Single-line comment should be preceded by blank line +dotnet_diagnostic.SA1515.severity = none -# CA5363: Do not disable request validation -dotnet_diagnostic.CA5363.severity = warning +# SA1516: Elements should be separated by blank line +dotnet_diagnostic.SA1516.severity = none -# CA5364: Do not use deprecated security protocols -dotnet_diagnostic.CA5364.severity = warning +# SA1517: Code should not contain blank lines at start of file +dotnet_diagnostic.SA1517.severity = warning -# CA5365: Do Not Disable HTTP Header Checking -dotnet_diagnostic.CA5365.severity = warning +# SA1518: Code should not contain blank lines at the end of the file +dotnet_diagnostic.SA1518.severity = warning -# CA5366: Use XmlReader For DataSet Read XML -dotnet_diagnostic.CA5366.severity = warning +# SA1519: Braces should not be omitted from multi-line child statement +dotnet_diagnostic.SA1519.severity = none -# CA5368: Set ViewStateUserKey For Classes Derived From Page -dotnet_diagnostic.CA5368.severity = warning +# SA1520: Use braces consistently +dotnet_diagnostic.SA1520.severity = none -# CA5369: Use XmlReader for Deserialize -dotnet_diagnostic.CA5369.severity = warning +# SA1600: Elements should be documented +dotnet_diagnostic.SA1600.severity = none -# CA5370: Use XmlReader for validating reader -dotnet_diagnostic.CA5370.severity = warning +# SA1601: Partial elements should be documented +dotnet_diagnostic.SA1601.severity = none -# CA5371: Use XmlReader for schema read -dotnet_diagnostic.CA5371.severity = warning +# SA1602: Enumeration items should be documented +dotnet_diagnostic.SA1602.severity = none -# CA5372: Use XmlReader for XPathDocument -dotnet_diagnostic.CA5372.severity = warning +# SA1603: Documentation should contain valid XML +dotnet_diagnostic.SA1603.severity = none -# CA5373: Do not use obsolete key derivation function -dotnet_diagnostic.CA5373.severity = warning +# SA1604: Element documentation should have summary +dotnet_diagnostic.SA1604.severity = none -# CA5374: Do not use XslTransform -dotnet_diagnostic.CA5374.severity = warning +# SA1605: Partial element documentation should have summary +dotnet_diagnostic.SA1605.severity = none -# CA5375: Do not use account shared access signature -dotnet_diagnostic.CA5379.severity = warning +# SA1606: Element documentation should have summary text +dotnet_diagnostic.SA1606.severity = none -# CA5384: Do not use digital signature algorithm (DSA) -dotnet_diagnostic.CA5384.severity = warning +# SA1607: Partial element documentation should have summary text +dotnet_diagnostic.SA1607.severity = none -# CA5385: Use Rivest-Shamir-Adleman (RSA) algorithm with sufficient key size -dotnet_diagnostic.CA5385.severity = warning +# SA1608: Element documentation should not have default summary +dotnet_diagnostic.SA1608.severity = none -# CA5387: Do not use weak key derivation function with insufficient iteration count -dotnet_diagnostic.CA5397.severity = warning +# SA1609: Property documentation should have value +dotnet_diagnostic.SA1609.severity = none -# RS0041: Public members should not use oblivious types -dotnet_diagnostic.RS0041.severity = warning +# SA1610: Property documentation should have value text +dotnet_diagnostic.SA1610.severity = none + +# SA1611: The documentation for parameter 'message' is missing +dotnet_diagnostic.SA1611.severity = none + +# SA1612: The parameter documentation is at incorrect position +dotnet_diagnostic.SA1612.severity = none + +# SA1613: Element parameter documentation should declare parameter name +dotnet_diagnostic.SA1613.severity = none + +# SA1614: Element parameter documentation should have text +dotnet_diagnostic.SA1614.severity = none + +# SA1615: Element return value should be documented +dotnet_diagnostic.SA1615.severity = none + +# SA1616: Element return value documentation should have text +dotnet_diagnostic.SA1616.severity = none + +# SA1617: Void return value should not be documented +dotnet_diagnostic.SA1617.severity = none + +# SA1618: The documentation for type parameter is missing +dotnet_diagnostic.SA1618.severity = none + +# SA1619: The documentation for type parameter is missing +dotnet_diagnostic.SA1619.severity = none + +# SA1620: Generic type parameter documentation should match type parameters +dotnet_diagnostic.SA1620.severity = none + +# SA1621: Generic type parameter documentation should declare parameter name +dotnet_diagnostic.SA1621.severity = none + +# SA1622: Generic type parameter documentation should have text +dotnet_diagnostic.SA1622.severity = none + +# SA1623: Property documentation text +dotnet_diagnostic.SA1623.severity = none + +# SA1624: Because the property only contains a visible get accessor, the documentation summary text should begin with 'Gets' +dotnet_diagnostic.SA1624.severity = none + +# SA1625: Element documentation should not be copied and pasted +dotnet_diagnostic.SA1625.severity = none + +# SA1626: Single-line comments should not use documentation style slashes +dotnet_diagnostic.SA1626.severity = none + +# SA1627: The documentation text within the \'exception\' tag should not be empty +dotnet_diagnostic.SA1627.severity = none + +# SA1628: Documentation text should begin with a capital letter +dotnet_diagnostic.SA1628.severity = none + +# SA1629: Documentation text should end with a period +dotnet_diagnostic.SA1629.severity = none + +# SA1630: Documentation text should contain whitespace +dotnet_diagnostic.SA1630.severity = none + +# SA1631: Documentation should meet character percentage +dotnet_diagnostic.SA1631.severity = none + +# SA1632: Documentation text should meet minimum character length +dotnet_diagnostic.SA1632.severity = none + +# SA1633: File should have header +dotnet_diagnostic.SA1633.severity = none + +# SA1634: File header should show copyright +dotnet_diagnostic.SA1634.severity = none + +# SA1635: File header should have copyright text +dotnet_diagnostic.SA1635.severity = none + +# SA1636: File header copyright text should match +dotnet_diagnostic.SA1636.severity = none + +# SA1637: File header should contain file name +dotnet_diagnostic.SA1637.severity = none + +# SA1638: File header file name documentation should match file name +dotnet_diagnostic.SA1638.severity = none +# SA1639: File header should have summary +dotnet_diagnostic.SA1639.severity = none + +# SA1640: File header should have valid company text +dotnet_diagnostic.SA1640.severity = none + +# SA1641: File header company name text should match +dotnet_diagnostic.SA1641.severity = none + +# SA1642: Constructor summary documentation should begin with standard text +dotnet_diagnostic.SA1642.severity = none + +# SA1643: Destructor summary documentation should begin with standard text +dotnet_diagnostic.SA1643.severity = none + +# SA1644: Documentation headers should not contain blank lines +dotnet_diagnostic.SA1644.severity = none + +# SA1645: Included documentation file does not exist +dotnet_diagnostic.SA1645.severity = none + +# SA1646: Included documentation XPath does not exist +dotnet_diagnostic.SA1646.severity = none + +# SA1647: Include node does not contain valid file and path +dotnet_diagnostic.SA1647.severity = none + +# SA1648: Inheritdoc should be used with inheriting class +dotnet_diagnostic.SA1648.severity = none + +# SA1649: File name should match first type name +dotnet_diagnostic.SA1649.severity = none + +# SA1650: Element documentation should be spelled correctly +dotnet_diagnostic.SA1650.severity = none + +# SA1651: Do not use placeholder elements +dotnet_diagnostic.SA1651.severity = none + +# SX1101: Do not prefix local calls with 'this.' +dotnet_diagnostic.SX1101.severity = none + +# SX1309: Field names should begin with underscore +dotnet_diagnostic.SX1309.severity = none + +# -------- # C# files +# -------- [*.cs] +# CSIsNull001 to catch uses of == null +dotnet_diagnostic.CSIsNull001.severity = warning + +# CSIsNull002 to catch uses of != null +dotnet_diagnostic.CSIsNull002.severity = warning + # CSIsNull001: Use 'is' pattern check dotnet_diagnostic.CSIsNull001.severity = error @@ -478,9 +2019,6 @@ dotnet_diagnostic.IDE0077.severity = warning # IDE0078: Use pattern matching dotnet_diagnostic.IDE0078.severity = warning -# IDE0079: Remove unnecessary suppression -dotnet_diagnostic.IDE0079.severity = error - # IDE0180: Use tuple to swap values dotnet_diagnostic.IDE0180.severity = warning @@ -595,7 +2133,9 @@ csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent csharp_style_deconstructed_variable_declaration = true:suggestion +# ------------------ # Visual Basic files +# ------------------ [*.vb] # Modifier preferences @@ -603,15 +2143,15 @@ visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public dotnet_separate_import_directive_groups = false:warning +# CA2007: Consider calling ConfigureAwait on the awaited task +dotnet_diagnostic.CA2007.severity = suggestion + # IDE0001: Simplify Names dotnet_diagnostic.IDE0001.severity = silent # IDE0002: Simplify Member Access dotnet_diagnostic.IDE0002.severity = silent -# IDE0079: Remove unnecessary suppression -dotnet_diagnostic.IDE0079.severity = none - # Expression-level preferences dotnet_style_coalesce_expression = false:suggestion dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion @@ -651,11 +2191,11 @@ end_of_line = lf [*.{cmd,bat}] end_of_line = crlf +# ------------- # Test specific -[**/tests/**/*.cs] +# ------------- -# CA1861: Avoid constant arrays as arguments - expected to be in-line for test readability (4000 hits) -dotnet_diagnostic.CA1861.severity = silent +[**/tests/**/*.cs] # This collides with TheoryData usage dotnet_style_prefer_collection_expression = true:silent @@ -670,9 +2210,15 @@ dotnet_diagnostic.xUnit1044.severity = none # xUnit1045: Avoid using TheoryData type arguments that might not be serializable dotnet_diagnostic.xUnit1045.severity = none +# CA1416: Validate platform compatibility +dotnet_diagnostic.CA1416.severity = none + # CA1507: CA1507: Use nameof in place of string - many false positives dotnet_diagnostic.CA1507.severity = none +# CA1815: Override equals and operator equals on value types +dotnet_diagnostic.CA1815.severity = none + # CA1822: Mark members as static dotnet_diagnostic.CA1822.severity = suggestion @@ -682,6 +2228,14 @@ dotnet_diagnostic.CA1852.severity = suggestion # CA1859: Use concrete types when possible for improved performance dotnet_diagnostic.CA1859.severity = none +# CA1861: Avoid constant arrays as arguments - expected to be in-line for test readability (4000 hits) +dotnet_diagnostic.CA1861.severity = silent + +# CA2007: Consider calling ConfigureAwait on the awaited task +dotnet_diagnostic.CA2007.severity = suggestion + +# SA1115: Parameter should begin on the line after the previous parameter +dotnet_diagnostic.SA1115.severity = none # Verify settings diff --git a/Winforms.sln b/Winforms.sln index d44bd5ea14b..c57b33f20b1 100644 --- a/Winforms.sln +++ b/Winforms.sln @@ -45,12 +45,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Accessibility", "Accessibil EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.IntegrationTests.Common", "src\System.Windows.Forms\tests\IntegrationTests\System.Windows.Forms.IntegrationTests.Common\System.Windows.Forms.IntegrationTests.Common.csproj", "{48979B4E-EAEC-4B41-BB49-44CA230BECAB}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{462AD69A-9395-4E98-882D-569CDE562559}" - ProjectSection(SolutionItems) = preProject - azure-pipelines.yml = azure-pipelines.yml - eng\pipelines\build.yml = eng\pipelines\build.yml - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "documentation", "documentation", "{C029199F-7D5C-417C-AA52-913A214E3285}" ProjectSection(SolutionItems) = preProject docs\building.md = docs\building.md @@ -154,11 +148,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Windows.Core EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "eng", "eng", "{8B4B1E09-B3C7-4044-B223-94EDEC1CAA20}" ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig .gitattributes = .gitattributes .gitignore = .gitignore - eng\CodeAnalysis.src.globalconfig = eng\CodeAnalysis.src.globalconfig - eng\CodeAnalysis.test.globalconfig = eng\CodeAnalysis.test.globalconfig Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets global.json = global.json @@ -187,6 +178,29 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "System.Windows.Forms.Analyz EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Windows.Core.Tests", "src\System.Private.Windows.Core\tests\System.Private.Windows.Core.Tests\System.Private.Windows.Core.Tests.csproj", "{B653C860-9B52-4597-9921-24DA79A4E6B1}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipelines", "Pipelines", "{656C66A4-59CD-4E14-8AE4-1F5BCEECB553}" + ProjectSection(SolutionItems) = preProject + eng\pipelines\azure-pipelines-codeql.yml = eng\pipelines\azure-pipelines-codeql.yml + azure-pipelines-PR.yml = azure-pipelines-PR.yml + azure-pipelines-richnav.yml = azure-pipelines-richnav.yml + azure-pipelines.yml = azure-pipelines.yml + eng\pipelines\build-PR.yml = eng\pipelines\build-PR.yml + eng\pipelines\build.yml = eng\pipelines\build.yml + eng\CIBuild.cmd = eng\CIBuild.cmd + eng\custom-cibuild.ps1 = eng\custom-cibuild.ps1 + eng\pipelines\post-build-PR.yml = eng\pipelines\post-build-PR.yml + eng\pipelines\post-build.yml = eng\pipelines\post-build.yml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analyzers", "Analyzers", "{D4D97D78-D213-45DF-B003-9C4C9F2E5E1C}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + eng\CodeAnalysisSource.cs = eng\CodeAnalysisSource.cs + eng\CodeAnalysisSource.vb = eng\CodeAnalysisSource.vb + eng\CodeStyle.props = eng\CodeStyle.props + eng\CodeStyle.targets = eng\CodeStyle.targets + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1092,7 +1106,6 @@ Global {6103E743-057D-41C6-946C-23A751A08748} = {088DD24C-DF6B-45F3-A8BC-592580A4B2A9} {088DD24C-DF6B-45F3-A8BC-592580A4B2A9} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7} {48979B4E-EAEC-4B41-BB49-44CA230BECAB} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A} - {462AD69A-9395-4E98-882D-569CDE562559} = {8B4B1E09-B3C7-4044-B223-94EDEC1CAA20} {D390F7D2-1E11-4DEE-B7F1-4FD0681A81F0} = {DF68A171-D27B-4E6A-8A7E-63A651622355} {55E34830-B375-41FF-AFCA-F53B80A4D152} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7} {D8598EC8-D64B-4BE7-A4DC-5D5CED6A3938} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC} @@ -1139,6 +1152,8 @@ Global {C4C031D5-F79A-44B6-811E-0797E7D5C1C1} = {E4C6C5F5-46E9-4C63-9628-26752B4D9C11} {0FD53580-3175-4F8F-8372-BE46C9122EE0} = {D3AD0BF9-F5E2-4913-9AE3-9C4998F95EA1} {B653C860-9B52-4597-9921-24DA79A4E6B1} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC} + {656C66A4-59CD-4E14-8AE4-1F5BCEECB553} = {8B4B1E09-B3C7-4044-B223-94EDEC1CAA20} + {D4D97D78-D213-45DF-B003-9C4C9F2E5E1C} = {8B4B1E09-B3C7-4044-B223-94EDEC1CAA20} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136} diff --git a/eng/CodeAnalysis.src.globalconfig b/eng/CodeAnalysis.src.globalconfig deleted file mode 100644 index 953e2ce5207..00000000000 --- a/eng/CodeAnalysis.src.globalconfig +++ /dev/null @@ -1,1751 +0,0 @@ -is_global = true - -# AD0001: Analyzer threw an exception -dotnet_diagnostic.AD0001.severity = suggestion - -# CA1000: Do not declare static members on generic types -dotnet_diagnostic.CA1000.severity = none - -# CA1001: Types that own disposable fields should be disposable -dotnet_diagnostic.CA1001.severity = none - -# CA1002: Do not expose generic lists -dotnet_diagnostic.CA1002.severity = none - -# CA1003: Use generic event handler instances -dotnet_diagnostic.CA1003.severity = none - -# CA1005: Avoid excessive parameters on generic types -dotnet_diagnostic.CA1005.severity = none - -# CA1008: Enums should have zero value -dotnet_diagnostic.CA1008.severity = none - -# CA1010: Generic interface should also be implemented -dotnet_diagnostic.CA1010.severity = none - -# CA1012: Abstract types should not have public constructors -dotnet_diagnostic.CA1012.severity = none - -# CA1014: Mark assemblies with CLSCompliant -dotnet_diagnostic.CA1014.severity = none - -# CA1016: Mark assemblies with assembly version -dotnet_diagnostic.CA1016.severity = none - -# CA1017: Mark assemblies with ComVisible -dotnet_diagnostic.CA1017.severity = none - -# CA1018: Mark attributes with AttributeUsageAttribute -dotnet_diagnostic.CA1018.severity = warning - -# CA1019: Define accessors for attribute arguments -dotnet_diagnostic.CA1019.severity = none - -# CA1021: Avoid out parameters -dotnet_diagnostic.CA1021.severity = none - -# CA1024: Use properties where appropriate -dotnet_diagnostic.CA1024.severity = none - -# CA1027: Mark enums with FlagsAttribute -dotnet_diagnostic.CA1027.severity = none - -# CA1028: Enum Storage should be Int32 -dotnet_diagnostic.CA1028.severity = none - -# CA1030: Use events where appropriate -dotnet_diagnostic.CA1030.severity = none - -# CA1031: Do not catch general exception types -dotnet_diagnostic.CA1031.severity = none - -# CA1032: Implement standard exception constructors -dotnet_diagnostic.CA1032.severity = none - -# CA1033: Interface methods should be callable by child types -dotnet_diagnostic.CA1033.severity = none - -# CA1034: Nested types should not be visible -dotnet_diagnostic.CA1034.severity = none - -# CA1036: Override methods on comparable types -dotnet_diagnostic.CA1036.severity = none - -# CA1040: Avoid empty interfaces -dotnet_diagnostic.CA1040.severity = none - -# CA1041: Provide ObsoleteAttribute message -dotnet_diagnostic.CA1041.severity = none - -# CA1043: Use Integral Or String Argument For Indexers -dotnet_diagnostic.CA1043.severity = none - -# CA1044: Properties should not be write only -dotnet_diagnostic.CA1044.severity = none - -# CA1045: Do not pass types by reference -dotnet_diagnostic.CA1045.severity = none - -# CA1046: Do not overload equality operator on reference types -dotnet_diagnostic.CA1046.severity = none - -# CA1047: Do not declare protected member in sealed type -dotnet_diagnostic.CA1047.severity = warning - -# CA1050: Declare types in namespaces -dotnet_diagnostic.CA1050.severity = warning - -# CA1051: Do not declare visible instance fields -dotnet_diagnostic.CA1051.severity = none - -# CA1052: Static holder types should be Static or NotInheritable -dotnet_diagnostic.CA1052.severity = warning -dotnet_code_quality.CA1052.api_surface = private, internal - -# CA1054: URI-like parameters should not be strings -dotnet_diagnostic.CA1054.severity = none - -# CA1055: URI-like return values should not be strings -dotnet_diagnostic.CA1055.severity = none - -# CA1056: URI-like properties should not be strings -dotnet_diagnostic.CA1056.severity = none - -# CA1058: Types should not extend certain base types -dotnet_diagnostic.CA1058.severity = none - -# CA1060: Move pinvokes to native methods class -dotnet_diagnostic.CA1060.severity = none - -# CA1061: Do not hide base class methods -dotnet_diagnostic.CA1061.severity = none - -# CA1062: Validate arguments of public methods -dotnet_diagnostic.CA1062.severity = none - -# CA1063: Implement IDisposable Correctly -dotnet_diagnostic.CA1063.severity = none - -# CA1064: Exceptions should be public -dotnet_diagnostic.CA1064.severity = none - -# CA1065: Do not raise exceptions in unexpected locations -dotnet_diagnostic.CA1065.severity = none - -# CA1066: Implement IEquatable when overriding Object.Equals -dotnet_diagnostic.CA1066.severity = warning - -# CA1067: Override Object.Equals(object) when implementing IEquatable -dotnet_diagnostic.CA1067.severity = warning - -# CA1068: CancellationToken parameters must come last -dotnet_diagnostic.CA1068.severity = none - -# CA1069: Enums values should not be duplicated -dotnet_diagnostic.CA1069.severity = none - -# CA1070: Do not declare event fields as virtual -dotnet_diagnostic.CA1070.severity = suggestion - -# CA1200: Avoid using cref tags with a prefix -dotnet_diagnostic.CA1200.severity = suggestion - -# CA1303: Do not pass literals as localized parameters -dotnet_diagnostic.CA1303.severity = none - -# CA1304: Specify CultureInfo -dotnet_diagnostic.CA1304.severity = none - -# CA1305: Specify IFormatProvider -dotnet_diagnostic.CA1305.severity = none - -# CA1307: Specify StringComparison for clarity -dotnet_diagnostic.CA1307.severity = none - -# CA1308: Normalize strings to uppercase -dotnet_diagnostic.CA1308.severity = none - -# CA1309: Use ordinal string comparison -dotnet_diagnostic.CA1309.severity = none - -# CA1310: Specify StringComparison for correctness -dotnet_diagnostic.CA1310.severity = suggestion - -# CA1311: Specify a culture or use an invariant version -dotnet_diagnostic.CA1311.severity = warning - -# CA1401: P/Invokes should not be visible -dotnet_diagnostic.CA1401.severity = warning - -# CA1416: Validate platform compatibility -dotnet_diagnostic.CA1416.severity = warning - -# CA1417: Do not use 'OutAttribute' on string parameters for P/Invokes -dotnet_diagnostic.CA1417.severity = warning - -# CA1418: Use valid platform string -dotnet_diagnostic.CA1418.severity = warning - -# CA1419: Provide a parameterless constructor that is as visible as the containing type for concrete types derived from 'System.Runtime.InteropServices.SafeHandle' -dotnet_diagnostic.CA1419.severity = warning - -# CA1420: Property, type, or attribute requires runtime marshalling -dotnet_diagnostic.CA1420.severity = warning - -# CA1421: This method uses runtime marshalling even when the 'DisableRuntimeMarshallingAttribute' is applied -dotnet_diagnostic.CA1421.severity = suggestion - -# CA1501: Avoid excessive inheritance -dotnet_diagnostic.CA1501.severity = none - -# CA1502: Avoid excessive complexity -dotnet_diagnostic.CA1502.severity = none - -# CA1505: Avoid unmaintainable code -dotnet_diagnostic.CA1505.severity = none - -# CA1506: Avoid excessive class coupling -dotnet_diagnostic.CA1506.severity = none - -# CA1507: Use nameof to express symbol names -dotnet_diagnostic.CA1507.severity = warning - -# CA1508: Avoid dead conditional code -dotnet_diagnostic.CA1508.severity = none - -# CA1509: Invalid entry in code metrics rule specification file -dotnet_diagnostic.CA1509.severity = none - -# CA1700: Do not name enum values 'Reserved' -dotnet_diagnostic.CA1700.severity = none - -# CA1707: Identifiers should not contain underscores -dotnet_diagnostic.CA1707.severity = none - -# CA1708: Identifiers should differ by more than case -dotnet_diagnostic.CA1708.severity = none - -# CA1710: Identifiers should have correct suffix -dotnet_diagnostic.CA1710.severity = none - -# CA1711: Identifiers should not have incorrect suffix -dotnet_diagnostic.CA1711.severity = none - -# CA1712: Do not prefix enum values with type name -dotnet_diagnostic.CA1712.severity = none - -# CA1713: Events should not have 'Before' or 'After' prefix -dotnet_diagnostic.CA1713.severity = none - -# CA1715: Identifiers should have correct prefix -dotnet_diagnostic.CA1715.severity = none - -# CA1716: Identifiers should not match keywords -dotnet_diagnostic.CA1716.severity = none - -# CA1720: Identifier contains type name -dotnet_diagnostic.CA1720.severity = none - -# CA1721: Property names should not match get methods -dotnet_diagnostic.CA1721.severity = none - -# CA1724: Type names should not match namespaces -dotnet_diagnostic.CA1724.severity = none - -# CA1725: Parameter names should match base declaration -dotnet_diagnostic.CA1725.severity = suggestion - -# CA1727: Use PascalCase for named placeholders -dotnet_diagnostic.CA1727.severity = warning - -# CA1802: Use literals where appropriate -dotnet_diagnostic.CA1802.severity = warning -dotnet_code_quality.CA1802.api_surface = private, internal - -# CA1805: Do not initialize unnecessarily -dotnet_diagnostic.CA1805.severity = warning - -# CA1806: Do not ignore method results -dotnet_diagnostic.CA1806.severity = none - -# CA1810: Initialize reference type static fields inline -dotnet_diagnostic.CA1810.severity = warning - -# CA1812: Avoid uninstantiated internal classes -dotnet_diagnostic.CA1812.severity = warning - -# CA1813: Avoid unsealed attributes -dotnet_diagnostic.CA1813.severity = none - -# CA1814: Prefer jagged arrays over multidimensional -dotnet_diagnostic.CA1814.severity = none - -# CA1815: Override equals and operator equals on value types -dotnet_diagnostic.CA1815.severity = warning - -# CA1816: Dispose methods should call SuppressFinalize -dotnet_diagnostic.CA1816.severity = none - -# CA1819: Properties should not return arrays -dotnet_diagnostic.CA1819.severity = none - -# CA1820: Test for empty strings using string length -dotnet_diagnostic.CA1820.severity = none - -# CA1821: Remove empty Finalizers -dotnet_diagnostic.CA1821.severity = none # TODO: warning - -# CA1822: Mark members as static -dotnet_diagnostic.CA1822.severity = warning -dotnet_code_quality.CA1822.api_surface = private, internal - -# CA1823: Avoid unused private fields -dotnet_diagnostic.CA1823.severity = warning - -# CA1824: Mark assemblies with NeutralResourcesLanguageAttribute -dotnet_diagnostic.CA1824.severity = warning - -# CA1825: Avoid zero-length array allocations -dotnet_diagnostic.CA1825.severity = warning - -# CA1826: Do not use Enumerable methods on indexable collections -dotnet_diagnostic.CA1826.severity = warning - -# CA1827: Do not use Count() or LongCount() when Any() can be used -dotnet_diagnostic.CA1827.severity = warning - -# CA1828: Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used -dotnet_diagnostic.CA1828.severity = warning - -# CA1829: Use Length/Count property instead of Count() when available -dotnet_diagnostic.CA1829.severity = warning - -# CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder -dotnet_diagnostic.CA1830.severity = warning - -# CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate -dotnet_diagnostic.CA1831.severity = warning - -# CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate -dotnet_diagnostic.CA1832.severity = warning - -# CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate -dotnet_diagnostic.CA1833.severity = warning - -# CA1834: Consider using 'StringBuilder.Append(char)' when applicable -dotnet_diagnostic.CA1834.severity = warning - -# CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -dotnet_diagnostic.CA1835.severity = warning - -# CA1836: Prefer IsEmpty over Count -dotnet_diagnostic.CA1836.severity = warning - -# CA1837: Use 'Environment.ProcessId' -dotnet_diagnostic.CA1837.severity = warning - -# CA1838: Avoid 'StringBuilder' parameters for P/Invokes -dotnet_diagnostic.CA1838.severity = warning - -# CA1839: Use 'Environment.ProcessPath' -dotnet_diagnostic.CA1839.severity = warning - -# CA1840: Use 'Environment.CurrentManagedThreadId' -dotnet_diagnostic.CA1840.severity = warning - -# CA1841: Prefer Dictionary.Contains methods -dotnet_diagnostic.CA1841.severity = warning - -# CA1842: Do not use 'WhenAll' with a single task -dotnet_diagnostic.CA1842.severity = warning - -# CA1843: Do not use 'WaitAll' with a single task -dotnet_diagnostic.CA1843.severity = warning - -# CA1844: Provide memory-based overrides of async methods when subclassing 'Stream' -dotnet_diagnostic.CA1844.severity = warning - -# CA1845: Use span-based 'string.Concat' -dotnet_diagnostic.CA1845.severity = warning - -# CA1846: Prefer 'AsSpan' over 'Substring' -dotnet_diagnostic.CA1846.severity = warning - -# CA1847: Use char literal for a single character lookup -dotnet_diagnostic.CA1847.severity = warning - -# CA1848: Use the LoggerMessage delegates -dotnet_diagnostic.CA1848.severity = none - -# CA1849: Call async methods when in an async method -dotnet_diagnostic.CA1849.severity = suggestion - -# CA1850: Prefer static 'HashData' method over 'ComputeHash' -dotnet_diagnostic.CA1850.severity = warning - -# CA1851: Possible multiple enumerations of 'IEnumerable' collection -dotnet_diagnostic.CA1851.severity = suggestion - -# CA1852: Seal internal types -dotnet_diagnostic.CA1852.severity = warning - -# CA1853: Unnecessary call to 'Dictionary.ContainsKey(key)' -dotnet_diagnostic.CA1853.severity = warning - -# CA1854: Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method -dotnet_diagnostic.CA1854.severity = warning - -# CA2000: Dispose objects before losing scope -dotnet_diagnostic.CA2000.severity = none - -# CA2002: Do not lock on objects with weak identity -dotnet_diagnostic.CA2002.severity = none - -# CA2007: Consider calling ConfigureAwait on the awaited task -dotnet_diagnostic.CA2007.severity = warning - -# CA2008: Do not create tasks without passing a TaskScheduler -dotnet_diagnostic.CA2008.severity = warning - -# CA2009: Do not call ToImmutableCollection on an ImmutableCollection value -dotnet_diagnostic.CA2009.severity = warning - -# CA2011: Avoid infinite recursion -dotnet_diagnostic.CA2011.severity = warning - -# CA2012: Use ValueTasks correctly -dotnet_diagnostic.CA2012.severity = warning - -# CA2013: Do not use ReferenceEquals with value types -dotnet_diagnostic.CA2013.severity = warning - -# CA2014: Do not use stackalloc in loops -dotnet_diagnostic.CA2014.severity = warning - -# CA2015: Do not define finalizers for types derived from MemoryManager -dotnet_diagnostic.CA2015.severity = warning - -# CA2016: Forward the 'CancellationToken' parameter to methods -dotnet_diagnostic.CA2016.severity = warning - -# CA2017: Parameter count mismatch -dotnet_diagnostic.CA2017.severity = warning - -# CA2018: 'Buffer.BlockCopy' expects the number of bytes to be copied for the 'count' argument -dotnet_diagnostic.CA2018.severity = warning - -# CA2019: Improper 'ThreadStatic' field initialization -dotnet_diagnostic.CA2019.severity = warning - -# CA2100: Review SQL queries for security vulnerabilities -dotnet_diagnostic.CA2100.severity = none - -# CA2101: Specify marshaling for P/Invoke string arguments -dotnet_diagnostic.CA2101.severity = none - -# CA2109: Review visible event handlers -dotnet_diagnostic.CA2109.severity = none - -# CA2119: Seal methods that satisfy private interfaces -dotnet_diagnostic.CA2119.severity = none - -# CA2153: Do Not Catch Corrupted State Exceptions -dotnet_diagnostic.CA2153.severity = none - -# CA2200: Rethrow to preserve stack details -dotnet_diagnostic.CA2200.severity = warning - -# CA2201: Do not raise reserved exception types -dotnet_diagnostic.CA2201.severity = none - -# CA2207: Initialize value type static fields inline -dotnet_diagnostic.CA2207.severity = warning - -# CA2208: Instantiate argument exceptions correctly -dotnet_diagnostic.CA2208.severity = none # TODO: warning -dotnet_code_quality.CA2208.api_surface = public - -# CA2211: Non-constant fields should not be visible -dotnet_diagnostic.CA2211.severity = none - -# CA2213: Disposable fields should be disposed -dotnet_diagnostic.CA2213.severity = none - -# CA2214: Do not call overridable methods in constructors -dotnet_diagnostic.CA2214.severity = none - -# CA2215: Dispose methods should call base class dispose -dotnet_diagnostic.CA2215.severity = none - -# CA2216: Disposable types should declare finalizer -dotnet_diagnostic.CA2216.severity = none - -# CA2217: Do not mark enums with FlagsAttribute -dotnet_diagnostic.CA2217.severity = none - -# CA2218: Override GetHashCode on overriding Equals -dotnet_diagnostic.CA2218.severity = none - -# CA2219: Do not raise exceptions in finally clauses -dotnet_diagnostic.CA2219.severity = none - -# CA2224: Override Equals on overloading operator equals -dotnet_diagnostic.CA2224.severity = none - -# CA2225: Operator overloads have named alternates -dotnet_diagnostic.CA2225.severity = none - -# CA2226: Operators should have symmetrical overloads -dotnet_diagnostic.CA2226.severity = none - -# CA2227: Collection properties should be read only -dotnet_diagnostic.CA2227.severity = none - -# CA2229: Implement serialization constructors -dotnet_diagnostic.CA2229.severity = warning - -# CA2231: Overload operator equals on overriding value type Equals -dotnet_diagnostic.CA2231.severity = none - -# CA2234: Pass system uri objects instead of strings -dotnet_diagnostic.CA2234.severity = none - -# CA2235: Mark all non-serializable fields -dotnet_diagnostic.CA2235.severity = none - -# CA2237: Mark ISerializable types with serializable -dotnet_diagnostic.CA2237.severity = none - -# CA2241: Provide correct arguments to formatting methods -dotnet_diagnostic.CA2241.severity = warning - -# CA2242: Test for NaN correctly -dotnet_diagnostic.CA2242.severity = warning - -# CA2243: Attribute string literals should parse correctly -dotnet_diagnostic.CA2243.severity = warning - -# CA2244: Do not duplicate indexed element initializations -dotnet_diagnostic.CA2244.severity = warning - -# CA2245: Do not assign a property to itself -dotnet_diagnostic.CA2245.severity = none # TODO: warning - -# CA2246: Assigning symbol and its member in the same statement -dotnet_diagnostic.CA2246.severity = warning - -# CA2247: Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum -dotnet_diagnostic.CA2247.severity = warning - -# CA2248: Provide correct 'enum' argument to 'Enum.HasFlag' -dotnet_diagnostic.CA2248.severity = warning - -# CA2249: Consider using 'string.Contains' instead of 'string.IndexOf' -dotnet_diagnostic.CA2249.severity = warning - -# CA2250: Use 'ThrowIfCancellationRequested' -dotnet_diagnostic.CA2250.severity = warning - -# CA2251: Use 'string.Equals' -dotnet_diagnostic.CA2251.severity = warning - -# CA2252: This API requires opting into preview features -dotnet_diagnostic.CA2252.severity = error - -# CA2253: Named placeholders should not be numeric values -dotnet_diagnostic.CA2253.severity = warning - -# CA2254: Template should be a static expression -dotnet_diagnostic.CA2254.severity = none - -# CA2255: The 'ModuleInitializer' attribute should not be used in libraries -dotnet_diagnostic.CA2255.severity = warning - -# CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface -dotnet_diagnostic.CA2256.severity = warning - -# CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static' -dotnet_diagnostic.CA2257.severity = warning - -# CA2258: Providing a 'DynamicInterfaceCastableImplementation' interface in Visual Basic is unsupported -dotnet_diagnostic.CA2258.severity = warning - -# CA2259: 'ThreadStatic' only affects static fields -dotnet_diagnostic.CA2259.severity = warning - -# CA2300: Do not use insecure deserializer BinaryFormatter -dotnet_diagnostic.CA2300.severity = none - -# CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder -dotnet_diagnostic.CA2301.severity = none - -# CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize -dotnet_diagnostic.CA2302.severity = none - -# CA2305: Do not use insecure deserializer LosFormatter -dotnet_diagnostic.CA2305.severity = none - -# CA2310: Do not use insecure deserializer NetDataContractSerializer -dotnet_diagnostic.CA2310.severity = none - -# CA2311: Do not deserialize without first setting NetDataContractSerializer.Binder -dotnet_diagnostic.CA2311.severity = none - -# CA2312: Ensure NetDataContractSerializer.Binder is set before deserializing -dotnet_diagnostic.CA2312.severity = none - -# CA2315: Do not use insecure deserializer ObjectStateFormatter -dotnet_diagnostic.CA2315.severity = none - -# CA2321: Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver -dotnet_diagnostic.CA2321.severity = none - -# CA2322: Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing -dotnet_diagnostic.CA2322.severity = none - -# CA2326: Do not use TypeNameHandling values other than None -dotnet_diagnostic.CA2326.severity = none - -# CA2327: Do not use insecure JsonSerializerSettings -dotnet_diagnostic.CA2327.severity = none - -# CA2328: Ensure that JsonSerializerSettings are secure -dotnet_diagnostic.CA2328.severity = none - -# CA2329: Do not deserialize with JsonSerializer using an insecure configuration -dotnet_diagnostic.CA2329.severity = none - -# CA2330: Ensure that JsonSerializer has a secure configuration when deserializing -dotnet_diagnostic.CA2330.severity = none - -# CA2350: Do not use DataTable.ReadXml() with untrusted data -dotnet_diagnostic.CA2350.severity = none - -# CA2351: Do not use DataSet.ReadXml() with untrusted data -dotnet_diagnostic.CA2351.severity = none - -# CA2352: Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks -dotnet_diagnostic.CA2352.severity = none - -# CA2353: Unsafe DataSet or DataTable in serializable type -dotnet_diagnostic.CA2353.severity = none - -# CA2354: Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attacks -dotnet_diagnostic.CA2354.severity = none - -# CA2355: Unsafe DataSet or DataTable type found in deserializable object graph -dotnet_diagnostic.CA2355.severity = none - -# CA2356: Unsafe DataSet or DataTable type in web deserializable object graph -dotnet_diagnostic.CA2356.severity = none - -# CA2361: Ensure auto-generated class containing DataSet.ReadXml() is not used with untrusted data -dotnet_diagnostic.CA2361.severity = none - -# CA2362: Unsafe DataSet or DataTable in auto-generated serializable type can be vulnerable to remote code execution attacks -dotnet_diagnostic.CA2362.severity = none - -# CA3001: Review code for SQL injection vulnerabilities -dotnet_diagnostic.CA3001.severity = none - -# CA3002: Review code for XSS vulnerabilities -dotnet_diagnostic.CA3002.severity = none - -# CA3003: Review code for file path injection vulnerabilities -dotnet_diagnostic.CA3003.severity = none - -# CA3004: Review code for information disclosure vulnerabilities -dotnet_diagnostic.CA3004.severity = none - -# CA3005: Review code for LDAP injection vulnerabilities -dotnet_diagnostic.CA3005.severity = none - -# CA3006: Review code for process command injection vulnerabilities -dotnet_diagnostic.CA3006.severity = none - -# CA3007: Review code for open redirect vulnerabilities -dotnet_diagnostic.CA3007.severity = none - -# CA3008: Review code for XPath injection vulnerabilities -dotnet_diagnostic.CA3008.severity = none - -# CA3009: Review code for XML injection vulnerabilities -dotnet_diagnostic.CA3009.severity = none - -# CA3010: Review code for XAML injection vulnerabilities -dotnet_diagnostic.CA3010.severity = none - -# CA3011: Review code for DLL injection vulnerabilities -dotnet_diagnostic.CA3011.severity = none - -# CA3012: Review code for regex injection vulnerabilities -dotnet_diagnostic.CA3012.severity = none - -# CA3061: Do Not Add Schema By URL -dotnet_diagnostic.CA3061.severity = warning - -# CA3075: Insecure DTD processing in XML -dotnet_diagnostic.CA3075.severity = warning - -# CA3076: Insecure XSLT script processing. -dotnet_diagnostic.CA3076.severity = warning - -# CA3077: Insecure Processing in API Design, XmlDocument and XmlTextReader -dotnet_diagnostic.CA3077.severity = warning - -# CA3147: Mark Verb Handlers With Validate Antiforgery Token -dotnet_diagnostic.CA3147.severity = warning - -# CA5350: Do Not Use Weak Cryptographic Algorithms -dotnet_diagnostic.CA5350.severity = warning - -# CA5351: Do Not Use Broken Cryptographic Algorithms -dotnet_diagnostic.CA5351.severity = warning - -# CA5358: Review cipher mode usage with cryptography experts -dotnet_diagnostic.CA5358.severity = none - -# CA5359: Do Not Disable Certificate Validation -dotnet_diagnostic.CA5359.severity = warning - -# CA5360: Do Not Call Dangerous Methods In Deserialization -dotnet_diagnostic.CA5360.severity = warning - -# CA5361: Do Not Disable SChannel Use of Strong Crypto -dotnet_diagnostic.CA5361.severity = warning - -# CA5362: Potential reference cycle in deserialized object graph -dotnet_diagnostic.CA5362.severity = none - -# CA5363: Do Not Disable Request Validation -dotnet_diagnostic.CA5363.severity = warning - -# CA5364: Do Not Use Deprecated Security Protocols -dotnet_diagnostic.CA5364.severity = warning - -# CA5365: Do Not Disable HTTP Header Checking -dotnet_diagnostic.CA5365.severity = warning - -# CA5366: Use XmlReader for 'DataSet.ReadXml()' -dotnet_diagnostic.CA5366.severity = none - -# CA5367: Do Not Serialize Types With Pointer Fields -dotnet_diagnostic.CA5367.severity = none - -# CA5368: Set ViewStateUserKey For Classes Derived From Page -dotnet_diagnostic.CA5368.severity = warning - -# CA5369: Use XmlReader for 'XmlSerializer.Deserialize()' -dotnet_diagnostic.CA5369.severity = none - -# CA5370: Use XmlReader for XmlValidatingReader constructor -dotnet_diagnostic.CA5370.severity = warning - -# CA5371: Use XmlReader for 'XmlSchema.Read()' -dotnet_diagnostic.CA5371.severity = none - -# CA5372: Use XmlReader for XPathDocument constructor -dotnet_diagnostic.CA5372.severity = none - -# CA5373: Do not use obsolete key derivation function -dotnet_diagnostic.CA5373.severity = warning - -# CA5374: Do Not Use XslTransform -dotnet_diagnostic.CA5374.severity = warning - -# CA5375: Do Not Use Account Shared Access Signature -dotnet_diagnostic.CA5375.severity = none - -# CA5376: Use SharedAccessProtocol HttpsOnly -dotnet_diagnostic.CA5376.severity = warning - -# CA5377: Use Container Level Access Policy -dotnet_diagnostic.CA5377.severity = warning - -# CA5378: Do not disable ServicePointManagerSecurityProtocols -dotnet_diagnostic.CA5378.severity = warning - -# CA5379: Ensure Key Derivation Function algorithm is sufficiently strong -dotnet_diagnostic.CA5379.severity = warning - -# CA5380: Do Not Add Certificates To Root Store -dotnet_diagnostic.CA5380.severity = warning - -# CA5381: Ensure Certificates Are Not Added To Root Store -dotnet_diagnostic.CA5381.severity = warning - -# CA5382: Use Secure Cookies In ASP.NET Core -dotnet_diagnostic.CA5382.severity = none - -# CA5383: Ensure Use Secure Cookies In ASP.NET Core -dotnet_diagnostic.CA5383.severity = none - -# CA5384: Do Not Use Digital Signature Algorithm (DSA) -dotnet_diagnostic.CA5384.severity = warning - -# CA5385: Use Rivest-Shamir-Adleman (RSA) Algorithm With Sufficient Key Size -dotnet_diagnostic.CA5385.severity = warning - -# CA5386: Avoid hardcoding SecurityProtocolType value -dotnet_diagnostic.CA5386.severity = none - -# CA5387: Do Not Use Weak Key Derivation Function With Insufficient Iteration Count -dotnet_diagnostic.CA5387.severity = none - -# CA5388: Ensure Sufficient Iteration Count When Using Weak Key Derivation Function -dotnet_diagnostic.CA5388.severity = none - -# CA5389: Do Not Add Archive Item's Path To The Target File System Path -dotnet_diagnostic.CA5389.severity = none - -# CA5390: Do not hard-code encryption key -dotnet_diagnostic.CA5390.severity = none - -# CA5391: Use antiforgery tokens in ASP.NET Core MVC controllers -dotnet_diagnostic.CA5391.severity = none - -# CA5392: Use DefaultDllImportSearchPaths attribute for P/Invokes -dotnet_diagnostic.CA5392.severity = none - -# CA5393: Do not use unsafe DllImportSearchPath value -dotnet_diagnostic.CA5393.severity = none - -# CA5394: Do not use insecure randomness -dotnet_diagnostic.CA5394.severity = none - -# CA5395: Miss HttpVerb attribute for action methods -dotnet_diagnostic.CA5395.severity = none - -# CA5396: Set HttpOnly to true for HttpCookie -dotnet_diagnostic.CA5396.severity = none - -# CA5397: Do not use deprecated SslProtocols values -dotnet_diagnostic.CA5397.severity = none - -# CA5398: Avoid hardcoded SslProtocols values -dotnet_diagnostic.CA5398.severity = none - -# CA5399: HttpClients should enable certificate revocation list checks -dotnet_diagnostic.CA5399.severity = none - -# CA5400: Ensure HttpClient certificate revocation list check is not disabled -dotnet_diagnostic.CA5400.severity = none - -# CA5401: Do not use CreateEncryptor with non-default IV -dotnet_diagnostic.CA5401.severity = none - -# CA5402: Use CreateEncryptor with the default IV -dotnet_diagnostic.CA5402.severity = none - -# CA5403: Do not hard-code certificate -dotnet_diagnostic.CA5403.severity = none - -# CA5404: Do not disable token validation checks -dotnet_diagnostic.CA5404.severity = none - -# CA5405: Do not always skip token validation in delegates -dotnet_diagnostic.CA5405.severity = none - -# IL3000: Avoid using accessing Assembly file path when publishing as a single-file -dotnet_diagnostic.IL3000.severity = none # TODO: warning - -# IL3001: Avoid using accessing Assembly file path when publishing as a single-file -dotnet_diagnostic.IL3001.severity = warning - -# IL3002: Using member with RequiresAssemblyFilesAttribute can break functionality when embedded in a single-file app -dotnet_diagnostic.IL3002.severity = warning - -# RS0041: Public members should not use oblivious types -dotnet_diagnostic.RS0041.severity = none - -# SA0001: XML comments -dotnet_diagnostic.SA0001.severity = none - -# SA0002: Invalid settings file -dotnet_diagnostic.SA0002.severity = none - -# SA1000: Spacing around keywords -# suggestion until https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3478 is resolved -dotnet_diagnostic.SA1000.severity = suggestion - -# SA1001: Commas should not be preceded by whitespace -dotnet_diagnostic.SA1001.severity = warning - -# SA1002: Semicolons should not be preceded by a space -dotnet_diagnostic.SA1002.severity = none - -# SA1003: Operator should not appear at the end of a line -dotnet_diagnostic.SA1003.severity = none - -# SA1004: Documentation line should begin with a space -dotnet_diagnostic.SA1004.severity = none - -# SA1005: Single line comment should begin with a space -dotnet_diagnostic.SA1005.severity = warning - -# SA1006: Preprocessor keywords should not be preceded by space -dotnet_diagnostic.SA1006.severity = none - -# SA1007: Operator keyword should be followed by space -dotnet_diagnostic.SA1007.severity = none - -# SA1008: Opening parenthesis should not be preceded by a space -dotnet_diagnostic.SA1008.severity = none - -# SA1009: Closing parenthesis should not be followed by a space -dotnet_diagnostic.SA1009.severity = none - -# SA1010: Opening square brackets should not be preceded by a space -dotnet_diagnostic.SA1010.severity = none - -# SA1011: Closing square bracket should be followed by a space -dotnet_diagnostic.SA1011.severity = none - -# SA1012: Opening brace should be followed by a space -dotnet_diagnostic.SA1012.severity = none - -# SA1013: Closing brace should be preceded by a space -dotnet_diagnostic.SA1013.severity = none - -# SA1014: Opening generic brackets should not be preceded by a space -dotnet_diagnostic.SA1014.severity = warning - -# SA1015: Closing generic bracket should not be followed by a space -dotnet_diagnostic.SA1015.severity = none - -# SA1016: Opening attribute brackets should be spaced correctly -dotnet_diagnostic.SA1016.severity = none - -# SA1017: Closing attribute brackets should be spaced correctly -dotnet_diagnostic.SA1017.severity = none - -# SA1018: Nullable type symbol should not be preceded by a space -dotnet_diagnostic.SA1018.severity = warning - -# SA1019: Member access symbols should be spaced correctly -dotnet_diagnostic.SA1019.severity = none - -# SA1020: Increment symbol should not be preceded by a space -dotnet_diagnostic.SA1020.severity = warning - -# SA1021: Negative sign should be preceded by a space -dotnet_diagnostic.SA1021.severity = none - -# SA1022: Positive signs should be spaced correctly -dotnet_diagnostic.SA1022.severity = none - -# SA1023: Dereference symbol '*' should not be preceded by a space." -dotnet_diagnostic.SA1023.severity = none - -# SA1024: Colon should be followed by a space -dotnet_diagnostic.SA1024.severity = none - -# SA1025: Code should not contain multiple whitespace characters in a row -dotnet_diagnostic.SA1025.severity = none - -# SA1026: Keyword followed by span or blank line -dotnet_diagnostic.SA1026.severity = warning - -# SA1027: Tabs and spaces should be used correctly -dotnet_diagnostic.SA1027.severity = warning - -# SA1028: Code should not contain trailing whitespace -dotnet_diagnostic.SA1028.severity = warning - -# SA1100: Do not prefix calls with base unless local implementation exists -dotnet_diagnostic.SA1100.severity = none - -# SA1101: Prefix local calls with this -dotnet_diagnostic.SA1101.severity = none - -# SA1102: Query clause should follow previous clause -dotnet_diagnostic.SA1102.severity = warning - -# SA1105: Query clauses spanning multiple lines should begin on own line -dotnet_diagnostic.SA1105.severity = warning - -# SA1104: Query clause should begin on new line when previous clause spans multiple lines -dotnet_diagnostic.SA1104.severity = none - -# SA1105: Query clauses spanning multiple lines should begin on own line -dotnet_diagnostic.SA1105.severity = none - -# SA1106: Code should not contain empty statements -dotnet_diagnostic.SA1106.severity = none - -# SA1107: Code should not contain multiple statements on one line -dotnet_diagnostic.SA1107.severity = none - -# SA1108: Block statements should not contain embedded comments -dotnet_diagnostic.SA1108.severity = none - -# SA1109: Block statements should not contain embedded regions -dotnet_diagnostic.SA1109.severity = none - -# SA1110: Opening parenthesis or bracket should be on declaration line -dotnet_diagnostic.SA1110.severity = none - -# SA1111: Closing parenthesis should be on line of last parameter -dotnet_diagnostic.SA1111.severity = none - -# SA1112: Closing parenthesis should be on line of opening parenthesis -dotnet_diagnostic.SA1112.severity = none - -# SA1113: Comma should be on the same line as previous parameter -dotnet_diagnostic.SA1113.severity = warning - -# SA1114: Parameter list should follow declaration -dotnet_diagnostic.SA1114.severity = none - -# SA1115: Parameter should begin on the line after the previous parameter -dotnet_diagnostic.SA1115.severity = warning - -# SA1116: Split parameters should start on line after declaration -dotnet_diagnostic.SA1116.severity = none - -# SA1117: Parameters should be on same line or separate lines -dotnet_diagnostic.SA1117.severity = none - -# SA1118: Parameter should not span multiple lines -dotnet_diagnostic.SA1118.severity = none - -# SA1119: Statement should not use unnecessary parenthesis -dotnet_diagnostic.SA1119.severity = none - -# SA1120: Comments should contain text -dotnet_diagnostic.SA1120.severity = none - -# SA1121: Use built-in type alias -dotnet_diagnostic.SA1121.severity = warning - -# SA1122: Use string.Empty for empty strings -dotnet_diagnostic.SA1122.severity = none - -# SA1123: Region should not be located within a code element -dotnet_diagnostic.SA1123.severity = none - -# SA1124: Do not use regions -dotnet_diagnostic.SA1124.severity = none - -# SA1125: Use shorthand for nullable types -dotnet_diagnostic.SA1125.severity = none - -# SA1126: Prefix calls correctly -dotnet_diagnostic.SA1126.severity = none - -# SA1127: Generic type constraints should be on their own line -dotnet_diagnostic.SA1127.severity = none - -# SA1128: Put constructor initializers on their own line -dotnet_diagnostic.SA1128.severity = none - -# SA1129: Do not use default value type constructor -dotnet_diagnostic.SA1129.severity = warning - -# SA1130: Use lambda syntax -dotnet_diagnostic.SA1130.severity = none - -# SA1131: Constant values should appear on the right-hand side of comparisons -dotnet_diagnostic.SA1131.severity = warning - -# SA1132: Do not combine fields -dotnet_diagnostic.SA1132.severity = none - -# SA1133: Do not combine attributes -dotnet_diagnostic.SA1133.severity = none - -# SA1134: Each attribute should be placed on its own line of code -dotnet_diagnostic.SA1134.severity = none - -# SA1135: Using directive should be qualified -dotnet_diagnostic.SA1135.severity = none - -# SA1136: Enum values should be on separate lines -dotnet_diagnostic.SA1136.severity = none - -# SA1137: Elements should have the same indentation -dotnet_diagnostic.SA1137.severity = none - -# SA1139: Use literal suffix notation instead of casting -dotnet_diagnostic.SA1139.severity = none - -# SA1141: Use tuple syntax -dotnet_diagnostic.SA1141.severity = warning - -# SA1142: Refer to tuple elements by name -dotnet_diagnostic.SA1142.severity = warning - -# SA1200: Using directive should appear within a namespace declaration -dotnet_diagnostic.SA1200.severity = none - -# SA1201: Elements should appear in the correct order -dotnet_diagnostic.SA1201.severity = none - -# SA1202: Elements should be ordered by access -dotnet_diagnostic.SA1202.severity = none - -# SA1203: Constants should appear before fields -dotnet_diagnostic.SA1203.severity = none - -# SA1204: Static elements should appear before instance elements -dotnet_diagnostic.SA1204.severity = none - -# SA1205: Partial elements should declare an access modifier -dotnet_diagnostic.SA1205.severity = warning - -# SA1206: Keyword ordering - TODO Re-enable as warning after https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3527 -dotnet_diagnostic.SA1206.severity = suggestion - -# SA1207: Protected should come before internal -dotnet_diagnostic.SA1207.severity = none - -# SA1208: Using directive ordering -dotnet_diagnostic.SA1208.severity = none - -# SA1209: Using alias directives should be placed after all using namespace directives -dotnet_diagnostic.SA1209.severity = none - -# SA1210: Using directives should be ordered alphabetically by the namespaces -dotnet_diagnostic.SA1210.severity = none - -# SA1211: Using alias directive ordering -dotnet_diagnostic.SA1211.severity = none - -# SA1212: A get accessor appears after a set accessor within a property or indexer -dotnet_diagnostic.SA1212.severity = warning - -# SA1213: Event accessors should follow order -dotnet_diagnostic.SA1213.severity = none - -# SA1214: Readonly fields should appear before non-readonly fields -dotnet_diagnostic.SA1214.severity = none - -# SA1216: Using static directives should be placed at the correct location -dotnet_diagnostic.SA1216.severity = none - -# SA1217: Using static directives should be ordered alphabetically -dotnet_diagnostic.SA1217.severity = none - -# SA1300: Element should begin with an uppercase letter -dotnet_diagnostic.SA1300.severity = none - -# SA1301: Element should begin with lower-case letter -dotnet_diagnostic.SA1301.severity = none - -# SA1302: Interface names should begin with I -dotnet_diagnostic.SA1302.severity = none # TODO: warning - -# SA1303: Const field names should begin with upper-case letter -dotnet_diagnostic.SA1303.severity = none - -# SA1304: Non-private readonly fields should begin with upper-case letter -dotnet_diagnostic.SA1304.severity = none - -# SA1305: Field names should not use Hungarian notation -dotnet_diagnostic.SA1305.severity = none - -# SA1306: Field should begin with lower-case letter -dotnet_diagnostic.SA1306.severity = none - -# SA1307: Field should begin with upper-case letter -dotnet_diagnostic.SA1307.severity = none - -# SA1308: Field should not begin with the prefix 's_' -dotnet_diagnostic.SA1308.severity = none - -# SA1309: Field names should not begin with underscore -dotnet_diagnostic.SA1309.severity = none - -# SA1310: Field should not contain an underscore -dotnet_diagnostic.SA1310.severity = none - -# SA1311: Static readonly fields should begin with upper-case letter -dotnet_diagnostic.SA1311.severity = none - -# SA1312: Variable should begin with lower-case letter -dotnet_diagnostic.SA1312.severity = none - -# SA1313: Parameter should begin with lower-case letter -dotnet_diagnostic.SA1313.severity = none - -# SA1314: Type parameter names should begin with T -dotnet_diagnostic.SA1314.severity = none - -# SA1316: Tuple element names should use correct casing -dotnet_diagnostic.SA1316.severity = none - -# SA1400: Member should declare an access modifier -dotnet_diagnostic.SA1400.severity = warning - -# SA1401: Fields should be private -dotnet_diagnostic.SA1401.severity = none - -# SA1402: File may only contain a single type -dotnet_diagnostic.SA1402.severity = none - -# SA1403: File may only contain a single namespace -dotnet_diagnostic.SA1403.severity = none - -# SA1404: Code analysis suppression should have justification -dotnet_diagnostic.SA1404.severity = none # TODO: warning - -# SA1405: Debug.Assert should provide message text -dotnet_diagnostic.SA1405.severity = none - -# SA1406: Debug.Fail should provide message text -dotnet_diagnostic.SA1406.severity = none - -# SA1407: Arithmetic expressions should declare precedence -dotnet_diagnostic.SA1407.severity = none - -# SA1408: Conditional expressions should declare precedence -dotnet_diagnostic.SA1408.severity = warning - -# SA1409: Remove unnecessary code -dotnet_diagnostic.SA1409.severity = none - -# SA1410: Remove delegate parens when possible -dotnet_diagnostic.SA1410.severity = warning - -# SA1411: Attribute constructor shouldn't use unnecessary parenthesis -dotnet_diagnostic.SA1411.severity = warning - -# SA1412: Store files as UTF-8 with byte order mark -dotnet_diagnostic.SA1412.severity = none - -# SA1413: Use trailing comma in multi-line initializers -dotnet_diagnostic.SA1413.severity = none - -# SA1414: Tuple types in signatures should have element names -dotnet_diagnostic.SA1414.severity = none - -# SA1500: Braces for multi-line statements should not share line -dotnet_diagnostic.SA1500.severity = error - -# SA1501: Statement should not be on a single line -dotnet_diagnostic.SA1501.severity = none - -# SA1502: Element should not be on a single line -dotnet_diagnostic.SA1502.severity = none - -# SA1503: Braces should not be omitted -dotnet_diagnostic.SA1503.severity = none - -# SA1504: All accessors should be single-line or multi-line -dotnet_diagnostic.SA1504.severity = none - -# SA1505: An opening brace should not be followed by a blank line -dotnet_diagnostic.SA1505.severity = warning - -# SA1506: Element documentation headers should not be followed by blank line -dotnet_diagnostic.SA1506.severity = none - -# SA1507: Code should not contain multiple blank lines in a row -dotnet_diagnostic.SA1507.severity = warning - -# SA1508: A closing brace should not be preceded by a blank line -dotnet_diagnostic.SA1508.severity = warning - -# SA1509: Opening braces should not be preceded by blank line -dotnet_diagnostic.SA1509.severity = warning - -# SA1510: 'else' statement should not be preceded by a blank line -dotnet_diagnostic.SA1510.severity = none - -# SA1511: While-do footer should not be preceded by blank line -dotnet_diagnostic.SA1511.severity = none - -# SA1512: Single-line comments should not be followed by blank line -dotnet_diagnostic.SA1512.severity = none - -# SA1513: Closing brace should be followed by blank line -dotnet_diagnostic.SA1513.severity = error - -# SA1514: Element documentation header should be preceded by blank line -dotnet_diagnostic.SA1514.severity = none - -# SA1515: Single-line comment should be preceded by blank line -dotnet_diagnostic.SA1515.severity = none - -# SA1516: Elements should be separated by blank line -dotnet_diagnostic.SA1516.severity = none - -# SA1517: Code should not contain blank lines at start of file -dotnet_diagnostic.SA1517.severity = warning - -# SA1518: Code should not contain blank lines at the end of the file -dotnet_diagnostic.SA1518.severity = warning - -# SA1519: Braces should not be omitted from multi-line child statement -dotnet_diagnostic.SA1519.severity = none - -# SA1520: Use braces consistently -dotnet_diagnostic.SA1520.severity = none - -# SA1600: Elements should be documented -dotnet_diagnostic.SA1600.severity = none - -# SA1601: Partial elements should be documented -dotnet_diagnostic.SA1601.severity = none - -# SA1602: Enumeration items should be documented -dotnet_diagnostic.SA1602.severity = none - -# SA1603: Documentation should contain valid XML -dotnet_diagnostic.SA1603.severity = none - -# SA1604: Element documentation should have summary -dotnet_diagnostic.SA1604.severity = none - -# SA1605: Partial element documentation should have summary -dotnet_diagnostic.SA1605.severity = none - -# SA1606: Element documentation should have summary text -dotnet_diagnostic.SA1606.severity = none - -# SA1607: Partial element documentation should have summary text -dotnet_diagnostic.SA1607.severity = none - -# SA1608: Element documentation should not have default summary -dotnet_diagnostic.SA1608.severity = none - -# SA1609: Property documentation should have value -dotnet_diagnostic.SA1609.severity = none - -# SA1610: Property documentation should have value text -dotnet_diagnostic.SA1610.severity = none - -# SA1611: The documentation for parameter 'message' is missing -dotnet_diagnostic.SA1611.severity = none - -# SA1612: The parameter documentation is at incorrect position -dotnet_diagnostic.SA1612.severity = none - -# SA1613: Element parameter documentation should declare parameter name -dotnet_diagnostic.SA1613.severity = none - -# SA1614: Element parameter documentation should have text -dotnet_diagnostic.SA1614.severity = none - -# SA1615: Element return value should be documented -dotnet_diagnostic.SA1615.severity = none - -# SA1616: Element return value documentation should have text -dotnet_diagnostic.SA1616.severity = none - -# SA1617: Void return value should not be documented -dotnet_diagnostic.SA1617.severity = none - -# SA1618: The documentation for type parameter is missing -dotnet_diagnostic.SA1618.severity = none - -# SA1619: The documentation for type parameter is missing -dotnet_diagnostic.SA1619.severity = none - -# SA1620: Generic type parameter documentation should match type parameters -dotnet_diagnostic.SA1620.severity = none - -# SA1621: Generic type parameter documentation should declare parameter name -dotnet_diagnostic.SA1621.severity = none - -# SA1622: Generic type parameter documentation should have text -dotnet_diagnostic.SA1622.severity = none - -# SA1623: Property documentation text -dotnet_diagnostic.SA1623.severity = none - -# SA1624: Because the property only contains a visible get accessor, the documentation summary text should begin with 'Gets' -dotnet_diagnostic.SA1624.severity = none - -# SA1625: Element documentation should not be copied and pasted -dotnet_diagnostic.SA1625.severity = none - -# SA1626: Single-line comments should not use documentation style slashes -dotnet_diagnostic.SA1626.severity = none - -# SA1627: The documentation text within the \'exception\' tag should not be empty -dotnet_diagnostic.SA1627.severity = none - -# SA1628: Documentation text should begin with a capital letter -dotnet_diagnostic.SA1628.severity = none - -# SA1629: Documentation text should end with a period -dotnet_diagnostic.SA1629.severity = none - -# SA1630: Documentation text should contain whitespace -dotnet_diagnostic.SA1630.severity = none - -# SA1631: Documentation should meet character percentage -dotnet_diagnostic.SA1631.severity = none - -# SA1632: Documentation text should meet minimum character length -dotnet_diagnostic.SA1632.severity = none - -# SA1633: File should have header -dotnet_diagnostic.SA1633.severity = none - -# SA1634: File header should show copyright -dotnet_diagnostic.SA1634.severity = none - -# SA1635: File header should have copyright text -dotnet_diagnostic.SA1635.severity = none - -# SA1636: File header copyright text should match -dotnet_diagnostic.SA1636.severity = none - -# SA1637: File header should contain file name -dotnet_diagnostic.SA1637.severity = none - -# SA1638: File header file name documentation should match file name -dotnet_diagnostic.SA1638.severity = none - -# SA1639: File header should have summary -dotnet_diagnostic.SA1639.severity = none - -# SA1640: File header should have valid company text -dotnet_diagnostic.SA1640.severity = none - -# SA1641: File header company name text should match -dotnet_diagnostic.SA1641.severity = none - -# SA1642: Constructor summary documentation should begin with standard text -dotnet_diagnostic.SA1642.severity = none - -# SA1643: Destructor summary documentation should begin with standard text -dotnet_diagnostic.SA1643.severity = none - -# SA1644: Documentation headers should not contain blank lines -dotnet_diagnostic.SA1644.severity = none - -# SA1645: Included documentation file does not exist -dotnet_diagnostic.SA1645.severity = none - -# SA1646: Included documentation XPath does not exist -dotnet_diagnostic.SA1646.severity = none - -# SA1647: Include node does not contain valid file and path -dotnet_diagnostic.SA1647.severity = none - -# SA1648: Inheritdoc should be used with inheriting class -dotnet_diagnostic.SA1648.severity = none - -# SA1649: File name should match first type name -dotnet_diagnostic.SA1649.severity = none - -# SA1650: Element documentation should be spelled correctly -dotnet_diagnostic.SA1650.severity = none - -# SA1651: Do not use placeholder elements -dotnet_diagnostic.SA1651.severity = none - -# SX1101: Do not prefix local calls with 'this.' -dotnet_diagnostic.SX1101.severity = none - -# SX1309: Field names should begin with underscore -dotnet_diagnostic.SX1309.severity = none - -# Static field names should begin with underscore -dotnet_diagnostic.SX1309S.severity = none - -# IDE0001: Simplify name -dotnet_diagnostic.IDE0001.severity = suggestion - -# IDE0002: Simplify member access -dotnet_diagnostic.IDE0002.severity = suggestion - -# IDE0003: Remove this or Me qualification -dotnet_diagnostic.IDE0003.severity = suggestion - -# IDE0004: Remove Unnecessary Cast -dotnet_diagnostic.IDE0004.severity = suggestion - -# IDE0005: Using directive is unnecessary. -dotnet_diagnostic.IDE0005.severity = suggestion - -# IDE0007: Use implicit type -dotnet_diagnostic.IDE0007.severity = silent - -# IDE0008: Use explicit type -dotnet_diagnostic.IDE0008.severity = suggestion - -# IDE0009: Add this or Me qualification -dotnet_diagnostic.IDE0009.severity = silent - -# IDE0010: Add missing cases -dotnet_diagnostic.IDE0010.severity = silent - -# IDE0011: Add braces -dotnet_diagnostic.IDE0011.severity = silent - -# IDE0016: Use 'throw' expression -dotnet_diagnostic.IDE0016.severity = silent - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = suggestion - -# IDE0018: Inline variable declaration -dotnet_diagnostic.IDE0018.severity = suggestion - -# IDE0019: Use pattern matching to avoid as followed by a null check -dotnet_diagnostic.IDE0019.severity = suggestion - -# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable) -dotnet_diagnostic.IDE0020.severity = warning - -# IDE0021: Use expression body for constructors -dotnet_diagnostic.IDE0021.severity = silent - -# IDE0022: Use expression body for methods -dotnet_diagnostic.IDE0022.severity = silent - -# IDE0023: Use expression body for operators -dotnet_diagnostic.IDE0023.severity = silent - -# IDE0024: Use expression body for operators -dotnet_diagnostic.IDE0024.severity = silent - -# IDE0025: Use expression body for properties -dotnet_diagnostic.IDE0025.severity = silent - -# IDE0026: Use expression body for indexers -dotnet_diagnostic.IDE0026.severity = silent - -# IDE0027: Use expression body for accessors -dotnet_diagnostic.IDE0027.severity = silent - -# IDE0028: Simplify collection initialization -dotnet_diagnostic.IDE0028.severity = suggestion - -# IDE0029: Use coalesce expression -dotnet_diagnostic.IDE0029.severity = warning - -# IDE0030: Use coalesce expression -dotnet_diagnostic.IDE0030.severity = warning - -# IDE0031: Use null propagation -dotnet_diagnostic.IDE0031.severity = warning - -# IDE0032: Use auto property -dotnet_diagnostic.IDE0032.severity = silent - -# IDE0033: Use explicitly provided tuple name -dotnet_diagnostic.IDE0033.severity = suggestion - -# IDE0034: Simplify 'default' expression -dotnet_diagnostic.IDE0034.severity = suggestion - -# IDE0035: Remove unreachable code -dotnet_diagnostic.IDE0035.severity = suggestion - -# IDE0036: Order modifiers -dotnet_diagnostic.IDE0036.severity = warning - -# IDE0037: Use inferred member name -dotnet_diagnostic.IDE0037.severity = silent - -# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable) -dotnet_diagnostic.IDE0038.severity = suggestion - -# IDE0039: Use local function -dotnet_diagnostic.IDE0039.severity = suggestion - -# IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = suggestion - -# IDE0041: Use 'is null' check -dotnet_diagnostic.IDE0041.severity = warning - -# IDE0042: Deconstruct variable declaration -dotnet_diagnostic.IDE0042.severity = silent - -# IDE0043: Invalid format string -dotnet_diagnostic.IDE0043.severity = warning - -# IDE0044: Add readonly modifier -dotnet_diagnostic.IDE0044.severity = suggestion - -# IDE0045: Use conditional expression for assignment -dotnet_diagnostic.IDE0045.severity = suggestion - -# IDE0046: Use conditional expression for return -dotnet_diagnostic.IDE0046.severity = suggestion - -# IDE0047: Remove unnecessary parentheses -dotnet_diagnostic.IDE0047.severity = silent - -# IDE0048: Add parentheses for clarity -dotnet_diagnostic.IDE0048.severity = silent - -# IDE0049: Use language keywords instead of framework type names for type references -dotnet_diagnostic.IDE0049.severity = warning - -# IDE0051: Remove unused private members -dotnet_diagnostic.IDE0051.severity = suggestion - -# IDE0052: Remove unread private members -dotnet_diagnostic.IDE0052.severity = suggestion - -# IDE0053: Use expression body for lambdas -dotnet_diagnostic.IDE0053.severity = silent - -# IDE0054: Use compound assignment -dotnet_diagnostic.IDE0054.severity = warning - -# IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = suggestion - -# IDE0056: Use index operator -dotnet_diagnostic.IDE0056.severity = suggestion - -# IDE0057: Use range operator -dotnet_diagnostic.IDE0057.severity = suggestion - -# IDE0058: Expression value is never used -dotnet_diagnostic.IDE0058.severity = silent - -# IDE0059: Unnecessary assignment of a value -dotnet_diagnostic.IDE0059.severity = none # TODO: warning - -# IDE0060: Remove unused parameter -dotnet_diagnostic.IDE0060.severity = silent -dotnet_code_quality_unused_parameters = non_public - -# IDE0061: Use expression body for local functions -dotnet_diagnostic.IDE0061.severity = silent - -# IDE0062: Make local function 'static' -dotnet_diagnostic.IDE0062.severity = warning - -# IDE0063: Use simple 'using' statement -dotnet_diagnostic.IDE0063.severity = silent - -# IDE0064: Make readonly fields writable -dotnet_diagnostic.IDE0064.severity = silent - -# IDE0065: Misplaced using directive -dotnet_diagnostic.IDE0065.severity = warning - -# IDE0066: Convert switch statement to expression -dotnet_diagnostic.IDE0066.severity = suggestion - -# IDE0070: Use 'System.HashCode' -dotnet_diagnostic.IDE0070.severity = suggestion - -# IDE0071: Simplify interpolation -dotnet_diagnostic.IDE0071.severity = warning - -# IDE0072: Add missing cases -dotnet_diagnostic.IDE0072.severity = silent - -# IDE0073: The file header is missing or not located at the top of the file -dotnet_diagnostic.IDE0073.severity = warning - -# IDE0074: Use compound assignment -dotnet_diagnostic.IDE0074.severity = warning - -# IDE0075: Simplify conditional expression -dotnet_diagnostic.IDE0075.severity = silent - -# IDE0076: Invalid global 'SuppressMessageAttribute' -dotnet_diagnostic.IDE0076.severity = warning - -# IDE0077: Avoid legacy format target in 'SuppressMessageAttribute' -dotnet_diagnostic.IDE0077.severity = silent - -# IDE0078: Use pattern matching -dotnet_diagnostic.IDE0078.severity = suggestion - -# IDE0079: Remove unnecessary suppression -dotnet_diagnostic.IDE0079.severity = suggestion - -# IDE0080: Remove unnecessary suppression operator -dotnet_diagnostic.IDE0080.severity = warning - -# IDE0081: Remove unnecessary suppression operator -dotnet_diagnostic.IDE0081.severity = none - -# IDE0082: 'typeof' can be converted to 'nameof' -dotnet_diagnostic.IDE0082.severity = warning - -# IDE0083: Use pattern matching -dotnet_diagnostic.IDE0083.severity = silent - -# IDE0084: Use pattern matching (IsNot operator) -dotnet_diagnostic.IDE0084.severity = none - -# IDE0090: Use 'new(...)' -dotnet_diagnostic.IDE0090.severity = silent - -# IDE0100: Remove redundant equality -dotnet_diagnostic.IDE0100.severity = warning - -# IDE0110: Remove unnecessary discard -dotnet_diagnostic.IDE0110.severity = warning - -# IDE0120: Simplify LINQ expression -dotnet_diagnostic.IDE0120.severity = none - -# IDE0130: Namespace does not match folder structure -dotnet_diagnostic.IDE0130.severity = silent - -# IDE0140: Simplify object creation -dotnet_diagnostic.IDE0140.severity = none - -# IDE0150: Prefer 'null' check over type check -dotnet_diagnostic.IDE0150.severity = silent - -# IDE0160: Convert to block scoped namespace -dotnet_diagnostic.IDE0160.severity = silent - -# IDE0161: Convert to file-scoped namespace -dotnet_diagnostic.IDE0161.severity = silent - -# IDE0170: Simplify property pattern -dotnet_diagnostic.IDE0170.severity = warning - -# IDE0180: Use tuple swap -dotnet_diagnostic.IDE0180.severity = suggestion - -# IDE0200: Remove unnecessary lambda expression -dotnet_diagnostic.IDE0200.severity = warning - -# IDE0210: Use top-level statements -dotnet_diagnostic.IDE0210.severity = silent - -# IDE0211: Use program main -dotnet_diagnostic.IDE0211.severity = silent - -# IDE0220: foreach cast -dotnet_diagnostic.IDE0220.severity = silent - -# IDE0230: Use UTF8 string literal -dotnet_diagnostic.IDE0230.severity = suggestion - -# IDE1005: Delegate invocation can be simplified. -dotnet_diagnostic.IDE1005.severity = warning - -# IDE1006: Naming styles -# This rule is configured by individual rules in .editorconfig. Do not override the severity here. -#dotnet_diagnostic.IDE1006.severity = silent - -# IDE2000: Allow multiple blank lines -dotnet_diagnostic.IDE2000.severity = silent - -# IDE2001: Embedded statements must be on their own line -dotnet_diagnostic.IDE2001.severity = silent - -# IDE2002: Consecutive braces must not have blank line between them -dotnet_diagnostic.IDE2002.severity = silent - -# IDE2003: Allow statement immediately after block -dotnet_diagnostic.IDE2003.severity = silent - -# IDE2004: Blank line not allowed after constructor initializer colon -dotnet_diagnostic.IDE2004.severity = silent - -# CSIsNull001 to catch uses of == null -dotnet_diagnostic.CSIsNull001.severity = warning - -# CSIsNull002 to catch uses of != null -dotnet_diagnostic.CSIsNull002.severity = warning \ No newline at end of file diff --git a/eng/CodeAnalysis.test.globalconfig b/eng/CodeAnalysis.test.globalconfig deleted file mode 100644 index 425fd9e434e..00000000000 --- a/eng/CodeAnalysis.test.globalconfig +++ /dev/null @@ -1,459 +0,0 @@ -is_global = true - -# This file takes priority over CodeAnalysis.src.globalconfig -global_level = 1 - -# CA1052: Static holder types should be Static or NotInheritable -dotnet_diagnostic.CA1052.severity = none # TODO: warning -dotnet_code_quality.CA1052.api_surface = unset - -# CA1311: Specify a culture or use an invariant version -dotnet_diagnostic.CA1311.severity = none - -# CA1416: Validate platform compatibility -dotnet_diagnostic.CA1416.severity = none # TODO: warning - -# CA1507: Use nameof to express symbol names -dotnet_diagnostic.CA1507.severity = none - -# CA1727: Use PascalCase for named placeholders -dotnet_diagnostic.CA1727.severity = suggestion - -# CA1802: Use literals where appropriate -dotnet_code_quality.CA1802.api_surface = unset - -# CA1810: Initialize reference type static fields inline -dotnet_diagnostic.CA1810.severity = none # TODO: warning - -# CA1812: Avoid uninstantiated internal classes -dotnet_diagnostic.CA1812.severity = none - -# CA1815: Override equals and operator equals on value types -dotnet_diagnostic.CA1815.severity = none - -# CA1822: Mark members as static -dotnet_diagnostic.CA1822.severity = none # TODO: warning -dotnet_code_quality.CA1822.api_surface = unset - -# CA1852: Seal internal types -dotnet_diagnostic.CA1852.severity = none - -# CA1853: Unnecessary call to 'Dictionary.ContainsKey(key)' -dotnet_diagnostic.CA1853.severity = none - -# CA1854: Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method -dotnet_diagnostic.CA1854.severity = none - -# CA2007: Consider calling ConfigureAwait on the awaited task -dotnet_diagnostic.CA2007.severity = none # TODO: warning - -# CA2014: Do not use stackalloc in loops. -dotnet_diagnostic.CA2014.severity = none # TODO: warning - -# CA2208: Instantiate argument exceptions correctly -dotnet_code_quality.CA2208.api_surface = unset - -# CA2245: Do not assign a property to itself -dotnet_diagnostic.CA2245.severity = warning - -# CA2253: Named placeholders should not be numeric values -dotnet_diagnostic.CA2253.severity = none - -# SA1000: Spacing around keywords -dotnet_diagnostic.SA1000.severity = none - -# SA1001: Commas should not be preceded by whitespace -dotnet_diagnostic.SA1001.severity = none - -# SA1014: Opening generic brackets should not be preceded by a space -dotnet_diagnostic.SA1014.severity = none - -# SA1018: Nullable type symbol should not be preceded by a space -dotnet_diagnostic.SA1018.severity = none - -# SA1020: Increment symbol should not be preceded by a space -dotnet_diagnostic.SA1020.severity = none - -# SA1026: Keyword followed by span or blank line -dotnet_diagnostic.SA1026.severity = none - -# SA1027: Tabs and spaces should be used correctly -dotnet_diagnostic.SA1027.severity = none - -# SA1028: Code should not contain trailing whitespace -dotnet_diagnostic.SA1028.severity = none - -# SA1102: Query clause should follow previous clause -dotnet_diagnostic.SA1102.severity = none - -# SA1103: Query clauses should be on separate lines or all on one line -dotnet_diagnostic.SA1103.severity = none - -# SA1113: Comma should be on the same line as previous parameter -dotnet_diagnostic.SA1113.severity = none - -# SA1115: Parameter should begin on the line after the previous parameter -dotnet_diagnostic.SA1115.severity = none - -# SA1121: Use built-in type alias -dotnet_diagnostic.SA1121.severity = none - -# SA1129: Do not use default value type constructor -dotnet_diagnostic.SA1129.severity = none - -# SA1131: Constant values should appear on the right-hand side of comparisons -dotnet_diagnostic.SA1131.severity = suggestion - -# SA1141: Use tuple syntax -dotnet_diagnostic.SA1141.severity = none - -# SA1142: Refer to tuple elements by name -dotnet_diagnostic.SA1142.severity = none - -# SA1205: Partial elements should declare an access modifier -dotnet_diagnostic.SA1205.severity = none - -# SA1206: Keyword ordering -dotnet_diagnostic.SA1206.severity = none - -# SA1212: A get accessor appears after a set accessor within a property or indexer -dotnet_diagnostic.SA1212.severity = none - -# SA1302: Interface names should begin with I -dotnet_diagnostic.SA1302.severity = none - -# SA1400: Member should declare an access modifier -dotnet_diagnostic.SA1400.severity = none - -# SA1410: Remove delegate parens when possible -dotnet_diagnostic.SA1410.severity = none - -# SA1411: Attribute constructor shouldn't use unnecessary parenthesis -dotnet_diagnostic.SA1411.severity = none - -# SA1518: Code should not contain blank lines at the end of the file -dotnet_diagnostic.SA1518.severity = none - -# IDE0001: Simplify name -dotnet_diagnostic.IDE0001.severity = silent - -# IDE0002: Simplify member access -dotnet_diagnostic.IDE0002.severity = silent - -# IDE0003: Remove this or Me qualification -dotnet_diagnostic.IDE0003.severity = silent - -# IDE0004: Remove Unnecessary Cast -dotnet_diagnostic.IDE0004.severity = silent - -# IDE0005: Using directive is unnecessary. -dotnet_diagnostic.IDE0005.severity = silent - -# IDE0008: Use explicit type -dotnet_diagnostic.IDE0008.severity = silent - -# IDE0017: Simplify object initialization -dotnet_diagnostic.IDE0017.severity = silent - -# IDE0018: Inline variable declaration -dotnet_diagnostic.IDE0018.severity = silent - -# IDE0019: Use pattern matching to avoid as followed by a null check -dotnet_diagnostic.IDE0019.severity = silent - -# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable) -dotnet_diagnostic.IDE0020.severity = silent - -# IDE0028: Simplify collection initialization -dotnet_diagnostic.IDE0028.severity = silent - -# IDE0029: Use coalesce expression -dotnet_diagnostic.IDE0029.severity = silent - -# IDE0030: Use coalesce expression -dotnet_diagnostic.IDE0030.severity = silent - -# IDE0031: Use null propagation -dotnet_diagnostic.IDE0031.severity = silent - -# IDE0033: Use explicitly provided tuple name -dotnet_diagnostic.IDE0033.severity = silent - -# IDE0034: Simplify 'default' expression -dotnet_diagnostic.IDE0034.severity = silent - -# IDE0035: Remove unreachable code -dotnet_diagnostic.IDE0035.severity = silent - -# IDE0036: Order modifiers -dotnet_diagnostic.IDE0036.severity = silent - -# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable) -dotnet_diagnostic.IDE0038.severity = silent - -# IDE0039: Use local function -dotnet_diagnostic.IDE0039.severity = silent - -# IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = silent - -# IDE0041: Use 'is null' check -dotnet_diagnostic.IDE0041.severity = silent - -# IDE0043: Invalid format string -dotnet_diagnostic.IDE0043.severity = silent - -# IDE0044: Add readonly modifier -dotnet_diagnostic.IDE0044.severity = silent - -# IDE0045: Use conditional expression for assignment -dotnet_diagnostic.IDE0045.severity = silent - -# IDE0046: Use conditional expression for return -dotnet_diagnostic.IDE0046.severity = silent - -# IDE0049: Use language keywords instead of framework type names for type references -dotnet_diagnostic.IDE0049.severity = silent - -# IDE0051: Remove unused private members -dotnet_diagnostic.IDE0051.severity = silent - -# IDE0052: Remove unread private members -dotnet_diagnostic.IDE0052.severity = silent - -# IDE0054: Use compound assignment -dotnet_diagnostic.IDE0054.severity = silent - -# IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = silent - -# IDE0056: Use index operator -dotnet_diagnostic.IDE0056.severity = silent - -# IDE0057: Use range operator -dotnet_diagnostic.IDE0057.severity = silent - -# IDE0059: Unnecessary assignment of a value -dotnet_diagnostic.IDE0059.severity = silent - -# IDE0060: Remove unused parameter -dotnet_code_quality_unused_parameters = unset - -# IDE0062: Make local function 'static' -dotnet_diagnostic.IDE0062.severity = silent - -# IDE0065: Misplaced using directive -dotnet_diagnostic.IDE0065.severity = silent - -# IDE0066: Convert switch statement to expression -dotnet_diagnostic.IDE0066.severity = silent - -# IDE0070: Use 'System.HashCode' -dotnet_diagnostic.IDE0070.severity = silent - -# IDE0071: Simplify interpolation -dotnet_diagnostic.IDE0071.severity = silent - -# IDE0073: The file header is missing or not located at the top of the file -dotnet_diagnostic.IDE0073.severity = silent - -# IDE0074: Use compound assignment -dotnet_diagnostic.IDE0074.severity = silent - -# IDE0076: Invalid global 'SuppressMessageAttribute' -dotnet_diagnostic.IDE0076.severity = silent - -# IDE0078: Use pattern matching -dotnet_diagnostic.IDE0078.severity = silent - -# IDE0079: RemoveUnnecessarySuppression -dotnet_diagnostic.IDE0079.severity = silent - -# IDE0080: Remove unnecessary suppression operator -dotnet_diagnostic.IDE0080.severity = silent - -# IDE0081: RemoveUnnecessaryByVal -dotnet_diagnostic.IDE0081.severity = silent - -# IDE0082: 'typeof' can be converted to 'nameof' -dotnet_diagnostic.IDE0082.severity = silent - -# IDE0084: Use pattern matching (IsNot operator) -dotnet_diagnostic.IDE0084.severity = silent - -# IDE0090: Simplify new expression -dotnet_diagnostic.IDE0090.severity = warning - -# IDE0100: Remove redundant equality -dotnet_diagnostic.IDE0100.severity = silent - -# IDE0110: Remove unnecessary discard -dotnet_diagnostic.IDE0110.severity = silent - -# IDE0120: Simplify LINQ expression -dotnet_diagnostic.IDE0120.severity = silent - -# IDE0140: Simplify object creation -dotnet_diagnostic.IDE0140.severity = silent - -# IDE0170: Simplify property pattern -dotnet_diagnostic.IDE0170.severity = silent - -# IDE0180: Use tuple swap -dotnet_diagnostic.IDE0180.severity = silent - -# IDE0200: Remove unnecessary lambda expression -dotnet_diagnostic.IDE0200.severity = silent - -# IDE0230: Use UTF8 string literal -dotnet_diagnostic.IDE0230.severity = silent - -# IDE1005: Delegate invocation can be simplified. -dotnet_diagnostic.IDE1005.severity = silent - -# xUnit1000: Test classes must be public -dotnet_diagnostic.xUnit1000.severity = warning - -# xUnit1001: Fact methods cannot have parameters -dotnet_diagnostic.xUnit1001.severity = warning - -# xUnit1002: Test methods cannot have multiple Fact or Theory attributes -dotnet_diagnostic.xUnit1002.severity = warning - -# xUnit1003: Theory methods must have test data -dotnet_diagnostic.xUnit1003.severity = warning - -# xUnit1004: Test methods should not be skipped -dotnet_diagnostic.xUnit1004.severity = silent # TODO: warning - -# xUnit1005: Fact methods should not have test data -dotnet_diagnostic.xUnit1005.severity = warning - -# xUnit1006: Theory methods should have parameters -dotnet_diagnostic.xUnit1006.severity = warning - -# xUnit1007: ClassData must point at a valid class -dotnet_diagnostic.xUnit1007.severity = warning - -# xUnit1008: Test data attribute should only be used on a Theory -dotnet_diagnostic.xUnit1008.severity = warning - -# xUnit1009: InlineData must match the number of method parameters -dotnet_diagnostic.xUnit1009.severity = warning - -# xUnit1010: The value is not convertible to the method parameter type -dotnet_diagnostic.xUnit1010.severity = warning - -# xUnit1011: There is no matching method parameter -dotnet_diagnostic.xUnit1011.severity = warning - -# xUnit1012: Null should not be used for value type parameters -dotnet_diagnostic.xUnit1012.severity = warning - -# xUnit1013: Public methods should be marked as test -dotnet_diagnostic.xUnit1013.severity = warning - -# xUnit1014: MemberData should use nameof operator for member name -dotnet_diagnostic.xUnit1014.severity = warning - -# xUnit1015: MemberData must reference an existing member -dotnet_diagnostic.xUnit1015.severity = warning - -# xUnit1016: MemberData must reference a public member -dotnet_diagnostic.xUnit1016.severity = warning - -# xUnit1017: MemberData must reference a static member -dotnet_diagnostic.xUnit1017.severity = warning - -# xUnit1018: MemberData must reference a valid member kind -dotnet_diagnostic.xUnit1018.severity = warning - -# xUnit1019: MemberData must reference a member providing a valid data type -dotnet_diagnostic.xUnit1019.severity = warning - -# xUnit1020: MemberData must reference a property with a getter -dotnet_diagnostic.xUnit1020.severity = warning - -# xUnit1021: MemberData should not have parameters if the referenced member is not a method -dotnet_diagnostic.xUnit1021.severity = warning - -# xUnit1022: Theory methods cannot have a parameter array -dotnet_diagnostic.xUnit1022.severity = warning - -# xUnit1023: Theory methods cannot have default parameter values -dotnet_diagnostic.xUnit1023.severity = warning - -# xUnit1024: Test methods cannot have overloads -dotnet_diagnostic.xUnit1024.severity = warning - -# xUnit1025: InlineData should be unique within the Theory it belongs to -dotnet_diagnostic.xUnit1025.severity = warning - -# xUnit1026: Theory methods should use all of their parameters -dotnet_diagnostic.xUnit1026.severity = warning - -# xUnit2000: Constants and literals should be the expected argument -dotnet_diagnostic.xUnit2000.severity = warning - -# xUnit2001: Do not use invalid equality check -dotnet_diagnostic.xUnit2001.severity = warning - -# xUnit2002: Do not use null check on value type -dotnet_diagnostic.xUnit2002.severity = warning - -# xUnit2003: Do not use equality check to test for null value -dotnet_diagnostic.xUnit2003.severity = warning - -# xUnit2004: Do not use equality check to test for boolean conditions -dotnet_diagnostic.xUnit2004.severity = warning - -# xUnit2005: Do not use identity check on value type -dotnet_diagnostic.xUnit2005.severity = warning - -# xUnit2006: Do not use invalid string equality check -dotnet_diagnostic.xUnit2006.severity = warning - -# xUnit2007: Do not use typeof expression to check the type -dotnet_diagnostic.xUnit2007.severity = warning - -# xUnit2008: Do not use boolean check to match on regular expressions -dotnet_diagnostic.xUnit2008.severity = warning - -# xUnit2009: Do not use boolean check to check for substrings -dotnet_diagnostic.xUnit2009.severity = warning - -# xUnit2010: Do not use boolean check to check for string equality -dotnet_diagnostic.xUnit2010.severity = warning - -# xUnit2011: Do not use empty collection check -dotnet_diagnostic.xUnit2011.severity = warning - -# xUnit2012: Do not use Enumerable.Any() to check if a value exists in a collection -dotnet_diagnostic.xUnit2012.severity = warning - -# xUnit2013: Do not use equality check to check for collection size. -dotnet_diagnostic.xUnit2013.severity = none - -# xUnit2014: Do not use throws check to check for asynchronously thrown exception -dotnet_diagnostic.xUnit2014.severity = none - -# xUnit2015: Do not use typeof expression to check the exception type -dotnet_diagnostic.xUnit2015.severity = warning - -# xUnit2016: Keep precision in the allowed range when asserting equality of doubles or decimals -dotnet_diagnostic.xUnit2016.severity = warning - -# xUnit2017: Do not use Contains() to check if a value exists in a collection -dotnet_diagnostic.xUnit2017.severity = none - -# xUnit2018: Do not compare an object's exact type to an abstract class or interface -dotnet_diagnostic.xUnit2018.severity = warning - -# xUnit2019: Do not use obsolete throws check to check for asynchronously thrown exception -dotnet_diagnostic.xUnit2019.severity = warning - -# xUnit3000: Test case classes must derive directly or indirectly from Xunit.LongLivedMarshalByRefObject -dotnet_diagnostic.xUnit3000.severity = warning - -# xUnit3001: Classes that implement Xunit.Abstractions.IXunitSerializable must have a public parameterless constructor -dotnet_diagnostic.xUnit3001.severity = warning diff --git a/eng/CodeStyle.targets b/eng/CodeStyle.targets index 68eb218b4a2..eb5bb76aee8 100644 --- a/eng/CodeStyle.targets +++ b/eng/CodeStyle.targets @@ -2,28 +2,22 @@ - - - - - - - - - + - + + - + + diff --git a/eng/stylecop.json b/eng/stylecop.json deleted file mode 100644 index 97cdca8c5f6..00000000000 --- a/eng/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "copyrightText": "Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.\nSee the LICENSE file in the project root for more information.", - "xmlHeader": false - } - } -} diff --git a/src/Common/tests/TestUtilities/CommonTestHelper.cs b/src/Common/tests/TestUtilities/CommonTestHelper.cs index 1225f3c538d..6a2a9d43c8f 100644 --- a/src/Common/tests/TestUtilities/CommonTestHelper.cs +++ b/src/Common/tests/TestUtilities/CommonTestHelper.cs @@ -78,7 +78,7 @@ public static TheoryData GetPointTheoryData(TestIncludeType includeType) TheoryData data = new(); if (!includeType.HasFlag(TestIncludeType.NoPositives)) { - data.Add(default(Point)); + data.Add(default); data.Add(new Point(10)); data.Add(new Point(1, 2)); } @@ -99,7 +99,7 @@ public static TheoryData GetSizeTheoryData(TestIncludeType includeType) TheoryData data = new(); if (!includeType.HasFlag(TestIncludeType.NoPositives)) { - data.Add(default(Size)); + data.Add(default); data.Add(new Size(new Point(1, 1))); data.Add(new Size(1, 2)); } diff --git a/src/Common/tests/TestUtilities/DebuggerAttributes.cs b/src/Common/tests/TestUtilities/DebuggerAttributes.cs index 72a1025ebf8..b72afd3a0ac 100644 --- a/src/Common/tests/TestUtilities/DebuggerAttributes.cs +++ b/src/Common/tests/TestUtilities/DebuggerAttributes.cs @@ -175,7 +175,7 @@ private static string GetDebuggerMemberString(object member, bool noQuotes) { null => "null", byte or sbyte or short or ushort or int or uint or long or ulong or float or double => member.ToString(), - string _ when noQuotes => member.ToString(), + string when noQuotes => member.ToString(), string => $"\"{member}\"", _ => $"{{{member}}}" }; diff --git a/src/Common/tests/TestUtilities/NativeAssert.cs b/src/Common/tests/TestUtilities/NativeAssert.cs new file mode 100644 index 00000000000..cd5051a03d1 --- /dev/null +++ b/src/Common/tests/TestUtilities/NativeAssert.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System; + +public static unsafe class NativeAssert +{ + public static void Null(void* pointer) => Assert.True(pointer is null); + + public static void NotNull(void* pointer) => Assert.True(pointer is not null); +} diff --git a/src/Common/tests/TestUtilities/ReflectionHelper.cs b/src/Common/tests/TestUtilities/ReflectionHelper.cs index de8f532596b..817eebc8b76 100644 --- a/src/Common/tests/TestUtilities/ReflectionHelper.cs +++ b/src/Common/tests/TestUtilities/ReflectionHelper.cs @@ -9,7 +9,7 @@ public static class ReflectionHelper { public static IEnumerable GetPublicNotAbstractClasses() { - var types = typeof(T).Assembly.GetTypes().Where(type => IsPublicNonAbstract(type)); + var types = typeof(T).Assembly.GetTypes().Where(IsPublicNonAbstract); foreach (var type in types) { if (type.GetConstructor( diff --git a/src/Common/tests/TestUtilities/TestAccessors.cs b/src/Common/tests/TestUtilities/TestAccessors.cs index ede707256c4..71bb3a8df87 100644 --- a/src/Common/tests/TestUtilities/TestAccessors.cs +++ b/src/Common/tests/TestUtilities/TestAccessors.cs @@ -33,14 +33,14 @@ public static partial class TestAccessors /// T.NegativeInfinity, T.Epsilon, T.Epsilon * T.NegativeOne -, ]; } diff --git a/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/TimeTests.vb b/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/TimeTests.vb index 3efaf462aaf..fcffdd0d7ff 100644 --- a/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/TimeTests.vb +++ b/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/TimeTests.vb @@ -9,7 +9,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests Public Class TimeTests Friend Const PrecisionTickLimit As Integer = 1_000_000 - Private Function TimesEqual( + Private Shared Function TimesEqual( vbTime As Date, systemTime As Date, acceptableDifferenceInTicks As Long) As Boolean diff --git a/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/TestUtilities/VbFileCleanupTestBase.vb b/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/TestUtilities/VbFileCleanupTestBase.vb index e75437ee559..76ffb5b0428 100644 --- a/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/TestUtilities/VbFileCleanupTestBase.vb +++ b/src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/TestUtilities/VbFileCleanupTestBase.vb @@ -68,7 +68,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests ''' The full path and file name of the created file. ''' If size = -1 no file is create but the full path is returned. ''' - Friend Function CreateTempFile(sourceDirectoryName As String, Optional filename As String = "Testing.Txt", Optional size As Integer = -1) As String + Friend Shared Function CreateTempFile(sourceDirectoryName As String, Optional filename As String = "Testing.Txt", Optional size As Integer = -1) As String Dim filenameWithPath As String = Path.Combine(sourceDirectoryName, filename) If size >= 0 Then @@ -109,7 +109,7 @@ Namespace Microsoft.VisualBasic.Forms.Tests GC.SuppressFinalize(Me) End Sub - Friend Function GetUniqueFileNameWithPath(testDirectory As String) As String + Friend Shared Function GetUniqueFileNameWithPath(testDirectory As String) As String Return Path.Combine(testDirectory, GetUniqueFileName()) End Function diff --git a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/AudioTests.cs b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/AudioTests.cs index be024769258..3317b3eeb19 100644 --- a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/AudioTests.cs +++ b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/AudioTests.cs @@ -74,7 +74,7 @@ public void PlaySystemSound_Throws() public void Stop() { Audio audio = new(); - Action testCode = () => audio.Stop(); + Action testCode = audio.Stop; testCode.Should().NotThrow(); } } diff --git a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/ComputerInfoTests.cs b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/ComputerInfoTests.cs index 3cceecaa9de..5796f292042 100644 --- a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/ComputerInfoTests.cs +++ b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Devices/ComputerInfoTests.cs @@ -13,7 +13,7 @@ public void Properties() { ComputerInfo info = new(); CultureInfo.InstalledUICulture.Should().Be(info.InstalledUICulture); - Environment.OSVersion.Platform.ToString().Should().Be( info.OSPlatform); + Environment.OSVersion.Platform.ToString().Should().Be(info.OSPlatform); Environment.OSVersion.Version.ToString().Should().Be(info.OSVersion); } diff --git a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Logging/FileLogTraceListenerTests.cs b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Logging/FileLogTraceListenerTests.cs index 861eaf7376e..b65b20a7a94 100644 --- a/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Logging/FileLogTraceListenerTests.cs +++ b/src/Microsoft.VisualBasic/tests/UnitTests/Microsoft/VisualBasic/Logging/FileLogTraceListenerTests.cs @@ -40,7 +40,7 @@ public void Write(bool includeHostName) listener.WriteLine("WriteLine"); listener.TraceOutputOptions = TraceOptions.LogicalOperationStack | TraceOptions.DateTime | TraceOptions.Timestamp | TraceOptions.ProcessId | TraceOptions.ThreadId; listener.TraceEvent(eventCache: cache, source: "Source", eventType: TraceEventType.Warning, id: 3, message: "TraceEvent"); - listener.AutoFlush=true; + listener.AutoFlush = true; listener.TraceData(eventCache: cache, source: "Source", eventType: TraceEventType.Error, id: 4, data: "TraceData"); listener.Flush(); listener.Close(); diff --git a/src/System.Drawing.Common/tests/Helpers.cs b/src/System.Drawing.Common/tests/Helpers.cs index 89bcdddbae5..42f8df23827 100644 --- a/src/System.Drawing.Common/tests/Helpers.cs +++ b/src/System.Drawing.Common/tests/Helpers.cs @@ -10,7 +10,7 @@ namespace System.Drawing; -public unsafe static class Helpers +public static unsafe class Helpers { // This MUST come before s_anyInstalledPrinters. Caching for performance in tests. public static PrinterSettings.StringCollection InstalledPrinters { get; } = PrinterSettings.InstalledPrinters; diff --git a/src/System.Drawing.Common/tests/System/Drawing/BitmapTests.cs b/src/System.Drawing.Common/tests/System/Drawing/BitmapTests.cs index 0c301c77977..98299e45734 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/BitmapTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/BitmapTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // (C) 2004 Ximian, Inc. http://www.ximian.com // Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com) // @@ -481,7 +481,7 @@ public void Clone_Disposed_ThrowsArgumentException() Bitmap bitmap = new(1, 1); bitmap.Dispose(); - AssertExtensions.Throws(null, () => bitmap.Clone()); + AssertExtensions.Throws(null, bitmap.Clone); AssertExtensions.Throws(null, () => bitmap.Clone(new Rectangle(0, 0, 1, 1), PixelFormat.Format32bppArgb)); AssertExtensions.Throws(null, () => bitmap.Clone(new RectangleF(0, 0, 1, 1), PixelFormat.Format32bppArgb)); } @@ -882,7 +882,7 @@ public void MakeTransparent_Disposed_ThrowsArgumentException() Bitmap bitmap = new(1, 1); bitmap.Dispose(); - AssertExtensions.Throws(null, () => bitmap.MakeTransparent()); + AssertExtensions.Throws(null, bitmap.MakeTransparent); AssertExtensions.Throws(null, () => bitmap.MakeTransparent(Color.Red)); } @@ -890,7 +890,7 @@ public void MakeTransparent_Disposed_ThrowsArgumentException() public void MakeTransparent_GrayscalePixelFormat_ThrowsArgumentException() { using Bitmap bitmap = new(1, 1, PixelFormat.Format16bppGrayScale); - AssertExtensions.Throws(null, () => bitmap.MakeTransparent()); + AssertExtensions.Throws(null, bitmap.MakeTransparent); try { @@ -1010,7 +1010,7 @@ public void SetResolution_Disposed_ThrowsArgumentException() public static IEnumerable LockBits_TestData() { - Bitmap bitmap() => new(2, 2, PixelFormat.Format32bppArgb); + static Bitmap bitmap() => new(2, 2, PixelFormat.Format32bppArgb); yield return new object[] { bitmap(), new Rectangle(0, 0, 2, 2), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb, 8, 1 }; yield return new object[] { bitmap(), new Rectangle(0, 0, 2, 2), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb, 8, 3 }; yield return new object[] { bitmap(), new Rectangle(0, 0, 2, 2), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb, 8, 2 }; @@ -1712,7 +1712,7 @@ public override long Position } public override void Flush() => _stream.Flush(); - public override int Read(byte[] buffer, int offset, int count) => _canRead ? _stream.Read(buffer, offset, count) : throw new NotSupportedException(); + public override int Read(byte[] buffer, int offset, int count) => _canRead ? _stream.Read(buffer, offset, count) : throw new NotSupportedException(); public override long Seek(long offset, SeekOrigin origin) => _stream.Seek(offset, origin); public override void SetLength(long value) => _stream.SetLength(value); public override void Write(byte[] buffer, int offset, int count) => _stream.Write(buffer, offset, count); diff --git a/src/System.Drawing.Common/tests/System/Drawing/BufferedGraphicsContextTests.cs b/src/System.Drawing.Common/tests/System/Drawing/BufferedGraphicsContextTests.cs index 86d0641416a..b39eb7451ef 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/BufferedGraphicsContextTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/BufferedGraphicsContextTests.cs @@ -230,7 +230,7 @@ public void Dispose_BusyAndValidated_ThrowsInvalidOperationException() using Graphics graphics = Graphics.FromImage(image); using (context.Allocate(graphics, Rectangle.Empty)) { - Assert.Throws(() => context.Dispose()); + Assert.Throws(context.Dispose); } } @@ -243,7 +243,7 @@ public void Dispose_BusyAndInvalidated_ThrowsInvalidOperationException() using (context.Allocate(graphics, Rectangle.Empty)) { context.Invalidate(); - Assert.Throws(() => context.Dispose()); + Assert.Throws(context.Dispose); } } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/CharacterRangeTests.cs b/src/System.Drawing.Common/tests/System/Drawing/CharacterRangeTests.cs index 8e746fcb595..3faf4546826 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/CharacterRangeTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/CharacterRangeTests.cs @@ -8,7 +8,7 @@ public class CharacterRangeTests [Fact] public void Ctor_Default() { - CharacterRange range = new(); + CharacterRange range = default; Assert.Equal(0, range.First); Assert.Equal(0, range.Length); } diff --git a/src/System.Drawing.Common/tests/System/Drawing/ColorTranslatorTests.cs b/src/System.Drawing.Common/tests/System/Drawing/ColorTranslatorTests.cs index 780a492f562..566203bc2f2 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/ColorTranslatorTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/ColorTranslatorTests.cs @@ -43,7 +43,7 @@ public class ColorTranslatorTests public static IEnumerable ToWin32Color_TestData() { - yield return new object[] { new Color(), 0 }; + yield return new object[] { default(Color), 0 }; yield return new object[] { Color.Red, 255 }; yield return new object[] { Color.White, 16777215 }; yield return new object[] { Color.FromArgb(1, 2, 3), 197121 }; @@ -83,7 +83,7 @@ public void FromOle_Color_ReturnsExpected(int oleColor, Color color) public static IEnumerable ToOle_TestData() { - yield return new object[] { new Color(), 0 }; + yield return new object[] { default(Color), 0 }; yield return new object[] { Color.Red, 255 }; yield return new object[] { Color.White, 16777215 }; yield return new object[] { Color.FromArgb(1, 2, 3), 197121 }; diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/CustomLineCapTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/CustomLineCapTests.cs index 7bfa49881fb..33f27496389 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/CustomLineCapTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/CustomLineCapTests.cs @@ -214,7 +214,7 @@ public void Disposed_MembersThrow() AssertExtensions.Throws(null, () => customLineCap.BaseCap); AssertExtensions.Throws(null, () => customLineCap.BaseInset); AssertExtensions.Throws(null, () => customLineCap.WidthScale); - AssertExtensions.Throws(null, () => customLineCap.Clone()); + AssertExtensions.Throws(null, customLineCap.Clone); AssertExtensions.Throws(null, () => customLineCap.SetStrokeCaps(LineCap.Flat, LineCap.Flat)); AssertExtensions.Throws(null, () => customLineCap.GetStrokeCaps(out LineCap startCap, out LineCap endCap)); } diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathIteratorTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathIteratorTests.cs index a803f19c4c6..184f5be59db 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathIteratorTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathIteratorTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -229,8 +229,8 @@ public void Enumerate_ZeroPoints_ReturnsExpected() using GraphicsPath gp = new(); using GraphicsPathIterator gpi = new(gp); Assert.Equal(0, gpi.Enumerate(ref points, ref types)); - Assert.Equal(0, points.Length); - Assert.Equal(0, types.Length); + Assert.Empty(points); + Assert.Empty(types); } [Fact] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathTests.cs index 884eee2bc21..d9be64fb63e 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/GraphicsPathTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -136,8 +136,8 @@ public void GraphicsPath_InvalidFillMode_ThrowsInvalidEnumArgumentException(Fill public void PathData_ReturnsExpected() { using GraphicsPath gp = new(); - Assert.Equal(0, gp.PathData.Points.Length); - Assert.Equal(0, gp.PathData.Types.Length); + Assert.Empty(gp.PathData.Points); + Assert.Empty(gp.PathData.Types); } [Fact] @@ -746,10 +746,10 @@ public void AddRectangle_ZeroWidthHeight_Success(int width, int height) using GraphicsPath gpi = new(); using GraphicsPath gpf = new(); gpi.AddRectangle(new Rectangle(1, 2, width, height)); - Assert.Equal(0, gpi.PathData.Points.Length); + Assert.Empty(gpi.PathData.Points); gpf.AddRectangle(new RectangleF(1f, 2f, width, height)); - Assert.Equal(0, gpf.PathData.Points.Length); + Assert.Empty(gpf.PathData.Points); } [Fact] @@ -1278,14 +1278,14 @@ public void Flatten_Rectangle_Success() public void Warp_DestinationPointsNull_ThrowsArgumentNullException() { using GraphicsPath gp = new(); - AssertExtensions.Throws("destPoints", () => gp.Warp(null, new RectangleF())); + AssertExtensions.Throws("destPoints", () => gp.Warp(null, default)); } [Fact] public void Warp_DestinationPointsZero_ThrowsArgumentException() { using GraphicsPath gp = new(); - AssertExtensions.Throws(null, () => new GraphicsPath().Warp([], new RectangleF())); + AssertExtensions.Throws(null, () => new GraphicsPath().Warp([], default)); } [Fact] @@ -1313,7 +1313,7 @@ public void Warp_RectangleEmpty_Success() { using GraphicsPath gp = new(); gp.AddPolygon([new(5, 5), new(15, 5), new(10, 15)]); - gp.Warp([new(0, 0)], new Rectangle(), null); + gp.Warp([new(0, 0)], default(Rectangle), null); AssertWrapNaN(gp); } @@ -1738,8 +1738,8 @@ public void IsOutlineVisible_PenNull_ThrowsArgumentNullException() using GraphicsPath gp = new(); AssertExtensions.Throws("pen", () => gp.IsOutlineVisible(1, 1, null)); AssertExtensions.Throws("pen", () => gp.IsOutlineVisible(1.0f, 1.0f, null)); - AssertExtensions.Throws("pen", () => gp.IsOutlineVisible(new Point(), null)); - AssertExtensions.Throws("pen", () => gp.IsOutlineVisible(new PointF(), null)); + AssertExtensions.Throws("pen", () => gp.IsOutlineVisible(default, null)); + AssertExtensions.Throws("pen", () => gp.IsOutlineVisible(default(PointF), null)); } [Fact] @@ -1848,8 +1848,8 @@ public static IEnumerable Reverse_TestData() { new Point[] { - new(1,2), new(3,4), new(5,6), new(7,8), - new(9,10), new(11,12), new(13,14) + new(1, 2), new(3, 4), new(5, 6), new(7, 8), + new(9, 10), new(11, 12), new(13, 14) } }; } @@ -1979,21 +1979,21 @@ public void Reverse_String_Success() gp.AddString("Mono::", FontFamily.GenericMonospace, 0, 10, new Point(10, 10), StringFormat.GenericDefault); byte[] expectedTypes = [ - 0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,129, - 0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,161, - 0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,129, - 0,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,161, - 0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,131,0,3, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,163,0,3,3,3, - 3,3,3,3,3,3,3,3,3,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,3, - 3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3, - 3,3,3,3,3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3, - 3,3,3,3,3,3,3,3,3,3,3,161,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3, - 3,3,3,3,3,3,3,3,3,131,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, - 3,3,3,3,3,3,3,163,0,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3, - 3,3,3,3,3,3,3,3,3,3,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1, - 1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3, - 1,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,129 + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 129, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 161, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 129, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 161, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 131, 0, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 163, 0, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 161, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 131, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 163, 0, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, + 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 129 ]; AssertReverse(gp, gp.PathPoints, expectedTypes); @@ -2061,8 +2061,8 @@ public void Ctor_PointsTypes_Success() private void AssertEmptyGraphicsPath(GraphicsPath gp) { - Assert.Equal(0, gp.PathData.Points.Length); - Assert.Equal(0, gp.PathData.Types.Length); + Assert.Empty(gp.PathData.Points); + Assert.Empty(gp.PathData.Types); Assert.Equal(0, gp.PointCount); } @@ -2114,7 +2114,7 @@ private void AssertBezier(GraphicsPath path) path.PathPoints.Should().HaveCount(4); path.PathTypes.Should().HaveCount(4); path.PathData.Points.Should().HaveCount(4); - path.GetBounds().Should().BeApproximately(new (1f, 1f, 3f, 3f), Delta); + path.GetBounds().Should().BeApproximately(new(1f, 1f, 3f, 3f), Delta); path.PathPoints.Should().BeApproximatelyEquivalentTo(expectedPoints, Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 3, 3, 3 }); } @@ -2130,7 +2130,7 @@ private void AssertCurve(GraphicsPath path) path.PathPoints.Should().HaveCount(4); path.PathTypes.Should().HaveCount(4); path.PathData.Points.Should().HaveCount(4); - path.GetBounds().Should().BeApproximately(new (1f, 1f, 1f, 1f), Delta); + path.GetBounds().Should().BeApproximately(new(1f, 1f, 1f, 1f), Delta); path.PathPoints.Should().BeApproximatelyEquivalentTo(expectedPoints, Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 3, 3, 3 }); } @@ -2140,7 +2140,7 @@ private void AssertClosedCurve(GraphicsPath path) path.PathPoints.Should().HaveCount(10); path.PathTypes.Should().HaveCount(10); path.PathData.Points.Should().HaveCount(10); - path.GetBounds().Should().BeApproximately(new (0.8333333f, 0.8333333f, 2.33333278f, 2.33333278f), Delta); + path.GetBounds().Should().BeApproximately(new(0.8333333f, 0.8333333f, 2.33333278f, 2.33333278f), Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 3, 3, 3, 3, 3, 3, 3, 3, 131 }); } @@ -2156,7 +2156,7 @@ private void AssertRectangle(GraphicsPath path) path.PathPoints.Should().HaveCount(4); path.PathTypes.Should().HaveCount(4); path.PathData.Points.Should().HaveCount(4); - path.GetBounds().Should().BeApproximately(new (1f, 1f, 2f, 2f), Delta); + path.GetBounds().Should().BeApproximately(new(1f, 1f, 2f, 2f), Delta); path.PathPoints.Should().BeApproximatelyEquivalentTo(expectedPoints, Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 1, 1, 129 }); } @@ -2166,7 +2166,7 @@ private void AssertEllipse(GraphicsPath path) path.PathPoints.Should().HaveCount(13); path.PathTypes.Should().HaveCount(13); path.PathData.Points.Should().HaveCount(13); - path.GetBounds().Should().BeApproximately(new (1f, 1f, 2f, 2f), Delta); + path.GetBounds().Should().BeApproximately(new(1f, 1f, 2f, 2f), Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 131 }); } @@ -2182,7 +2182,7 @@ private void AssertPie(GraphicsPath path) path.PathPoints.Should().HaveCount(5); path.PathTypes.Should().HaveCount(5); path.PathData.Points.Should().HaveCount(5); - path.GetBounds().Should().BeApproximately(new (2f, 2f, 0.9999058f, 0.0274119377f), Delta); + path.GetBounds().Should().BeApproximately(new(2f, 2f, 0.9999058f, 0.0274119377f), Delta); path.PathPoints.Should().BeApproximatelyEquivalentTo(expectedPoints, Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 1, 3, 3, 131 }); } @@ -2199,7 +2199,7 @@ private void AssertPolygon(GraphicsPath path) path.PathPoints.Should().HaveCount(3); path.PathTypes.Should().HaveCount(3); path.PathData.Points.Should().HaveCount(3); - path.GetBounds().Should().BeApproximately(new (1f, 1f, 2f, 2f), Delta); + path.GetBounds().Should().BeApproximately(new(1f, 1f, 2f, 2f), Delta); path.PathPoints.Should().BeApproximatelyEquivalentTo(expectedPoints, Delta); path.PathTypes.Should().BeEquivalentTo(new byte[] { 0, 1, 129 }); } diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/HatchBrushTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/HatchBrushTests.cs index 9d93bcdac00..405561edf5a 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/HatchBrushTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/HatchBrushTests.cs @@ -7,7 +7,7 @@ public class HatchBrushTests { public static IEnumerable Ctor_HatchStyle_ForeColor_TestData() { - yield return new object[] { HatchStyle.Horizontal, new Color() }; + yield return new object[] { HatchStyle.Horizontal, default(Color) }; yield return new object[] { HatchStyle.SolidDiamond, Color.PapayaWhip }; } @@ -26,7 +26,7 @@ public void Ctor_HatchStyle_ForeColor(HatchStyle hatchStyle, Color foreColor) public static IEnumerable Ctor_HatchStyle_ForeColor_BackColor_TestData() { - yield return new object[] { HatchStyle.Horizontal, new Color(), new Color() }; + yield return new object[] { HatchStyle.Horizontal, default(Color), default(Color) }; yield return new object[] { HatchStyle.SolidDiamond, Color.PapayaWhip, Color.Plum }; } @@ -45,7 +45,7 @@ public void Ctor_HatchStyle_ForeColor_BackColor(HatchStyle hatchStyle, Color for } [Theory] - [InlineData(HatchStyle.Horizontal -1 )] + [InlineData(HatchStyle.Horizontal - 1)] [InlineData(HatchStyle.SolidDiamond + 1)] public void Ctor_InvalidHatchStyle_ThrowsArgumentException(HatchStyle hatchStyle) { @@ -82,7 +82,7 @@ public void Clone_Disposed_ThrowsArgumentException() HatchBrush brush = new(HatchStyle.DarkHorizontal, Color.PeachPuff, Color.Purple); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.Clone()); + AssertExtensions.Throws(null, brush.Clone); } [Fact] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/LinearGradientBrushTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/LinearGradientBrushTests.cs index 00261dadf98..b7c3a66d220 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/LinearGradientBrushTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/LinearGradientBrushTests.cs @@ -23,7 +23,7 @@ public void Ctor_PointF_PointF_Color_Color(Point point1, Point point2, Color col { using LinearGradientBrush brush = new((PointF)point1, point2, color1, color2); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -50,7 +50,7 @@ public void Ctor_Point_Point_Color_Color(Point point1, Point point2, Color color { using LinearGradientBrush brush = new(point1, point2, color1, color2); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -84,7 +84,7 @@ public void Ctor_Rectangle_Color_Color_LinearGradientMode(Rectangle rectangle, C { using LinearGradientBrush brush = new(rectangle, color1, color2, linearGradientMode); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -101,7 +101,7 @@ public void Ctor_RectangleF_Color_Color_LinearGradientMode(Rectangle rectangle, { using LinearGradientBrush brush = new((RectangleF)rectangle, color1, color2, linearGradientMode); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -127,7 +127,7 @@ public void Ctor_Rectangle_Color_Color_Angle(Rectangle rectangle, Color color1, { using LinearGradientBrush brush = new(rectangle, color1, color2, angle); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -144,7 +144,7 @@ public void Ctor_RectangleF_Color_Color_Angle(Rectangle rectangle, Color color1, { using LinearGradientBrush brush = new((RectangleF)rectangle, color1, color2, angle); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -170,7 +170,7 @@ public void Ctor_Rectangle_Color_Color_Angle_IsAngleScalable(Rectangle rectangle { using LinearGradientBrush brush = new(rectangle, color1, color2, angle, isAngleScalable); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -187,7 +187,7 @@ public void Ctor_RectangleF_Color_Color_Angle_IsAngleScalable(Rectangle rectangl { using LinearGradientBrush brush = new((RectangleF)rectangle, color1, color2, angle, isAngleScalable); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.False(brush.GammaCorrection); _ = brush.InterpolationColors; @@ -249,7 +249,7 @@ public void Clone_Disposed_ThrowsArgumentException() LinearGradientBrush brush = new(new Rectangle(1, 2, 3, 4), Color.Plum, Color.Red, 45, true); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.Clone()); + AssertExtensions.Throws(null, brush.Clone); } [Fact] @@ -649,7 +649,7 @@ public void ResetTransform_Disposed_ThrowsArgumentException() LinearGradientBrush brush = new(new Rectangle(1, 2, 3, 4), Color.Plum, Color.Red, 45, true); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.ResetTransform()); + AssertExtensions.Throws(null, brush.ResetTransform); } [Fact] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/MatrixTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/MatrixTests.cs index 2ae28afcc9e..434941ff91e 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/MatrixTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/MatrixTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -127,8 +127,8 @@ public void Ctor_RectangleF_Points(Rectangle rect, Point[] plgpnts, float[] expe [Fact] public void Ctor_NullPoints_ThrowsArgumentNullException() { - AssertExtensions.Throws("plgpts", () => new Matrix(new RectangleF(), null)); - AssertExtensions.Throws("plgpts", () => new Matrix(new Rectangle(), null)); + AssertExtensions.Throws("plgpts", () => new Matrix(default(RectangleF), null)); + AssertExtensions.Throws("plgpts", () => new Matrix(default, null)); } [Theory] @@ -137,8 +137,8 @@ public void Ctor_NullPoints_ThrowsArgumentNullException() [InlineData(4)] public void Ctor_PointsLengthNotThree_ThrowsArgumentNullException(int length) { - AssertExtensions.Throws(null, () => new Matrix(new RectangleF(), new PointF[length])); - AssertExtensions.Throws(null, () => new Matrix(new Rectangle(), new Point[length])); + AssertExtensions.Throws(null, () => new Matrix(default, new PointF[length])); + AssertExtensions.Throws(null, () => new Matrix(default, new Point[length])); } [Fact] @@ -258,12 +258,12 @@ public void Invert_FloatBounds_ThrowsArgumentException(float f) using Matrix matrix4 = new(1, 2, 3, f, 5, 6); using Matrix matrix5 = new(1, 2, 3, 4, f, 6); using Matrix matrix6 = new(1, 2, 3, 4, 5, f); - AssertExtensions.Throws(null, () => matrix1.Invert()); - AssertExtensions.Throws(null, () => matrix2.Invert()); - AssertExtensions.Throws(null, () => matrix3.Invert()); - AssertExtensions.Throws(null, () => matrix4.Invert()); - AssertExtensions.Throws(null, () => matrix5.Invert()); - AssertExtensions.Throws(null, () => matrix6.Invert()); + AssertExtensions.Throws(null, matrix1.Invert); + AssertExtensions.Throws(null, matrix2.Invert); + AssertExtensions.Throws(null, matrix3.Invert); + AssertExtensions.Throws(null, matrix4.Invert); + AssertExtensions.Throws(null, matrix5.Invert); + AssertExtensions.Throws(null, matrix6.Invert); } [Fact] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/PathGradientBrushTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/PathGradientBrushTests.cs index 75d99540ab1..1ba88167d51 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/PathGradientBrushTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Drawing2D/PathGradientBrushTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -131,7 +131,7 @@ public void Clone_Disposed_ThrowsArgumentException() PathGradientBrush brush = new(_defaultFloatPoints); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.Clone()); + AssertExtensions.Throws(null, brush.Clone); } [Fact] @@ -265,7 +265,7 @@ public void Blend_ReturnsExpected(float[] factors, float[] positions) else { Assert.Equal(factors, brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); } } @@ -274,13 +274,13 @@ public void Blend_CannotChange() { using PathGradientBrush brush = new(_defaultFloatPoints, WrapMode.TileFlipXY); brush.Blend.Factors = []; - Assert.Equal(1, brush.Blend.Factors.Length); + Assert.Single(brush.Blend.Factors); brush.Blend.Factors = new float[2]; - Assert.Equal(1, brush.Blend.Factors.Length); + Assert.Single(brush.Blend.Factors); brush.Blend.Positions = []; - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); brush.Blend.Positions = new float[2]; - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); } [Fact] @@ -312,7 +312,7 @@ public void Blend_InvalidFactorPositions_ThrowsArgumentException(Blend blend) [Fact] public void Blend_InvalidFactorPositionsLengthMismatch_ThrowsArgumentException() { - Blend invalidBlend = new () { Factors = new float[2], Positions = new float[1] }; + Blend invalidBlend = new() { Factors = new float[2], Positions = new float[1] }; using PathGradientBrush brush = new(_defaultFloatPoints); AssertExtensions.Throws("value", null, () => brush.Blend = invalidBlend); @@ -554,9 +554,9 @@ public void InterpolationColors_CannotChange() Assert.NotEqual(Color.Pink, brush.InterpolationColors.Colors[0]); Assert.Equal(defaultColors, brush.InterpolationColors.Colors); brush.InterpolationColors.Positions = []; - Assert.Equal(1, brush.InterpolationColors.Positions.Length); + Assert.Single(brush.InterpolationColors.Positions); brush.InterpolationColors.Positions = new float[2]; - Assert.Equal(1, brush.InterpolationColors.Positions.Length); + Assert.Single(brush.InterpolationColors.Positions); } [Fact] @@ -688,7 +688,7 @@ public void ResetTransform_Disposed_ThrowsArgumentException() PathGradientBrush brush = new(_defaultFloatPoints); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.ResetTransform()); + AssertExtensions.Throws(null, brush.ResetTransform); } [Fact] @@ -941,7 +941,7 @@ private void AssertDefaults(PathGradientBrush brush) { Assert.Equal(_defaultRectangle, brush.Rectangle); Assert.Equal([1], brush.Blend.Factors); - Assert.Equal(1, brush.Blend.Positions.Length); + Assert.Single(brush.Blend.Positions); Assert.Equal(new PointF(10.5f, 16f), brush.CenterPoint); Assert.Equal(new Color[] { Color.Empty }, brush.InterpolationColors.Colors); Assert.Equal(new Color[] { Color.FromArgb(255, 255, 255, 255) }, brush.SurroundColors); diff --git a/src/System.Drawing.Common/tests/System/Drawing/FontTests.cs b/src/System.Drawing.Common/tests/System/Drawing/FontTests.cs index 3a3141ec1ba..e3bc4f9c2c3 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/FontTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/FontTests.cs @@ -411,7 +411,7 @@ public void Clone_DisposedFont_ThrowsArgumentException() Font font = new(family, 10); font.Dispose(); - AssertExtensions.Throws(null, () => font.Clone()); + AssertExtensions.Throws(null, font.Clone); } public static IEnumerable Equals_TestData() @@ -652,7 +652,7 @@ public void FromLogFont_UnblittableStruct() } } - [Serializable()] + [Serializable] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct UnblittableLOGFONT { diff --git a/src/System.Drawing.Common/tests/System/Drawing/GraphicsTests.cs b/src/System.Drawing.Common/tests/System/Drawing/GraphicsTests.cs index 8bdc68e8fc2..585f4e6a55f 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/GraphicsTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/GraphicsTests.cs @@ -141,12 +141,12 @@ public void ReleaseHdc_ValidHdc_ResetsHdc() hdc = graphics.GetHdc(); graphics.ReleaseHdc(hdc); - AssertExtensions.Throws(null, () => graphics.ReleaseHdc()); + AssertExtensions.Throws(null, graphics.ReleaseHdc); AssertExtensions.Throws(null, () => graphics.ReleaseHdcInternal(hdc)); hdc = graphics.GetHdc(); graphics.ReleaseHdcInternal(hdc); - AssertExtensions.Throws(null, () => graphics.ReleaseHdc()); + AssertExtensions.Throws(null, graphics.ReleaseHdc); AssertExtensions.Throws(null, () => graphics.ReleaseHdcInternal(hdc)); } @@ -187,7 +187,7 @@ public void ReleaseHdc_NoHdc_ThrowsArgumentException() { using Bitmap bitmap = new(10, 10); using Graphics graphics = Graphics.FromImage(bitmap); - AssertExtensions.Throws(null, () => graphics.ReleaseHdc()); + AssertExtensions.Throws(null, graphics.ReleaseHdc); AssertExtensions.Throws(null, () => graphics.ReleaseHdc(IntPtr.Zero)); AssertExtensions.Throws(null, () => graphics.ReleaseHdcInternal(IntPtr.Zero)); } @@ -199,7 +199,7 @@ public void ReleaseHdc_Disposed_ThrowsObjectDisposedException() Graphics graphics = Graphics.FromImage(bitmap); graphics.Dispose(); - AssertExtensions.Throws(null, () => graphics.ReleaseHdc()); + AssertExtensions.Throws(null, graphics.ReleaseHdc); AssertExtensions.Throws(null, () => graphics.ReleaseHdc(IntPtr.Zero)); AssertExtensions.Throws(null, () => graphics.ReleaseHdcInternal(IntPtr.Zero)); } @@ -556,7 +556,7 @@ public void Flush_Busy_ThrowsInvalidOperationException() graphics.GetHdc(); try { - Assert.Throws(() => graphics.Flush()); + Assert.Throws(graphics.Flush); Assert.Throws(() => graphics.Flush(FlushIntention.Sync)); } finally @@ -572,7 +572,7 @@ public void Flush_Disposed_ThrowsArgumentException() Graphics graphics = Graphics.FromImage(image); graphics.Dispose(); - AssertExtensions.Throws(null, () => graphics.Flush()); + AssertExtensions.Throws(null, graphics.Flush); AssertExtensions.Throws(null, () => graphics.Flush(FlushIntention.Flush)); } @@ -1163,7 +1163,7 @@ public void ResetTransform_Busy_ThrowsInvalidOperationException() graphics.GetHdc(); try { - Assert.Throws(() => graphics.ResetTransform()); + Assert.Throws(graphics.ResetTransform); } finally { @@ -1178,7 +1178,7 @@ public void ResetTransform_Disposed_ThrowsArgumentException() Graphics graphics = Graphics.FromImage(image); graphics.Dispose(); - AssertExtensions.Throws(null, () => graphics.ResetTransform()); + AssertExtensions.Throws(null, graphics.ResetTransform); } [Fact] @@ -2781,7 +2781,7 @@ public void DrawString_DefaultFont_Succeeds() { using Bitmap image = new(50, 50); using Graphics graphics = Graphics.FromImage(image); - graphics.DrawString("Test text", SystemFonts.DefaultFont, Brushes.White, new Point()); + graphics.DrawString("Test text", SystemFonts.DefaultFont, Brushes.White, default(Point)); Helpers.VerifyBitmapNotBlank(image); } @@ -2793,7 +2793,7 @@ public void DrawString_CompositingModeSourceCopy_ThrowsArgumentException() graphics.CompositingMode = CompositingMode.SourceCopy; AssertExtensions.Throws( null, - () => graphics.DrawString("Test text", SystemFonts.DefaultFont, Brushes.White, new Point())); + () => graphics.DrawString("Test text", SystemFonts.DefaultFont, Brushes.White, default(Point))); } private static void VerifyGraphics(Graphics graphics, RectangleF expectedVisibleClipBounds) @@ -2898,7 +2898,7 @@ public void DrawCachedBitmap_ColorDepthChange_ThrowsInvalidOperation( } #endif - internal unsafe static void VerifyBitmapEmpty(Bitmap bitmap) + internal static unsafe void VerifyBitmapEmpty(Bitmap bitmap) { BitmapData data = bitmap.LockBits(default, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); try @@ -2912,7 +2912,7 @@ internal unsafe static void VerifyBitmapEmpty(Bitmap bitmap) } } - internal unsafe static void VerifyBitmapNotEmpty(Bitmap bitmap) + internal static unsafe void VerifyBitmapNotEmpty(Bitmap bitmap) { BitmapData data = bitmap.LockBits(default, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); try diff --git a/src/System.Drawing.Common/tests/System/Drawing/IconTests.cs b/src/System.Drawing.Common/tests/System/Drawing/IconTests.cs index 7248a68534d..e4608cd1e91 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/IconTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/IconTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2004,2006-2008 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -551,7 +551,7 @@ public void ToBitmap_BitmapIconFromHandle_ReturnsExpected() [Fact] public void ToBitmap_PngIconSupportedInSwitches_Success() { - void VerifyPng() + static void VerifyPng() { using Icon icon = GetPngIcon(); using Bitmap bitmap = icon.ToBitmap(); @@ -586,10 +586,10 @@ void VerifyPng() [Fact] public void ToBitmap_PngIconNotSupportedInSwitches_ThrowsArgumentOutOfRangeException() { - void VerifyPngNotSupported() + static void VerifyPngNotSupported() { using Icon icon = GetPngIcon(); - AssertExtensions.Throws(null, () => icon.ToBitmap()); + AssertExtensions.Throws(null, icon.ToBitmap); } if (RemoteExecutor.IsSupported && (!AppContext.TryGetSwitch(DontSupportPngFramesInIcons, out bool isEnabled) || !isEnabled)) diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMapTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMapTests.cs index b4875fdc1ac..a8f152aa4e4 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMapTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMapTests.cs @@ -9,8 +9,8 @@ public class ColorMapTests public void Ctor_Default() { ColorMap cm = new(); - Assert.Equal(new Color(), cm.OldColor); - Assert.Equal(new Color(), cm.NewColor); + Assert.Equal(default, cm.OldColor); + Assert.Equal(default, cm.NewColor); } [Fact] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMatrixTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMatrixTests.cs index 992651797ae..8594144a084 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMatrixTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ColorMatrixTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2005-2007 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -81,8 +81,8 @@ public static IEnumerable BadCtorParams [3.0f], [4.0f], [5.0f] - } - , typeof(IndexOutOfRangeException) + }, + typeof(IndexOutOfRangeException) }; } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/Effects/EffectsTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/Effects/EffectsTests.cs index a35ed6b6b6f..41221dc9dc1 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/Effects/EffectsTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/Effects/EffectsTests.cs @@ -16,7 +16,7 @@ public void SepiaEffect_Apply() // We don't really need to check all effect results, just seeing that something changed for one is probably // enough until we look at providing alternative implementations. - bitmap.GetPixel(0,0).Should().Be(Color.FromArgb(255, 255, 255, 239)); + bitmap.GetPixel(0, 0).Should().Be(Color.FromArgb(255, 255, 255, 239)); } [Theory] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageAttributesTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageAttributesTests.cs index 671e95e8c14..9a08074a634 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageAttributesTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageAttributesTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -84,7 +84,7 @@ public void Clone_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.Clone()); + AssertExtensions.Throws(null, imageAttr.Clone); } [Fact] @@ -323,7 +323,7 @@ public void ClearColorMatrix_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.ClearColorMatrix()); + AssertExtensions.Throws(null, imageAttr.ClearColorMatrix); AssertExtensions.Throws(null, () => imageAttr.ClearColorMatrix(ColorAdjustType.Default)); } @@ -699,7 +699,7 @@ public void SetNoOp_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.SetNoOp()); + AssertExtensions.Throws(null, imageAttr.SetNoOp); AssertExtensions.Throws(null, () => imageAttr.SetNoOp(ColorAdjustType.Default)); } @@ -767,7 +767,7 @@ public void ClearNoOp_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.ClearNoOp()); + AssertExtensions.Throws(null, imageAttr.ClearNoOp); AssertExtensions.Throws(null, () => imageAttr.ClearNoOp(ColorAdjustType.Default)); } @@ -877,7 +877,7 @@ public void ClearColorKey_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.ClearColorKey()); + AssertExtensions.Throws(null, imageAttr.ClearColorKey); AssertExtensions.Throws(null, () => imageAttr.ClearColorKey(ColorAdjustType.Default)); } @@ -1038,7 +1038,7 @@ public void ClearOutputChannel_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.ClearOutputChannel()); + AssertExtensions.Throws(null, imageAttr.ClearOutputChannel); AssertExtensions.Throws(null, () => imageAttr.ClearOutputChannel(ColorAdjustType.Default)); } @@ -1153,7 +1153,7 @@ public void ClearOutputChannelColorProfile_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.ClearOutputChannelColorProfile()); + AssertExtensions.Throws(null, imageAttr.ClearOutputChannelColorProfile); AssertExtensions.Throws(null, () => imageAttr.ClearOutputChannelColorProfile(ColorAdjustType.Default)); } @@ -1275,7 +1275,7 @@ public void ClearRemapTable_Disposed_ThrowsArgumentException() ImageAttributes imageAttr = new(); imageAttr.Dispose(); - AssertExtensions.Throws(null, () => imageAttr.ClearRemapTable()); + AssertExtensions.Throws(null, imageAttr.ClearRemapTable); AssertExtensions.Throws(null, () => imageAttr.ClearRemapTable(ColorAdjustType.Default)); } diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageCodecInfoTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageCodecInfoTests.cs index e5b9574d58d..f49adde53d7 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageCodecInfoTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageCodecInfoTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Authors: // Jordi Mas i Hernandez (jordi@ximian.com) // Sebastien Pouliot diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageFormatTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageFormatTests.cs index a0fac187604..6e1bb80499c 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageFormatTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/ImageFormatTests.cs @@ -34,8 +34,10 @@ public static IEnumerable ImageFormatGuidTestData yield return new object[] { JpegImageFormat.Guid, ImageFormat.Jpeg }; yield return new object[] { WmfImageFormat.Guid, ImageFormat.Wmf }; #if NET +#pragma warning disable CA1416 // Validate platform compatibility yield return new object[] { HeifImageFormat.Guid, ImageFormat.Heif }; yield return new object[] { WebpImageFormat.Guid, ImageFormat.Webp }; +#pragma warning restore CA1416 #endif yield return new object[] { new Guid("48749428-316f-496a-ab30-c819a92b3137"), CustomImageFormat }; } @@ -56,8 +58,10 @@ public static IEnumerable ImageFormatToStringTestData yield return new object[] { "Jpeg", ImageFormat.Jpeg }; yield return new object[] { "Wmf", ImageFormat.Wmf }; #if NET +#pragma warning disable CA1416 // Validate platform compatibility yield return new object[] { "Heif", ImageFormat.Heif }; yield return new object[] { "Webp", ImageFormat.Webp }; +#pragma warning restore CA1416 #endif yield return new object[] { "[ImageFormat: 48749428-316f-496a-ab30-c819a92b3137]", CustomImageFormat }; } @@ -69,7 +73,7 @@ public static IEnumerable ImageFromFileToStringTestData { yield return new object[] { Path.Combine("bitmaps", "nature24bits.gif"), "Gif" }; yield return new object[] { Path.Combine("bitmaps", "nature24bits.jpg"), "Jpeg" }; - yield return new object[] { Path.Combine("bitmaps", "VisualPng.ico"), "Icon"}; + yield return new object[] { Path.Combine("bitmaps", "VisualPng.ico"), "Icon" }; yield return new object[] { Path.Combine("bitmaps", "almogaver32bits.tif"), "Tiff" }; } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/MetafileTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/MetafileTests.cs index 718c92189e0..2c76cca2cb5 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/MetafileTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/MetafileTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -513,7 +513,7 @@ public void Ctor_RectangleFEmpty_Success(string description) using (Bitmap bmp = new(10, 10, PixelFormat.Format32bppArgb)) using (Graphics g = Graphics.FromImage(bmp)) using (Metafile metafile = new( - fileName, g.GetHdc(), new RectangleF(), MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, description)) + fileName, g.GetHdc(), default(RectangleF), MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, description)) { AssertMetafileIsBlank(metafile); AssertEmfType(metafile.GetMetafileHeader(), EmfType.EmfOnly); @@ -597,7 +597,7 @@ public void Ctor_RectangleEmpty_Success(string description) using (Bitmap bmp = new(10, 10, PixelFormat.Format32bppArgb)) using (Graphics g = Graphics.FromImage(bmp)) using (Metafile metafile = new( - fileName, g.GetHdc(), new Rectangle(), MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, description)) + fileName, g.GetHdc(), default, MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, description)) { AssertMetafileIsBlank(metafile); AssertEmfType(metafile.GetMetafileHeader(), EmfType.EmfOnly); @@ -772,7 +772,7 @@ public void Ctor_RectangleEmptyI_Success(string description) using Graphics g = Graphics.FromImage(bmp); using MemoryStream stream = new(); using Metafile metafile = new( - stream, g.GetHdc(), new Rectangle(), MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, description); + stream, g.GetHdc(), default, MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, description); AssertMetafileIsBlank(metafile); AssertEmfType(metafile.GetMetafileHeader(), EmfType.EmfOnly); } @@ -898,7 +898,7 @@ public void GetMetafileHeader_Disposed_ThrowsArgumentException() Metafile metafile = new(GetPath(WmfFile)); metafile.Dispose(); - AssertExtensions.Throws(null, () => metafile.GetMetafileHeader()); + AssertExtensions.Throws(null, metafile.GetMetafileHeader); } [Fact] diff --git a/src/System.Drawing.Common/tests/System/Drawing/Imaging/PropertyItemTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Imaging/PropertyItemTests.cs index 0ff53a4714a..0ed061e03a1 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Imaging/PropertyItemTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Imaging/PropertyItemTests.cs @@ -63,7 +63,7 @@ public void Value_Set_GetReturnsExpected(byte[] value) public static IEnumerable Properties_TestData() { yield return new object[] { int.MaxValue, int.MaxValue, short.MaxValue, new byte[1] { 0 } }; - yield return new object[] { int.MinValue, int.MinValue, short.MinValue, new byte[2] { 1, 1} }; + yield return new object[] { int.MinValue, int.MinValue, short.MinValue, new byte[2] { 1, 1 } }; yield return new object[] { 0, 0, 0, new byte[0] }; } diff --git a/src/System.Drawing.Common/tests/System/Drawing/PenTests.cs b/src/System.Drawing.Common/tests/System/Drawing/PenTests.cs index 75c706ef23f..9556d01388d 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/PenTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/PenTests.cs @@ -148,7 +148,7 @@ public void Alignment_GetWhenDisposed_ThrowsArgumentException() [Theory] [MemberData(nameof(Ctor_Brush_TestData))] - public void Brush_SetValid_GetReturnsExpected(T brush, PenType penType) where T : Brush + public void Brush_SetValid_GetReturnsExpected(T brush, PenType penType) where T : Brush { using Pen pen = new(Color.Red); pen.Brush = brush; @@ -228,7 +228,7 @@ public void Clone_Disposed_ThrowsArgumentException() Pen pen = new(brush); pen.Dispose(); - AssertExtensions.Throws(null, () => pen.Clone()); + AssertExtensions.Throws(null, pen.Clone); } [Fact] @@ -875,7 +875,7 @@ public void ResetTransform_Disposed_ThrowsArgumentException() Pen pen = new(brush); pen.Dispose(); - AssertExtensions.Throws(null, () => pen.ResetTransform()); + AssertExtensions.Throws(null, pen.ResetTransform); } public static IEnumerable RotateTransform_TestData() diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/MarginsTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/MarginsTests.cs index 9a5dd530ead..c78f7b14819 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/MarginsTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/MarginsTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Authors: // Sebastien Pouliot // diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/PageSettingsTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/PageSettingsTests.cs index e14c72f99ec..853d075f182 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/PageSettingsTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/PageSettingsTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/PaperSourceTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/PaperSourceTests.cs index be8d9d5f983..b6c9c2fc5e5 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/PaperSourceTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/PaperSourceTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2009 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrintDocumentTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrintDocumentTests.cs index edacdcb97d5..d1982fbabdc 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrintDocumentTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrintDocumentTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -203,7 +203,7 @@ public void PrintPage_SetValue_ReturnsExpected() Assert.False(flag); } - [ConditionalFact(Helpers.AnyInstalledPrinters)] + [ConditionalFact(Helpers.AnyInstalledPrinters)] public void QueryPageSettings_SetValue_ReturnsExpected() { bool flag = false; diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterResolutionTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterResolutionTests.cs index 32515088b9b..c1492490dff 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterResolutionTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterResolutionTests.cs @@ -85,7 +85,7 @@ public void Kind_SetInvalid_ThrowsInvalidEnumArgumentException(PrinterResolution public static IEnumerable ToString_TestData() { yield return new object[] { new PrinterResolution(), "[PrinterResolution X=0 Y=0]" }; - yield return new object[] { new PrinterResolution { X = -1, Y = -2}, "[PrinterResolution X=-1 Y=-2]" }; + yield return new object[] { new PrinterResolution { X = -1, Y = -2 }, "[PrinterResolution X=-1 Y=-2]" }; yield return new object[] { new PrinterResolution { Kind = PrinterResolutionKind.High }, "[PrinterResolution High]" }; yield return new object[] { new PrinterResolution { X = 1, Y = 2, Kind = PrinterResolutionKind.High }, "[PrinterResolution High]" }; } diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterSettingsTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterSettingsTests.cs index 1095420831d..29660da2f69 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterSettingsTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterSettingsTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Authors: // Sebastien Pouliot // diff --git a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterUnitConvertTests.cs b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterUnitConvertTests.cs index e067aec9ed3..3dc964fc8cf 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterUnitConvertTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/Printing/PrinterUnitConvertTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining diff --git a/src/System.Drawing.Common/tests/System/Drawing/RegionTests.cs b/src/System.Drawing.Common/tests/System/Drawing/RegionTests.cs index 9fc440edd59..4ced62e9aa0 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/RegionTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/RegionTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Copyright (C) 2004-2008 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -517,8 +517,8 @@ public void Complement_Disposed_ThrowsArgumentException() using GraphicsPath graphicPath = new(); using Region other = new(); AssertExtensions.Throws(null, () => disposedRegion.Complement(graphicPath)); - AssertExtensions.Throws(null, () => disposedRegion.Complement(new Rectangle())); - AssertExtensions.Throws(null, () => disposedRegion.Complement(new RectangleF())); + AssertExtensions.Throws(null, () => disposedRegion.Complement(default(Rectangle))); + AssertExtensions.Throws(null, () => disposedRegion.Complement(default(RectangleF))); AssertExtensions.Throws(null, () => disposedRegion.Complement(disposedRegion)); } @@ -581,7 +581,7 @@ public void Equals_Valid_ReturnsExpected(Region region, Region other, bool expec using (region) using (other) { - Assert.Equal(expected, region.Equals(other, s_graphic)); + Assert.Equal(expected, region.Equals(other, s_graphic)); } } @@ -900,8 +900,8 @@ public void Exclude_Disposed_ThrowsArgumentException() using GraphicsPath graphicsPath = new(); using Region other = new(); AssertExtensions.Throws(null, () => disposedRegion.Exclude(graphicsPath)); - AssertExtensions.Throws(null, () => disposedRegion.Exclude(new Rectangle())); - AssertExtensions.Throws(null, () => disposedRegion.Exclude(new RectangleF())); + AssertExtensions.Throws(null, () => disposedRegion.Exclude(default(Rectangle))); + AssertExtensions.Throws(null, () => disposedRegion.Exclude(default(RectangleF))); AssertExtensions.Throws(null, () => disposedRegion.Exclude(other)); } @@ -1051,7 +1051,7 @@ public void Intersect_SmallerRect_Success() Assert.False(clipRegion.IsInfinite(s_graphic)); RectangleF[] rects = clipRegion.GetRegionScans(matrix); - Assert.Equal(1, rects.Length); + Assert.Single(rects); Assert.Equal(new RectangleF(-5, -5, 10, 10), rects[0]); } @@ -1257,8 +1257,8 @@ public void Intersect_Disposed_ThrowsArgumentException() using GraphicsPath graphicsPath = new(); using Region other = new(); AssertExtensions.Throws(null, () => disposedRegion.Intersect(graphicsPath)); - AssertExtensions.Throws(null, () => disposedRegion.Intersect(new Rectangle())); - AssertExtensions.Throws(null, () => disposedRegion.Intersect(new RectangleF())); + AssertExtensions.Throws(null, () => disposedRegion.Intersect(default(Rectangle))); + AssertExtensions.Throws(null, () => disposedRegion.Intersect(default(RectangleF))); AssertExtensions.Throws(null, () => disposedRegion.Intersect(other)); } @@ -1796,8 +1796,8 @@ public void Union_Disposed_ThrowsArgumentException() using GraphicsPath graphicsPath = new(); using Region other = new(); AssertExtensions.Throws(null, () => disposedRegion.Union(graphicsPath)); - AssertExtensions.Throws(null, () => disposedRegion.Union(new Rectangle())); - AssertExtensions.Throws(null, () => disposedRegion.Union(new RectangleF())); + AssertExtensions.Throws(null, () => disposedRegion.Union(default(Rectangle))); + AssertExtensions.Throws(null, () => disposedRegion.Union(default(RectangleF))); AssertExtensions.Throws(null, () => disposedRegion.Union(disposedRegion)); } @@ -2154,8 +2154,8 @@ public void Xor_Disposed_ThrowsArgumentException() using GraphicsPath graphicsPath = new(); using Region other = new(); AssertExtensions.Throws(null, () => disposedRegion.Xor(graphicsPath)); - AssertExtensions.Throws(null, () => disposedRegion.Xor(new Rectangle())); - AssertExtensions.Throws(null, () => disposedRegion.Xor(new RectangleF())); + AssertExtensions.Throws(null, () => disposedRegion.Xor(default(Rectangle))); + AssertExtensions.Throws(null, () => disposedRegion.Xor(default(RectangleF))); AssertExtensions.Throws(null, () => disposedRegion.Xor(other)); } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/SolidBrushTests.cs b/src/System.Drawing.Common/tests/System/Drawing/SolidBrushTests.cs index 7f984a8d843..9242e1a461d 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/SolidBrushTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/SolidBrushTests.cs @@ -7,7 +7,7 @@ public class SolidBrushTests { public static IEnumerable Colors_TestData() { - yield return new object[] { new Color(), Color.FromArgb(0) }; + yield return new object[] { default(Color), Color.FromArgb(0) }; yield return new object[] { Color.PapayaWhip, Color.PapayaWhip }; } @@ -53,13 +53,13 @@ public void Clone_Disposed_ThrowsArgumentException() SolidBrush brush = new(Color.LavenderBlush); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.Clone()); + AssertExtensions.Throws(null, brush.Clone); } [Fact] public void Color_EmptyAndGetDisposed_ThrowsArgumentException() { - SolidBrush brush = new(new Color()); + SolidBrush brush = new(default(Color)); brush.Dispose(); AssertExtensions.Throws(null, () => brush.Color); @@ -84,7 +84,7 @@ public void Color_SetValid_GetReturnsExpected() [Fact] public void Color_SetDisposed_ThrowsArgumentException() { - SolidBrush brush = new(new Color()); + SolidBrush brush = new(default(Color)); brush.Dispose(); AssertExtensions.Throws(null, () => brush.Color = Color.WhiteSmoke); @@ -109,6 +109,6 @@ public void Dispose_MultipleTimes_Success() public void Dispose_SetImmutable_ThrowsArgumentException() { SolidBrush brush = Assert.IsType(SystemBrushes.ActiveBorder); - AssertExtensions.Throws(null, () => brush.Dispose()); + AssertExtensions.Throws(null, brush.Dispose); } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/StringFormatTests.cs b/src/System.Drawing.Common/tests/System/Drawing/StringFormatTests.cs index 95159343624..a84fe087689 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/StringFormatTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/StringFormatTests.cs @@ -119,7 +119,7 @@ public void Clone_Disposed_ThrowsArgumentException() StringFormat format = new(); format.Dispose(); - AssertExtensions.Throws(null, () => format.Clone()); + AssertExtensions.Throws(null, format.Clone); } [Theory] @@ -429,6 +429,6 @@ public void ToString_Disposed_ThrowsArgumentException() StringFormat format = new(StringFormatFlags.DirectionVertical); format.Dispose(); - AssertExtensions.Throws(null, () => format.ToString()); + AssertExtensions.Throws(null, format.ToString); } } diff --git a/src/System.Drawing.Common/tests/System/Drawing/SystemFontsTests.cs b/src/System.Drawing.Common/tests/System/Drawing/SystemFontsTests.cs index 6c5f5afb388..9a4c0343c82 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/SystemFontsTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/SystemFontsTests.cs @@ -65,7 +65,7 @@ public static IEnumerable SystemFonts_WindowsNames_TestData() // am-ET 0x5E => new SystemFontList("Ebrima"), // For now we assume everything else uses Segoe UI - _ => new SystemFontList("Segoe UI"),// If there's other failure reported we can add it + _ => new SystemFontList("Segoe UI"), // If there's other failure reported we can add it }; return fonts.ToTestData(); } @@ -125,7 +125,7 @@ public SystemFontList(string c_it_m_mb_scFonts) public IEnumerable ToTestData() { - return new [] + return new[] { new object[] { () => SystemFonts.CaptionFont, nameof(CaptionFont), CaptionFont}, [(() => SystemFonts.IconTitleFont), nameof(IconTitleFont), IconTitleFont], diff --git a/src/System.Drawing.Common/tests/System/Drawing/SystemPensTest.cs b/src/System.Drawing.Common/tests/System/Drawing/SystemPensTest.cs index 213171dffa1..95c766cbbd8 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/SystemPensTest.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/SystemPensTest.cs @@ -55,7 +55,7 @@ public void SystemPens_Get_ReturnsExpected(Func getPen, Color expectedColor Assert.Equal(PenType.SolidColor, pen.PenType); Assert.Same(pen, getPen()); - AssertExtensions.Throws(null, () => pen.Dispose()); + AssertExtensions.Throws(null, pen.Dispose); AssertExtensions.Throws(null, () => pen.SetLineCap(LineCap.ArrowAnchor, LineCap.Custom, DashCap.Round)); AssertExtensions.Throws(null, () => pen.Alignment = PenAlignment.Center); diff --git a/src/System.Drawing.Common/tests/System/Drawing/TextureBrushTests.cs b/src/System.Drawing.Common/tests/System/Drawing/TextureBrushTests.cs index d887bfbb9a0..f6c67e69697 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/TextureBrushTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/TextureBrushTests.cs @@ -315,7 +315,7 @@ public void Clone_Disposed_ThrowsArgumentException() TextureBrush brush = new(image); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.Clone()); + AssertExtensions.Throws(null, brush.Clone); } [Fact] @@ -450,7 +450,7 @@ public void ResetTransform_Disposed_ThrowsArgumentException() TextureBrush brush = new(image); brush.Dispose(); - AssertExtensions.Throws(null, () => brush.ResetTransform()); + AssertExtensions.Throws(null, brush.ResetTransform); } public static IEnumerable RotateTransform_TestData() diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/BmpCodecTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/BmpCodecTests.cs index 47aaea6e29f..2c38870ac07 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/BmpCodecTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/BmpCodecTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // BMPCodec class testing unit // // Authors: diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/GifCodecTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/GifCodecTests.cs index d7fd26fd37e..7fd52c13b80 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/GifCodecTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/GifCodecTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // GIF Codec class testing unit // // Authors: diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/IconCodecTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/IconCodecTests.cs index 71389f054d3..25f68e36b64 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/IconCodecTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/IconCodecTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // ICO Codec class testing unit // // Authors: @@ -49,7 +49,7 @@ public void Image16() Assert.True(bmp.RawFormat.Equals(ImageFormat.MemoryBmp)); Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(2, bmp.Flags); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] @@ -57,7 +57,7 @@ public void Image16_PaletteEntries() { string sInFile = Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico"); using Image image = Image.FromFile(sInFile); - Assert.Equal(0, image.Palette.Entries.Length); + Assert.Empty(image.Palette.Entries); } // simley.ico has 48x48, 32x32 and 16x16 images (in that order) @@ -74,9 +74,9 @@ public void Bitmap16Features() Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(73746, bmp.Flags); - Assert.Equal(1, bmp.FrameDimensionsList.Length); - Assert.Equal(0, bmp.PropertyIdList.Length); - Assert.Equal(0, bmp.PropertyItems.Length); + Assert.Single(bmp.FrameDimensionsList); + Assert.Empty(bmp.PropertyIdList); + Assert.Empty(bmp.PropertyItems); Assert.Null(bmp.Tag); Assert.Equal(96.0f, bmp.HorizontalResolution); Assert.Equal(96.0f, bmp.VerticalResolution); @@ -97,7 +97,7 @@ public void Bitmap16Features_Palette_Entries() { string sInFile = Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"); using Bitmap bmp = new(sInFile); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] @@ -222,9 +222,9 @@ public void Bitmap32Features() Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(73746, bmp.Flags); - Assert.Equal(1, bmp.FrameDimensionsList.Length); - Assert.Equal(0, bmp.PropertyIdList.Length); - Assert.Equal(0, bmp.PropertyItems.Length); + Assert.Single(bmp.FrameDimensionsList); + Assert.Empty(bmp.PropertyIdList); + Assert.Empty(bmp.PropertyItems); Assert.Null(bmp.Tag); Assert.Equal(96.0f, bmp.HorizontalResolution); Assert.Equal(96.0f, bmp.VerticalResolution); @@ -245,7 +245,7 @@ public void Bitmap32Features_PaletteEntries() { string sInFile = Helpers.GetTestBitmapPath("VisualPng.ico"); using Bitmap bmp = new(sInFile); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] @@ -427,9 +427,9 @@ public void Bitmap48Features() Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(73746, bmp.Flags); - Assert.Equal(1, bmp.FrameDimensionsList.Length); - Assert.Equal(0, bmp.PropertyIdList.Length); - Assert.Equal(0, bmp.PropertyItems.Length); + Assert.Single(bmp.FrameDimensionsList); + Assert.Empty(bmp.PropertyIdList); + Assert.Empty(bmp.PropertyItems); Assert.Null(bmp.Tag); Assert.Equal(96.0f, bmp.HorizontalResolution); Assert.Equal(96.0f, bmp.VerticalResolution); @@ -450,7 +450,7 @@ public void Bitmap48Features_Palette_Entries() { string sInFile = Helpers.GetTestBitmapPath("48x48_one_entry_1bit.ico"); using Bitmap bmp = new(sInFile); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] @@ -649,9 +649,9 @@ public void Bitmap64Features() Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(73746, bmp.Flags); - Assert.Equal(1, bmp.FrameDimensionsList.Length); - Assert.Equal(0, bmp.PropertyIdList.Length); - Assert.Equal(0, bmp.PropertyItems.Length); + Assert.Single(bmp.FrameDimensionsList); + Assert.Empty(bmp.PropertyIdList); + Assert.Empty(bmp.PropertyItems); Assert.Null(bmp.Tag); Assert.Equal(96.0f, bmp.HorizontalResolution); Assert.Equal(96.0f, bmp.VerticalResolution); @@ -672,7 +672,7 @@ public void Bitmap64Features_Palette_Entries() { string sInFile = Helpers.GetTestBitmapPath("64x64_one_entry_8bit.ico"); using Bitmap bmp = new(sInFile); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] @@ -907,9 +907,9 @@ public void Bitmap96Features() Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(73746, bmp.Flags); - Assert.Equal(1, bmp.FrameDimensionsList.Length); - Assert.Equal(0, bmp.PropertyIdList.Length); - Assert.Equal(0, bmp.PropertyItems.Length); + Assert.Single(bmp.FrameDimensionsList); + Assert.Empty(bmp.PropertyIdList); + Assert.Empty(bmp.PropertyItems); Assert.Null(bmp.Tag); Assert.Equal(96.0f, bmp.HorizontalResolution); Assert.Equal(96.0f, bmp.VerticalResolution); @@ -930,7 +930,7 @@ public void Bitmap96Features_Palette_Entries() { string sInFile = Helpers.GetTestBitmapPath("96x96_one_entry_8bit.ico"); using Bitmap bmp = new(sInFile); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] @@ -1840,10 +1840,10 @@ public void Xp32bppIconFeatures() // note that image is "promoted" to 32bits Assert.Equal(PixelFormat.Format32bppArgb, bmp.PixelFormat); Assert.Equal(73746, bmp.Flags); - Assert.Equal(0, bmp.Palette.Entries.Length); - Assert.Equal(1, bmp.FrameDimensionsList.Length); - Assert.Equal(0, bmp.PropertyIdList.Length); - Assert.Equal(0, bmp.PropertyItems.Length); + Assert.Empty(bmp.Palette.Entries); + Assert.Single(bmp.FrameDimensionsList); + Assert.Empty(bmp.PropertyIdList); + Assert.Empty(bmp.PropertyItems); Assert.Null(bmp.Tag); Assert.Equal(96.0f, bmp.HorizontalResolution); Assert.Equal(96.0f, bmp.VerticalResolution); diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/JpegCodecTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/JpegCodecTests.cs index d775fec9aec..76be41e6df2 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/JpegCodecTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/JpegCodecTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // JpegCodec class testing unit // // Authors: @@ -192,7 +192,7 @@ public void Bitmap24bitFeatures() /* note: under MS flags aren't constant between executions in this case (no palette) */ // Assert.Equal(77960, bmp.Flags); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); } [Fact] diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/PngCodecTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/PngCodecTests.cs index d56f273e9ee..59c89b471a6 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/PngCodecTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/PngCodecTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // PNG Codec class testing unit // // Authors: @@ -251,7 +251,7 @@ public void Bitmap2bitFeatures() // MS returns a random Flags value (not a good sign) // Assert.Equal (0, bmp.Palette.Flags); - Assert.Equal(0, bmp.Palette.Entries.Length); + Assert.Empty(bmp.Palette.Entries); Assert.Equal(100, bmp.Width); Assert.Equal(100, bmp.Height); diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/TiffCodecTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/TiffCodecTests.cs index 7a137090b07..1a613fe6999 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/TiffCodecTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing.Imaging/TiffCodecTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // TIFF Codec class testing unit // // Authors: diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing/BitmapTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing/BitmapTests.cs index 9daf0662ba6..b9ac7040295 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing/BitmapTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing/BitmapTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Bitmap class testing unit // // Authors: @@ -554,7 +554,7 @@ private static byte[] HashLock(Bitmap bmp, int width, int height, PixelFormat fm // The results match the .NET Framework private static readonly byte[] s_defaultBitmapHash = [0x29, 0x39, 0x25, 0xCE, 0x10, 0x9C, 0x6A, 0xB, 0x2D, 0xCD, 0xAA, 0xD9, 0x18, 0xBE, 0xF3, 0xA5, 0x58, 0xA5, 0x4D, 0xD9, 0xFA, 0x41, 0x70, 0x76, 0x83, 0x3, 0x9C, 0x41, 0x5A, 0x25, 0xCE, 0xCB]; - private static readonly byte[] s_finalWholeBitmapHash = [0xDE, 0xBF, 0xCF, 0xFB, 0xE, 0x9E, 0xA7, 0xC1, 0x23, 0xC, 0x9E,0x7E, + private static readonly byte[] s_finalWholeBitmapHash = [0xDE, 0xBF, 0xCF, 0xFB, 0xE, 0x9E, 0xA7, 0xC1, 0x23, 0xC, 0x9E, 0x7E, 0xE3, 0xC1, 0xFC, 0x14, 0x37, 0x21, 0xE2, 0x30, 0x2A, 0x6D, 0xD0, 0xDB, 0xBE, 0xE, 0x1C, 0x1F, 0xC2, 0xB7, 0xBD, 0xC4]; [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] // [ActiveIssue("https://github.com/dotnet/winforms/issues/8817")] @@ -1182,7 +1182,7 @@ private static void HiconTest(string msg, Bitmap b, int size) b.PixelFormat.Should().Be(PixelFormat.Format32bppArgb, msg); // Unlike the GDI+ icon decoder the palette isn't kept - Assert.Equal(0, b.Palette.Entries.Length); + Assert.Empty(b.Palette.Entries); Assert.Equal(size, b.Height); Assert.Equal(size, b.Width); Assert.Equal(b.RawFormat, ImageFormat.MemoryBmp); @@ -1269,7 +1269,7 @@ public void HBitmap() using (Bitmap bitmap = new(sInFile)) { Assert.Equal(PixelFormat.Format24bppRgb, bitmap.PixelFormat); - Assert.Equal(0, bitmap.Palette.Entries.Length); + Assert.Empty(bitmap.Palette.Entries); Assert.Equal(183, bitmap.Height); Assert.Equal(173, bitmap.Width); Assert.Equal(73744, bitmap.Flags); @@ -1280,7 +1280,7 @@ public void HBitmap() // hbitmap survives original bitmap disposal using Image image = Image.FromHbitmap(hbitmap); // Assert.Equal (PixelFormat.Format32bppRgb, image.PixelFormat); - Assert.Equal(0, image.Palette.Entries.Length); + Assert.Empty(image.Palette.Entries); Assert.Equal(183, image.Height); Assert.Equal(173, image.Width); Assert.Equal(335888, image.Flags); @@ -1295,7 +1295,7 @@ public void CreateMultipleBitmapFromSameHBITMAP() using (Bitmap bitmap = new(sInFile)) { Assert.Equal(PixelFormat.Format24bppRgb, bitmap.PixelFormat); - Assert.Equal(0, bitmap.Palette.Entries.Length); + Assert.Empty(bitmap.Palette.Entries); Assert.Equal(183, bitmap.Height); Assert.Equal(173, bitmap.Width); Assert.Equal(73744, bitmap.Flags); @@ -1307,7 +1307,7 @@ public void CreateMultipleBitmapFromSameHBITMAP() using (Image image = Image.FromHbitmap(hbitmap)) { // Assert.Equal (PixelFormat.Format32bppRgb, image.PixelFormat); - Assert.Equal(0, image.Palette.Entries.Length); + Assert.Empty(image.Palette.Entries); Assert.Equal(183, image.Height); Assert.Equal(173, image.Width); Assert.Equal(335888, image.Flags); @@ -1316,7 +1316,7 @@ public void CreateMultipleBitmapFromSameHBITMAP() using Image image2 = Image.FromHbitmap(hbitmap); // Assert.Equal (PixelFormat.Format32bppRgb, image2.PixelFormat); - Assert.Equal(0, image2.Palette.Entries.Length); + Assert.Empty(image2.Palette.Entries); Assert.Equal(183, image2.Height); Assert.Equal(173, image2.Width); Assert.Equal(335888, image2.Flags); diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs index b6e19ea56ae..8dde4209c2e 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Graphics class testing unit // // Authors: @@ -154,7 +154,7 @@ public void Clip() g.Clip = new Region(new Rectangle(50, 40, 210, 220)); rects = g.Clip.GetRegionScans(new Matrix()); - Assert.Equal(1, rects.Length); + Assert.Single(rects); Assert.Equal(50, rects[0].X); Assert.Equal(40, rects[0].Y); Assert.Equal(210, rects[0].Width); @@ -208,7 +208,7 @@ public void IntersectClip() g.IntersectClip(new Rectangle(290, 40, 60, 80)); _rects = g.Clip.GetRegionScans(new Matrix()); - Assert.Equal(1, _rects.Length); + Assert.Single(_rects); Assert.Equal(290, _rects[0].X); Assert.Equal(40, _rects[0].Y); @@ -226,7 +226,7 @@ public void ResetClip() g.ResetClip(); _rects = g.Clip.GetRegionScans(new Matrix()); - Assert.Equal(1, _rects.Length); + Assert.Single(_rects); Assert.Equal(-4194304, _rects[0].X); Assert.Equal(-4194304, _rects[0].Y); @@ -244,7 +244,7 @@ public void SetClip() // Region g.SetClip(new Region(new Rectangle(50, 40, 210, 220)), CombineMode.Replace); rects = g.Clip.GetRegionScans(new Matrix()); - Assert.Equal(1, rects.Length); + Assert.Single(rects); Assert.Equal(50, rects[0].X); Assert.Equal(40, rects[0].Y); Assert.Equal(210, rects[0].Width); @@ -256,7 +256,7 @@ public void SetClip() { g.SetClip(new RectangleF(50, 40, 210, 220)); rects = g.Clip.GetRegionScans(new Matrix()); - Assert.Equal(1, rects.Length); + Assert.Single(rects); Assert.Equal(50, rects[0].X); Assert.Equal(40, rects[0].Y); Assert.Equal(210, rects[0].Width); @@ -268,7 +268,7 @@ public void SetClip() { g.SetClip(new Rectangle(50, 40, 210, 220)); rects = g.Clip.GetRegionScans(new Matrix()); - Assert.Equal(1, rects.Length); + Assert.Single(rects); Assert.Equal(50, rects[0].X); Assert.Equal(40, rects[0].Y); Assert.Equal(210, rects[0].Width); @@ -1848,22 +1848,22 @@ public void MeasureCharacterRanges_NullOrEmptyText() { using Bitmap bitmap = new(20, 20); using Graphics g = Graphics.FromImage(bitmap); - Region[] regions = g.MeasureCharacterRanges(null, _font, new RectangleF(), null); - Assert.Equal(0, regions.Length); + Region[] regions = g.MeasureCharacterRanges(null, _font, default, null); + Assert.Empty(regions); - regions = g.MeasureCharacterRanges(string.Empty, _font, new RectangleF(), null); - Assert.Equal(0, regions.Length); - regions = g.MeasureCharacterRanges(string.Empty.AsSpan(), _font, new RectangleF(), null); - Assert.Equal(0, regions.Length); + regions = g.MeasureCharacterRanges(string.Empty, _font, default, null); + Assert.Empty(regions); + regions = g.MeasureCharacterRanges(string.Empty.AsSpan(), _font, default, null); + Assert.Empty(regions); // null font is ok with null or empty string - regions = g.MeasureCharacterRanges(null, null, new RectangleF(), null); - Assert.Equal(0, regions.Length); + regions = g.MeasureCharacterRanges(null, null, default, null); + Assert.Empty(regions); - regions = g.MeasureCharacterRanges(string.Empty, null, new RectangleF(), null); - Assert.Equal(0, regions.Length); - regions = g.MeasureCharacterRanges(string.Empty.AsSpan(), null, new RectangleF(), null); - Assert.Equal(0, regions.Length); + regions = g.MeasureCharacterRanges(string.Empty, null, default, null); + Assert.Empty(regions); + regions = g.MeasureCharacterRanges(string.Empty.AsSpan(), null, default, null); + Assert.Empty(regions); } [Fact] @@ -1872,11 +1872,11 @@ public void MeasureCharacterRanges_EmptyStringFormat() using Bitmap bitmap = new(20, 20); using Graphics g = Graphics.FromImage(bitmap); // string format without character ranges - Region[] regions = g.MeasureCharacterRanges("Mono", _font, new RectangleF(), new StringFormat()); - Assert.Equal(0, regions.Length); + Region[] regions = g.MeasureCharacterRanges("Mono", _font, default, new StringFormat()); + Assert.Empty(regions); - g.MeasureCharacterRanges("Mono".AsSpan(), _font, new RectangleF(), new StringFormat()); - Assert.Equal(0, regions.Length); + g.MeasureCharacterRanges("Mono".AsSpan(), _font, default, new StringFormat()); + Assert.Empty(regions); } [Fact] @@ -1884,8 +1884,8 @@ public void MeasureCharacterRanges_FontNull() { using Bitmap bitmap = new(20, 20); using Graphics g = Graphics.FromImage(bitmap); - Assert.Throws(() => g.MeasureCharacterRanges("a", null, new RectangleF(), null)); - Assert.Throws(() => g.MeasureCharacterRanges("a".AsSpan(), null, new RectangleF(), null)); + Assert.Throws(() => g.MeasureCharacterRanges("a", null, default, null)); + Assert.Throws(() => g.MeasureCharacterRanges("a".AsSpan(), null, default, null)); } [Fact] @@ -2000,8 +2000,8 @@ public void MeasureCharacterRanges_NullStringFormat() { using Bitmap bitmap = new(20, 20); using Graphics g = Graphics.FromImage(bitmap); - Assert.Throws(() => g.MeasureCharacterRanges("Mono", _font, new RectangleF(), null)); - Assert.Throws(() => g.MeasureCharacterRanges("Mono".AsSpan(), _font, new RectangleF(), null)); + Assert.Throws(() => g.MeasureCharacterRanges("Mono", _font, default, null)); + Assert.Throws(() => g.MeasureCharacterRanges("Mono".AsSpan(), _font, default, null)); } private static readonly CharacterRange[] s_ranges = [new(0, 1), new(1, 1), new(2, 1)]; @@ -2177,7 +2177,7 @@ public void TestReleaseHdcException() { using Bitmap b = new(10, 10); using Graphics g = Graphics.FromImage(b); - Assert.Throws(() => g.ReleaseHdc()); + Assert.Throws(g.ReleaseHdc); } [Fact] @@ -2187,7 +2187,7 @@ public void TestReleaseHdcException2() using Graphics g = Graphics.FromImage(b); g.GetHdc(); g.ReleaseHdc(); - Assert.Throws(() => g.ReleaseHdc()); + Assert.Throws(g.ReleaseHdc); } [ConditionalFact] @@ -2535,7 +2535,7 @@ public void DrawImage_ImagePointArray() { using Bitmap bmp = new(40, 40); using Graphics g = Graphics.FromImage(bmp); - g.DrawImage(bmp, [ new(0, 0), new(1, 1), new(2, 2)]); + g.DrawImage(bmp, [new(0, 0), new(1, 1), new(2, 2)]); } [Fact] @@ -2591,7 +2591,7 @@ public void DrawImage_NullRectangleRectangleGraphicsUnit() { using Bitmap bmp = new(40, 40); using Graphics g = Graphics.FromImage(bmp); - Assert.Throws(() => g.DrawImage(null, new Rectangle(), new Rectangle(), GraphicsUnit.Display)); + Assert.Throws(() => g.DrawImage(null, default(Rectangle), default, GraphicsUnit.Display)); } private void DrawImage_ImageRectangleRectangleGraphicsUnit(GraphicsUnit unit) diff --git a/src/System.Drawing.Common/tests/mono/System.Imaging/MetafileTest.cs b/src/System.Drawing.Common/tests/mono/System.Imaging/MetafileTest.cs index 39e72ae2c19..bfbfc1a6dd1 100644 --- a/src/System.Drawing.Common/tests/mono/System.Imaging/MetafileTest.cs +++ b/src/System.Drawing.Common/tests/mono/System.Imaging/MetafileTest.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// + // Metafile class unit tests // // Authors: @@ -218,7 +218,7 @@ public void Metafile_IntPtrRectangle_Empty() IntPtr hdc = g.GetHdc(); try { - Metafile mf = new(hdc, new Rectangle()); + Metafile mf = new(hdc, default(Rectangle)); CheckEmptyHeader(mf, EmfType.EmfPlusDual); } finally @@ -235,7 +235,7 @@ public void Metafile_IntPtrRectangleF_Empty() IntPtr hdc = g.GetHdc(); try { - Metafile mf = new(hdc, new RectangleF()); + Metafile mf = new(hdc, default(RectangleF)); CheckEmptyHeader(mf, EmfType.EmfPlusDual); } finally diff --git a/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/BinaryFormatWriterTests.cs b/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/BinaryFormatWriterTests.cs index c50d94e3d34..771fd2fb064 100644 --- a/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/BinaryFormatWriterTests.cs +++ b/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/BinaryFormatWriterTests.cs @@ -178,8 +178,8 @@ public void BinaryFormatWriter_TryWriteDrawingPrimitivesObject_UnsupportedObject public static TheoryData SystemDrawing_TestData => new() { - new PointF(), - new RectangleF() + default(PointF), + default(RectangleF) }; public static TheoryData DrawingPrimitives_TestData => new() @@ -225,7 +225,7 @@ public void BinaryFormatWriter_TryWriteDrawingPrimitivesObject_UnsupportedObject public static TheoryData Array_UnsupportedTestData => new() { - new Point[] { new() }, + new Point[] { default }, new object[] { new() }, }; } diff --git a/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/HashTableTests.cs b/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/HashTableTests.cs index 4b10daa9078..2ac417127d3 100644 --- a/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/HashTableTests.cs +++ b/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/HashTableTests.cs @@ -233,11 +233,11 @@ public void RoundTripHashtables(Hashtable hashtable) }, new Hashtable() { - { "Foo", new Point() } + { "Foo", default(Point) } }, new Hashtable() { - { "Foo", new PointF() } + { "Foo", default(PointF) } }, new Hashtable() { diff --git a/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/ListTests.cs b/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/ListTests.cs index 450d4cc46d9..5961a44afb6 100644 --- a/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/ListTests.cs +++ b/src/System.Private.Windows.Core/tests/BinaryFormatTests/FormatTests/FormattedObject/ListTests.cs @@ -47,7 +47,7 @@ public class ListTests : SerializationTest new ArrayList() { int.MaxValue, - new Point() + default(Point) } }; diff --git a/src/System.Private.Windows.Core/tests/System.Private.Windows.Core.Tests/System/Value/StoringNull.cs b/src/System.Private.Windows.Core/tests/System.Private.Windows.Core.Tests/System/Value/StoringNull.cs index e2b4af09144..cb0e09b4d6e 100644 --- a/src/System.Private.Windows.Core/tests/System.Private.Windows.Core.Tests/System/Value/StoringNull.cs +++ b/src/System.Private.Windows.Core/tests/System.Private.Windows.Core.Tests/System/Value/StoringNull.cs @@ -17,6 +17,6 @@ public void GetIntFromStoredNull() bool success = nullFastValue.TryGetValue(out int result); Assert.False(success); - Assert.Equal(default(int), result); + Assert.Equal(default, result); } } diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Generators/ProjectFileReaderTests.FontConverter.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Generators/ProjectFileReaderTests.FontConverter.cs index f506d5fa375..fe302182d71 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Generators/ProjectFileReaderTests.FontConverter.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Generators/ProjectFileReaderTests.FontConverter.cs @@ -33,27 +33,27 @@ public static TheoryData TestConve { CultureInfo culture = new(cultureName); - testData.Add(culture, $"Courier New", "Courier New", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Regular); - testData.Add(culture, $"Courier New{s_separator} 11", "Courier New", 11f, (int)GraphicsUnit.Point,(int)FontStyle.Regular); - testData.Add(culture, $"Arial{s_separator} 11px", "Arial", 11f, (int)GraphicsUnit.Pixel,(int)FontStyle.Regular); - testData.Add(culture, $"Courier New{s_separator} 11 px", "Courier New", 11f, (int)GraphicsUnit.Pixel,(int)FontStyle.Regular); - testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Regular", "Courier New", 11f, (int)GraphicsUnit.Pixel,(int)FontStyle.Regular); - testData.Add(culture, $"Courier New{s_separator} style=Bold", "Courier New", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Bold); - testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Bold{s_separator} Italic", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Bold |FontStyle.Italic)); - testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Regular, Italic", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Regular |FontStyle.Italic)); - testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Bold{s_separator} Italic{s_separator} Strikeout", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Bold |FontStyle.Italic |FontStyle.Strikeout)); - testData.Add(culture, $"Arial{s_separator} 11 px{s_separator} style=Bold, Italic, Strikeout", "Arial", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Bold |FontStyle.Italic |FontStyle.Strikeout)); - testData.Add(culture, $"arIAL{s_separator} 10{s_separator} style=bold", "arIAL", 10f, (int)GraphicsUnit.Point,(int)FontStyle.Bold); - testData.Add(culture, $"Arial{s_separator} 10{s_separator}", "Arial", 10f, (int)GraphicsUnit.Point,(int)FontStyle.Regular); - testData.Add(culture, $"Arial{s_separator}", "Arial", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Regular); - testData.Add(culture, $"Arial{s_separator} 10{s_separator} style=12", "Arial", 10f, (int)GraphicsUnit.Point, (int)(FontStyle.Underline |FontStyle.Strikeout)); - testData.Add(culture, $"Courier New{s_separator} Style=Bold", "Courier New", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Bold); // FullFramework style keyword is case sensitive. - testData.Add(culture, $"{s_separator} 10{s_separator} style=bold", "", 10f, (int)GraphicsUnit.Point,(int)FontStyle.Bold); + testData.Add(culture, $"Courier New", "Courier New", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Regular); + testData.Add(culture, $"Courier New{s_separator} 11", "Courier New", 11f, (int)GraphicsUnit.Point, (int)FontStyle.Regular); + testData.Add(culture, $"Arial{s_separator} 11px", "Arial", 11f, (int)GraphicsUnit.Pixel, (int)FontStyle.Regular); + testData.Add(culture, $"Courier New{s_separator} 11 px", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)FontStyle.Regular); + testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Regular", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)FontStyle.Regular); + testData.Add(culture, $"Courier New{s_separator} style=Bold", "Courier New", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Bold); + testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Bold{s_separator} Italic", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Bold | FontStyle.Italic)); + testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Regular, Italic", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Regular | FontStyle.Italic)); + testData.Add(culture, $"Courier New{s_separator} 11 px{s_separator} style=Bold{s_separator} Italic{s_separator} Strikeout", "Courier New", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout)); + testData.Add(culture, $"Arial{s_separator} 11 px{s_separator} style=Bold, Italic, Strikeout", "Arial", 11f, (int)GraphicsUnit.Pixel, (int)(FontStyle.Bold | FontStyle.Italic | FontStyle.Strikeout)); + testData.Add(culture, $"arIAL{s_separator} 10{s_separator} style=bold", "arIAL", 10f, (int)GraphicsUnit.Point, (int)FontStyle.Bold); + testData.Add(culture, $"Arial{s_separator} 10{s_separator}", "Arial", 10f, (int)GraphicsUnit.Point, (int)FontStyle.Regular); + testData.Add(culture, $"Arial{s_separator}", "Arial", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Regular); + testData.Add(culture, $"Arial{s_separator} 10{s_separator} style=12", "Arial", 10f, (int)GraphicsUnit.Point, (int)(FontStyle.Underline | FontStyle.Strikeout)); + testData.Add(culture, $"Courier New{s_separator} Style=Bold", "Courier New", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Bold); // FullFramework style keyword is case sensitive. + testData.Add(culture, $"{s_separator} 10{s_separator} style=bold", "", 10f, (int)GraphicsUnit.Point, (int)FontStyle.Bold); // NOTE: in .NET runtime these tests will result in FontName='', but the implementation relies on GDI+, which we don't have... - testData.Add(culture, $"11px{s_separator} Style=Bold", $"11px", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Bold); - testData.Add(culture, $"11px", "11px", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Regular); - testData.Add(culture, $"Style=Bold", "Style=Bold", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point,(int)FontStyle.Regular); + testData.Add(culture, $"11px{s_separator} Style=Bold", $"11px", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Bold); + testData.Add(culture, $"11px", "11px", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Regular); + testData.Add(culture, $"Style=Bold", "Style=Bold", PropertyDefaultValue.FontSize, (int)GraphicsUnit.Point, (int)FontStyle.Regular); } return testData; diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/TestAdditionalText.cs b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/TestAdditionalText.cs index d2c3d139283..9506b416169 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/TestAdditionalText.cs +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/TestAdditionalText.cs @@ -32,4 +32,3 @@ public TestAdditionalText(string text = "", Encoding? encoding = null, string pa public override SourceText GetText(CancellationToken cancellationToken = default) => _text; } - diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ResourceCodeDomSerializer.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ResourceCodeDomSerializer.cs index 9a8a6075675..f06497e7ade 100644 --- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ResourceCodeDomSerializer.cs +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ResourceCodeDomSerializer.cs @@ -38,10 +38,10 @@ internal partial class ResourceCodeDomSerializer : CodeDomSerializer { name = methodInvokeEx.Parameters switch { - // We've found a call to the ApplyResources method on a ComponentResourceManager object. now we just need to figure out - // which component ApplyResources is being called for, and put it into that component's bucket. - [CodeFieldReferenceExpression { TargetObject: CodeThisReferenceExpression } fieldReferenceEx, ..] => fieldReferenceEx.FieldName, - [CodeVariableReferenceExpression variableReferenceEx, ..] => variableReferenceEx.VariableName, + // We've found a call to the ApplyResources method on a ComponentResourceManager object. now we just need to figure out + // which component ApplyResources is being called for, and put it into that component's bucket. + [CodeFieldReferenceExpression { TargetObject: CodeThisReferenceExpression } fieldReferenceEx, ..] => fieldReferenceEx.FieldName, + [CodeVariableReferenceExpression variableReferenceEx, ..] => variableReferenceEx.VariableName, _ => null }; } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/AnchorEditor.AnchorUI.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/AnchorEditor.AnchorUI.cs index 8548b4a74d6..15d695106a0 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/AnchorEditor.AnchorUI.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/AnchorEditor.AnchorUI.cs @@ -210,7 +210,7 @@ private class SpringControl : Control public SpringControl(AnchorUI picker) { - _picker = picker ?? throw new ArgumentException(); + _picker = picker ?? throw new ArgumentNullException(nameof(picker)); TabStop = true; } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolboxSnapDragDropEventArgs.SnapDirection.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolboxSnapDragDropEventArgs.SnapDirection.cs index 7807b1bf9e8..61db5a0cc29 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolboxSnapDragDropEventArgs.SnapDirection.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/ToolboxSnapDragDropEventArgs.SnapDirection.cs @@ -11,10 +11,10 @@ internal sealed partial class ToolboxSnapDragDropEventArgs [Flags] public enum SnapDirection { - None = 0x00, - Top = 0x01, - Bottom = 0x02, - Right = 0x04, - Left = 0x08 + None = 0x00, + Top = 0x01, + Bottom = 0x02, + Right = 0x04, + Left = 0x08 } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DocumentDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DocumentDesigner.cs index 94cc41a65b8..139dcd9b63b 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DocumentDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DocumentDesigner.cs @@ -1433,15 +1433,10 @@ ViewTechnology[] IRootDesigner.SupportedTechnologies /// The view for this document. The designer should assume that the view will be shown shortly /// after this call is made and make any necessary preparations. /// - object IRootDesigner.GetView(ViewTechnology technology) - { - if (technology is not ViewTechnology.Default and not ((ViewTechnology)1)) - { - throw new ArgumentException(); - } - - return _frame; - } + object IRootDesigner.GetView(ViewTechnology technology) => + technology is not ViewTechnology.Default and not (ViewTechnology)1 + ? throw new ArgumentException(null, nameof(technology)) + : (object)_frame; /// /// Determines if the given tool is supported by this designer. diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FolderNameEditor.FolderBrowserStyles.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FolderNameEditor.FolderBrowserStyles.cs index dd85db0271e..b9e1ae8f0a0 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FolderNameEditor.FolderBrowserStyles.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/FolderNameEditor.FolderBrowserStyles.cs @@ -8,12 +8,12 @@ public partial class FolderNameEditor [Flags] protected enum FolderBrowserStyles { - BrowseForComputer = (int)PInvoke.BIF_BROWSEFORCOMPUTER, - BrowseForEverything = (int)PInvoke.BIF_BROWSEINCLUDEFILES, - BrowseForPrinter = (int)PInvoke.BIF_BROWSEFORPRINTER, - RestrictToDomain = (int)PInvoke.BIF_DONTGOBELOWDOMAIN, - RestrictToFilesystem = (int)PInvoke.BIF_RETURNONLYFSDIRS, - RestrictToSubfolders = (int)PInvoke.BIF_RETURNFSANCESTORS, - ShowTextBox = (int)PInvoke.BIF_EDITBOX + BrowseForComputer = (int)PInvoke.BIF_BROWSEFORCOMPUTER, + BrowseForEverything = (int)PInvoke.BIF_BROWSEINCLUDEFILES, + BrowseForPrinter = (int)PInvoke.BIF_BROWSEFORPRINTER, + RestrictToDomain = (int)PInvoke.BIF_DONTGOBELOWDOMAIN, + RestrictToFilesystem = (int)PInvoke.BIF_RETURNONLYFSDIRS, + RestrictToSubfolders = (int)PInvoke.BIF_RETURNFSANCESTORS, + ShowTextBox = (int)PInvoke.BIF_EDITBOX } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ImageListDesigner.OriginalImageCollection.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ImageListDesigner.OriginalImageCollection.cs index 8420ab297e5..436ae943ffc 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ImageListDesigner.OriginalImageCollection.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ImageListDesigner.OriginalImageCollection.cs @@ -69,7 +69,7 @@ public ImageListImage this[int index] object? IList.this[int index] { get => this[index]; - set => this[index] = value is ImageListImage image ? image : throw new ArgumentException(); + set => this[index] = value is ImageListImage image ? image : throw new ArgumentException(null, nameof(index)); } public void SetKeyName(int index, string name) @@ -110,7 +110,7 @@ public void AddRange(ImageListImage[] values) } } - int IList.Add(object? value) => value is ImageListImage image ? Add(image) : throw new ArgumentException(); + int IList.Add(object? value) => value is ImageListImage image ? Add(image) : throw new ArgumentException(null, nameof(value)); // Called when reloading the form. In this case, we have no "originals" list, // so we make one out of the image list. diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/CodeDomHelpers.cs b/src/System.Windows.Forms.Design/tests/UnitTests/CodeDomHelpers.cs index f1c9ede3a4a..2926cd3f50d 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/CodeDomHelpers.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/CodeDomHelpers.cs @@ -67,7 +67,7 @@ public static string GetConstructionString(CodeObject o) return $"new CodeObjectCreateExpression({GetType(coce.CreateType)})"; } - string parameters = string.Join(", ", coce.Parameters.Cast().Select(o => GetConstructionString(o))); + string parameters = string.Join(", ", coce.Parameters.Cast().Select(GetConstructionString)); return $"new CodeObjectCreateExpression({GetType(coce.CreateType)}, {parameters})"; } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/ControlDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/ControlDesignerTests.cs index 8360bfb0d7c..5a2e5279f9d 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/ControlDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/ControlDesignerTests.cs @@ -19,7 +19,7 @@ public void ControlDesigner_Ctor_Default() Assert.True(controlDesigner.ControlSupportsSnaplines); Assert.Throws(() => controlDesigner.Component); Assert.True(controlDesigner.ForceVisible); - Assert.Throws(() => controlDesigner.GetParentComponentProperty()); + Assert.Throws(controlDesigner.GetParentComponentProperty); Assert.False(controlDesigner.SerializePerformLayout); } @@ -164,7 +164,7 @@ public void GetHitTest() using TestControlDesigner controlDesigner = new(); using Button button = new(); controlDesigner.Initialize(button); - Assert.False(controlDesigner.GetHitTestMethod(new Drawing.Point())); + Assert.False(controlDesigner.GetHitTestMethod(default)); } [Fact] @@ -273,6 +273,6 @@ public void ControlDesigner_AssociatedComponentsTest() childControl.Site = mockSite.Object; control.Controls.Add(childControl); - Assert.Equal(1, controlDesigner.AssociatedComponents.Count); + Assert.Single(controlDesigner.AssociatedComponents); } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/GlobalSuppressions.cs b/src/System.Windows.Forms.Design/tests/UnitTests/GlobalSuppressions.cs index 74c4ab93ea5..4df68b277ea 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/GlobalSuppressions.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/GlobalSuppressions.cs @@ -1,7 +1,5 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/Mocks/MockSite.cs b/src/System.Windows.Forms.Design/tests/UnitTests/Mocks/MockSite.cs index 0d2d899c3fe..44f57e24bc6 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/Mocks/MockSite.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/Mocks/MockSite.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.ComponentModel; using Moq; diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/SplitContainerDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/SplitContainerDesignerTests.cs index 5297724aade..af202c39af7 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/SplitContainerDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/SplitContainerDesignerTests.cs @@ -24,7 +24,7 @@ private Mock GetMockSize(SplitContainer splitContainer, SplitContainerDes .Setup(s => s.GetService(typeof(IComponentChangeService))) .Returns(mockComponentChangeService.Object); - return MockSite.CreateMockSiteWithDesignerHost(mockDesignerHost.Object); + return MockSite.CreateMockSiteWithDesignerHost(mockDesignerHost.Object); } [WinFormsFact] @@ -43,7 +43,7 @@ public void SplitContainerDesigner_AssociatedComponentsTest() using Control control = new(); control.Parent = splitContainer.Panel1; - Assert.Equal(1, splitContainerDesigner.AssociatedComponents.Count); + Assert.Single(splitContainerDesigner.AssociatedComponents); } // Regression test for https://github.com/dotnet/winforms/issues/11793 diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs index ececff2e734..bda27a91e4d 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ArrayEditorTests.cs @@ -246,6 +246,7 @@ private class ClassWithItem } #pragma warning disable IDE0051 // Remove unused private members +#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable private class ClassWithPrivateItem { private int Item { get; set; } @@ -317,5 +318,5 @@ private class ClassWithNoSuchDefaultProperty } #pragma warning restore IDE0051 - +#pragma warning restore CA1052 } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs index 06dbe18f9d0..1380021c8b4 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs @@ -110,7 +110,7 @@ public void CollectionEditor_CreateCollectionForm_Invoke_Success() public void CollectionEditor_CreateCollectionForm_NullCollectionType_ThrowsArgumentNullException() { SubCollectionEditor editor = new(null); - Assert.Throws("type", () => editor.CreateCollectionForm()); + Assert.Throws("type", editor.CreateCollectionForm); } [Theory] @@ -135,7 +135,7 @@ public void CollectionEditor_CreateCollectionItemType_Invoke_ReturnsExpected(Typ public void CollectionEditor_CreateCollectionItemType_NullType_ThrowsArgumentNullException() { SubCollectionEditor editor = new(null); - Assert.Throws("type", () => editor.CreateCollectionItemType()); + Assert.Throws("type", editor.CreateCollectionItemType); } public static IEnumerable InvalidDesignerHost_TestData() @@ -383,7 +383,7 @@ public void CollectionEditor_CreateNewItemTypes_Invoke_ReturnsExpected(Type type public void CollectionEditor_CreateNewItemTypes_NullType_ThrowsArgumentNullException() { SubCollectionEditor editor = new(null); - Assert.Throws("type", () => editor.CreateNewItemTypes()); + Assert.Throws("type", editor.CreateNewItemTypes); } public static IEnumerable DestroyInstance_NormalObject_TestData() @@ -1072,7 +1072,9 @@ private class ClassWithPrivateItem #pragma warning restore IDE0051 } +#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable private class ClassWithStaticItem +#pragma warning restore CA1052 // Static holder types should be Static or NotInheritable { public static int Item { get; set; } } @@ -1089,7 +1091,9 @@ private class ClassWithPrivateItems #pragma warning restore IDE0051 } +#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable private class ClassWithStaticItems +#pragma warning restore CA1052 // Static holder types should be Static or NotInheritable { public static int Items { get; set; } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ComponentDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ComponentDesignerTests.cs index e78cff53327..360167df910 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ComponentDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ComponentDesignerTests.cs @@ -1262,7 +1262,7 @@ public void ComponentDesigner_DoDefaultAction_InvokeWithNotCanceledThrowingCreat designer.Initialize(rootComponent); component.StringPropertySetCount = 0; - Assert.Throws(exception.GetType(), () => designer.DoDefaultAction()); + Assert.Throws(exception.GetType(), designer.DoDefaultAction); mockSite.Verify(s => s.GetService(typeof(IEventBindingService)), Times.Once()); mockSite.Verify(s => s.GetService(typeof(ISelectionService)), Times.Once()); mockSite.Verify(s => s.GetService(typeof(IDesignerHost)), Times.Exactly(2)); @@ -1273,7 +1273,7 @@ public void ComponentDesigner_DoDefaultAction_InvokeWithNotCanceledThrowingCreat Assert.Equal(0, component.StringPropertySetCount); // Call again. - Assert.Throws(exception.GetType(), () => designer.DoDefaultAction()); + Assert.Throws(exception.GetType(), designer.DoDefaultAction); mockSite.Verify(s => s.GetService(typeof(IEventBindingService)), Times.Exactly(2)); mockSite.Verify(s => s.GetService(typeof(ISelectionService)), Times.Exactly(2)); mockSite.Verify(s => s.GetService(typeof(IDesignerHost)), Times.Exactly(3)); @@ -1554,7 +1554,7 @@ public void ComponentDesigner_DoDefaultAction_InvokeThrowsNonInvalidOperationExc designer.Initialize(rootComponent); component.StringPropertySetCount = 0; - Assert.Throws(exception.GetType(), () => designer.DoDefaultAction()); + Assert.Throws(exception.GetType(), designer.DoDefaultAction); mockSite.Verify(s => s.GetService(typeof(IEventBindingService)), Times.Once()); mockSite.Verify(s => s.GetService(typeof(ISelectionService)), Times.Once()); mockSite.Verify(s => s.GetService(typeof(IDesignerHost)), Times.Exactly(2)); @@ -1567,7 +1567,7 @@ public void ComponentDesigner_DoDefaultAction_InvokeThrowsNonInvalidOperationExc Assert.Equal(0, component.StringPropertySetCount); // Call again. - Assert.Throws(exception.GetType(), () => designer.DoDefaultAction()); + Assert.Throws(exception.GetType(), designer.DoDefaultAction); mockSite.Verify(s => s.GetService(typeof(IEventBindingService)), Times.Exactly(2)); mockSite.Verify(s => s.GetService(typeof(ISelectionService)), Times.Exactly(2)); mockSite.Verify(s => s.GetService(typeof(IDesignerHost)), Times.Exactly(3)); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignSurfaceTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignSurfaceTests.cs index 027afabedd8..8ce95669e1b 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignSurfaceTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignSurfaceTests.cs @@ -1190,7 +1190,7 @@ public void DesignSurface_Dispose_InvokeHasLoader_ThrowsInvalidOperationExceptio mockLoader .Setup(l => l.BeginLoad(host)); surface.BeginLoad(mockLoader.Object); - Assert.Throws(() => surface.Dispose()); + Assert.Throws(surface.Dispose); Assert.True(host.Loading); // Should not throw again. @@ -1211,7 +1211,7 @@ public void DesignSurface_Dispose_InvokeHasHostWithTransactions_ThrowsInvalidOpe Assert.True(host.Loading); Assert.True(host.InTransaction); Assert.Equal("Transaction1", host.TransactionDescription); - Assert.Throws(() => surface.Dispose()); + Assert.Throws(surface.Dispose); Assert.True(host.Loading); Assert.True(host.InTransaction); Assert.Equal("Transaction1", host.TransactionDescription); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionMethodItemTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionMethodItemTests.cs index 178ae9371f3..60c1a7afac2 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionMethodItemTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionMethodItemTests.cs @@ -205,7 +205,7 @@ public void Invoke_ValidMemberName_ReturnsExpected(string memberName) public void Invoke_NullActionList_ThrowsInvalidOperationException() { DesignerActionMethodItem item = new(null, "memberName", "displayName", "category", "description"); - Assert.Throws(() => item.Invoke()); + Assert.Throws(item.Invoke); } [Theory] @@ -216,7 +216,7 @@ public void Invoke_NoSuchMemberName_ThrowsInvalidOperationException(string membe { SubDesignerActionList list = new(); DesignerActionMethodItem item = new(list, memberName, "displayName", "category", "description"); - Assert.Throws(() => item.Invoke()); + Assert.Throws(item.Invoke); } [Fact] @@ -224,7 +224,7 @@ public void Invoke_NullMemberName_ThrowsArgumentNullException() { SubDesignerActionList list = new(); DesignerActionMethodItem item = new(list, null, "displayName", "category", "description"); - Assert.Throws("name", () => item.Invoke()); + Assert.Throws("name", item.Invoke); } [Fact] @@ -232,7 +232,7 @@ public void Invoke_MemberWithParameters_ThrowsTargetParameterCountException() { SubDesignerActionList list = new(); DesignerActionMethodItem item = new(list, nameof(SubDesignerActionList.MethodWithParameters), "displayName", "category", "description"); - Assert.Throws(() => item.Invoke()); + Assert.Throws(item.Invoke); } private class SubDesignerActionList : DesignerActionList diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerHostTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerHostTests.cs index 435da486d0a..c536ad4bed3 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerHostTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerHostTests.cs @@ -1797,7 +1797,7 @@ public void DesignerHost_Dispose_Invoke_ThrowsInvalidOperationException() SubDesignSurface surface = new(); IDesignerLoaderHost2 host = surface.Host; IDisposable disposable = Assert.IsAssignableFrom(host); - Assert.Throws(() => disposable.Dispose()); + Assert.Throws(disposable.Dispose); } [WinFormsFact(Skip = "Unstable test, see: https://github.com/dotnet/winforms/issues/1460")] @@ -1809,7 +1809,7 @@ public void DesignerHost_Add_DesignerDisposeThrowsDuringUnloadingDispose_ThrowsI using ThrowingDesignerDisposeComponent component = new(); host.Container.Add(component); - Assert.Throws(() => surface.Dispose()); + Assert.Throws(surface.Dispose); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.False(host.Loading); @@ -1824,7 +1824,7 @@ public void DesignerHost_Add_ComponentDisposeThrowsDuringUnloadingDispose_Throws using ThrowingDisposeDesignerComponent component = new(); host.Container.Add(component); - Assert.Throws(() => surface.Dispose()); + Assert.Throws(surface.Dispose); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.False(host.Loading); @@ -1837,7 +1837,7 @@ public void DesignerHost_Add_RootDesignerDisposeThrowsDuringUnloadingDispose_Thr IDesignerLoaderHost2 host = surface.Host; surface.BeginLoad(typeof(ThrowingRootDesignerDisposeComponent)); - Assert.Throws(() => surface.Dispose()); + Assert.Throws(surface.Dispose); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.False(host.Loading); @@ -1849,7 +1849,7 @@ public void DesignerHost_Add_RootComponentDisposeThrowsDuringUnloadingDispose_Th SubDesignSurface surface = new(); IDesignerLoaderHost2 host = surface.Host; surface.BeginLoad(typeof(ThrowingDisposeRootDesignerComponent)); - Assert.Throws(() => surface.Dispose()); + Assert.Throws(surface.Dispose); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.False(host.Loading); @@ -2066,7 +2066,7 @@ public void DesignerHost_CreateTransaction_CancelNested_ThrowsInvalidOperationEx IDesignerLoaderHost2 host = surface.Host; DesignerTransaction transaction1 = host.CreateTransaction("Description1"); DesignerTransaction transaction2 = host.CreateTransaction("Description2"); - Assert.Throws(() => transaction1.Cancel()); + Assert.Throws(transaction1.Cancel); } [WinFormsFact] @@ -2179,7 +2179,7 @@ public void DesignerHost_CreateTransaction_CommitNested_ThrowsInvalidOperationEx IDesignerLoaderHost2 host = surface.Host; DesignerTransaction transaction1 = host.CreateTransaction("Description1"); DesignerTransaction transaction2 = host.CreateTransaction("Description2"); - Assert.Throws(() => transaction1.Commit()); + Assert.Throws(transaction1.Commit); } public static IEnumerable DesignerHost_EndLoad_TestData() diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ExceptionCollectionTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ExceptionCollectionTests.cs index 860d03dceca..e09ffba0499 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ExceptionCollectionTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/ExceptionCollectionTests.cs @@ -13,7 +13,7 @@ public static IEnumerable Ctor_ArrayList_TestData() { yield return new object[] { null }; yield return new object[] { new ArrayList() }; - yield return new object[] { new ArrayList { new InvalidOperationException(), new InvalidOperationException(), new InvalidOperationException()} }; + yield return new object[] { new ArrayList { new InvalidOperationException(), new InvalidOperationException(), new InvalidOperationException() } }; } [Theory] @@ -63,6 +63,6 @@ public void ExceptionCollection_Serialize_ThrowsSerializationException(bool form public void ExceptionCollection_GetObjectData_ThrowsPlatformNotSupportedException() { ExceptionCollection collection = new(new ArrayList()); - Assert.Throws(() => collection.GetObjectData(null, new StreamingContext())); + Assert.Throws(() => collection.GetObjectData(null, default)); } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationServiceTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationServiceTests.cs index 4d75dd2f21d..5b6857c7364 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationServiceTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomComponentSerializationServiceTests.cs @@ -133,7 +133,7 @@ public void CreateStore_CloseSerialize_Success() Assert.Empty(store.Errors); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); Assert.Equal(2, state.Count); @@ -236,7 +236,7 @@ public void CreateStore_CloseSerializeWithInvalidProvider_Success(object result) mockServiceProvider.Verify(p => p.GetService(typeof(MemberRelationshipService)), Times.Exactly(3)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -338,7 +338,7 @@ public void CreateStore_CloseSerializeWithValidProvider_Success(object component mockServiceProvider.Verify(p => p.GetService(typeof(DesignerOptionService)), Times.Once()); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -383,7 +383,7 @@ public void CreateStore_CloseSerializeAbsolute_Success() Assert.Empty(store.Errors); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -434,7 +434,7 @@ public void CreateStore_CloseSerializeMember_Success() Assert.Empty(store.Errors); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -480,7 +480,7 @@ public void CreateStore_CloseSerializeMemberAbsolute_Success() Assert.Empty(store.Errors); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -524,7 +524,7 @@ public void CreateStore_CloseSerializeThenSerializeMember_Success() Assert.Empty(store.Errors); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -573,7 +573,7 @@ public void CreateStore_CloseSerializeMemberThenSerialize_Success() Assert.Empty(store.Errors); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); Dictionary state = GetState(info); CodeDomComponentSerializationState valueState = state["name"]; @@ -620,7 +620,7 @@ public void CreateStore_CloseSerializeThrows_Success() Site = mockSite.Object }; service.Serialize(store, value); - Assert.Throws(() => store.Close()); + Assert.Throws(store.Close); Assert.Empty(store.Errors); } @@ -643,7 +643,7 @@ public void CreateStore_ISerializableGetObjectDataDefault_Success() SerializationStore store = service.CreateStore(); ISerializable serializable = Assert.IsAssignableFrom(store); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); Assert.Empty(Assert.IsType>(info.GetValue("Names", typeof(List)))); @@ -662,7 +662,7 @@ public void CreateStore_ISerializableGetObjectDataSerialized_Success() service.Serialize(store, value); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); Assert.NotEmpty(Assert.IsType>(info.GetValue("Names", typeof(List)))); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -676,7 +676,7 @@ public void CreateStore_ISerializableGetObjectDataDefaultNullInfo_ThrowsArgument CodeDomComponentSerializationService service = new(); SerializationStore store = service.CreateStore(); ISerializable serializable = Assert.IsAssignableFrom(store); - Assert.Throws("info", () => serializable.GetObjectData(null, new StreamingContext())); + Assert.Throws("info", () => serializable.GetObjectData(null, default)); } [Theory] @@ -715,7 +715,7 @@ public void Serialize_InvokeObject_Success() object value = new(); service.Serialize(store, value); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -726,7 +726,7 @@ public void Serialize_InvokeObject_Success() // Serialize again. service.Serialize(store, value); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -752,7 +752,7 @@ public void Serialize_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -765,7 +765,7 @@ public void Serialize_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -800,7 +800,7 @@ public void Serialize_InvokeIComponentWithISite_Success(string name, int expecte mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -814,7 +814,7 @@ public void Serialize_InvokeIComponentWithISite_Success(string name, int expecte mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -860,7 +860,7 @@ public void Serialize_InvokeIComponentWithINestedSite_Success(string fullName, i mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -873,7 +873,7 @@ public void Serialize_InvokeIComponentWithINestedSite_Success(string fullName, i mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -923,7 +923,7 @@ public void SerializeAbsolute_InvokeObject_Success() object value = new(); service.SerializeAbsolute(store, value); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -934,7 +934,7 @@ public void SerializeAbsolute_InvokeObject_Success() // Serialize again. service.SerializeAbsolute(store, value); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -960,7 +960,7 @@ public void SerializeAbsolute_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -973,7 +973,7 @@ public void SerializeAbsolute_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1008,7 +1008,7 @@ public void SerializeAbsolute_InvokeIComponentWithISite_Success(string name, int mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1022,7 +1022,7 @@ public void SerializeAbsolute_InvokeIComponentWithISite_Success(string name, int mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1068,7 +1068,7 @@ public void SerializeAbsolute_InvokeIComponentWithINestedSite_Success(string ful mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1081,7 +1081,7 @@ public void SerializeAbsolute_InvokeIComponentWithINestedSite_Success(string ful mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1133,7 +1133,7 @@ public void SerializeMember_InvokeObject_Success() object value = new(); service.SerializeMember(store, value, member1); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1144,7 +1144,7 @@ public void SerializeMember_InvokeObject_Success() // Serialize again. service.SerializeMember(store, value, member1); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1155,7 +1155,7 @@ public void SerializeMember_InvokeObject_Success() // Serialize another. service.SerializeMember(store, value, member2); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1183,7 +1183,7 @@ public void SerializeMember_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1196,7 +1196,7 @@ public void SerializeMember_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1209,7 +1209,7 @@ public void SerializeMember_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1246,7 +1246,7 @@ public void SerializeMember_InvokeIComponentWithISite_Success(string name, int e mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1260,7 +1260,7 @@ public void SerializeMember_InvokeIComponentWithISite_Success(string name, int e mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1274,7 +1274,7 @@ public void SerializeMember_InvokeIComponentWithISite_Success(string name, int e mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1322,7 +1322,7 @@ public void SerializeMember_InvokeIComponentWithINestedSite_Success(string fullN mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1335,7 +1335,7 @@ public void SerializeMember_InvokeIComponentWithINestedSite_Success(string fullN mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1348,7 +1348,7 @@ public void SerializeMember_InvokeIComponentWithINestedSite_Success(string fullN mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1412,7 +1412,7 @@ public void SerializeMemberAbsolute_InvokeObject_Success() object value = new(); service.SerializeMemberAbsolute(store, value, member1); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1423,7 +1423,7 @@ public void SerializeMemberAbsolute_InvokeObject_Success() // Serialize again. service.SerializeMemberAbsolute(store, value, member1); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1434,7 +1434,7 @@ public void SerializeMemberAbsolute_InvokeObject_Success() // Serialize another. service.SerializeMemberAbsolute(store, value, member2); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1462,7 +1462,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1475,7 +1475,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1488,7 +1488,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithoutSite_Success() mockComponent.Verify(c => c.Site, Times.Once()); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches("^object_........_...._...._...._............$", nameResult); @@ -1525,7 +1525,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithISite_Success(string nam mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1539,7 +1539,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithISite_Success(string nam mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1553,7 +1553,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithISite_Success(string nam mockSite.Verify(s => s.Name, Times.Exactly(expectedCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); AssertNullState(info); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); @@ -1601,7 +1601,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithINestedSite_Success(stri mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); SerializationInfo info = new(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); string nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1614,7 +1614,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithINestedSite_Success(stri mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); @@ -1627,7 +1627,7 @@ public void SerializeMemberAbsolute_InvokeIComponentWithINestedSite_Success(stri mockNestedSite.Verify(s => s.FullName, Times.Exactly(expectedFullNameCallCount)); info = new SerializationInfo(store.GetType(), new FormatterConverter()); - serializable.GetObjectData(info, new StreamingContext()); + serializable.GetObjectData(info, default); nameResult = Assert.IsType(Assert.Single(Assert.IsType>(info.GetValue("Names", typeof(List))))); Assert.Matches(expectedPattern, nameResult); Assert.Null(info.GetValue("Assemblies", typeof(AssemblyName[]))); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomSerializerExceptionTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomSerializerExceptionTests.cs index be1f4c1ae3c..2c7b3f44220 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomSerializerExceptionTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/CodeDomSerializerExceptionTests.cs @@ -106,6 +106,6 @@ public void CodeDomSerializerException_Serialize_ThrowsSerializationException(bo public void CodeDomSerializerException_GetObjectData_ThrowsPlatformNotSupportedException() { CodeDomSerializerException exception = new("message", new CodeLinePragma("fileName.cs", 11)); - Assert.Throws(() => exception.GetObjectData(null, new StreamingContext())); + Assert.Throws(() => exception.GetObjectData(null, default)); } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/DesignerSerializationManagerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/DesignerSerializationManagerTests.cs index bd70e5fec8d..d10dd7470d0 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/DesignerSerializationManagerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/Serialization/DesignerSerializationManagerTests.cs @@ -705,7 +705,7 @@ public void DesignerSerializationManager_CreateSession_InvokeWithSession_ThrowsI { DesignerSerializationManager manager = new(); manager.CreateSession(); - Assert.Throws(() => manager.CreateSession()); + Assert.Throws(manager.CreateSession); } public static IEnumerable GetInstance_NoSuchInstance_TestData() diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxItemTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxItemTests.cs index b888ae5ff86..8e2dce80827 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxItemTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxItemTests.cs @@ -973,7 +973,7 @@ public void ToolboxItem_CheckUnlocked_Locked_ThrowsInvalidOperationException() { SubToolboxItem item = new(); item.Lock(); - Assert.Throws(() => item.CheckUnlocked()); + Assert.Throws(item.CheckUnlocked); } public static IEnumerable Equals_TestData() diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/AxImporterTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/AxImporterTests.cs index 3a43bf46d9d..d5494c7cb25 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/AxImporterTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/AxImporterTests.cs @@ -20,4 +20,3 @@ public void Constructor_ShouldThrowNotImplementedException() .WithMessage(SR.NotImplementedByDesign); } } - diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/BaseContextMenuStripTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/BaseContextMenuStripTests.cs index 279de7326d6..41998f5ca30 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/BaseContextMenuStripTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/BaseContextMenuStripTests.cs @@ -30,6 +30,6 @@ public void RefreshItems_SetsFontFromIUIService() foreach (var item in contextMenuStrip.Items.OfType()) { item.Font.Should().Be(expectedFont); - } + } } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/CollectionEditVerbManagerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/CollectionEditVerbManagerTests.cs index 4565f095fff..6e17148c11c 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/CollectionEditVerbManagerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/CollectionEditVerbManagerTests.cs @@ -35,4 +35,3 @@ public void CollectionEditVerbManager_EditItemsVerb_ReturnExpectedValue(string? editor.EditItemsVerb.CommandID.Should().Be(new CommandID(new Guid("74d21313-2aee-11d1-8bfb-00a0c90f26f7"), 8192)); } } - diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignBindingTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignBindingTests.cs index a64e263d8d4..2205330f9a4 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignBindingTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignBindingTests.cs @@ -30,14 +30,14 @@ public void Constructor_InitializesProperties() [Fact] public void IsNull_ReturnsTrueWhenDataSourceIsNull() { - DesignBinding binding = new (null, "TestMember"); + DesignBinding binding = new(null, "TestMember"); binding.IsNull.Should().BeTrue(); } [Fact] public void IsNull_ReturnsFalseWhenDataSourceIsNotNull() { - DesignBinding binding = new (new object(), "TestMember"); + DesignBinding binding = new(new object(), "TestMember"); binding.IsNull.Should().BeFalse(); } @@ -54,7 +54,7 @@ public void IsNull_ReturnsFalseWhenDataSourceIsNotNull() [MemberData(nameof(DataFieldTestData))] public void DataField_ReturnsExpected(string dataMember, string expectedField) { - DesignBinding binding = new (new object(), dataMember); + DesignBinding binding = new(new object(), dataMember); binding.DataField.Should().Be(expectedField); } @@ -63,7 +63,7 @@ public void Equals_ReturnsTrueForMatchingDataSourceAndDataMember() { object dataSource = new(); string dataMember = "TestMember"; - DesignBinding binding = new (dataSource, dataMember); + DesignBinding binding = new(dataSource, dataMember); binding.Equals(dataSource, dataMember).Should().BeTrue(); } @@ -72,7 +72,7 @@ public void Equals_ReturnsFalseForNonMatchingDataSource() { object dataSource = new(); string dataMember = "TestMember"; - DesignBinding binding = new (dataSource, dataMember); + DesignBinding binding = new(dataSource, dataMember); binding.Equals(new object(), dataMember).Should().BeFalse(); } @@ -81,7 +81,7 @@ public void Equals_ReturnsFalseForNonMatchingDataMember() { object dataSource = new(); string dataMember = "TestMember"; - DesignBinding binding = new (dataSource, dataMember); + DesignBinding binding = new(dataSource, dataMember); binding.Equals(dataSource, "DifferentMember").Should().BeFalse(); } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignerExtendersTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignerExtendersTests.cs index 7663d52b158..5593d7d2ad9 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignerExtendersTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignerExtendersTests.cs @@ -18,7 +18,7 @@ public void Dispose_RemovesExtenderProviders() DesignerExtenders designerExtenders = new(extenderServiceMock.Object); IExtenderProvider[] providers = designerExtenders.TestAccessor().Dynamic._providers; - IExtenderProviderService extenderService= designerExtenders.TestAccessor().Dynamic._extenderService; + IExtenderProviderService extenderService = designerExtenders.TestAccessor().Dynamic._extenderService; providers.Should().NotBeNull(); extenderService.Should().NotBeNull(); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FormatStringDialogTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FormatStringDialogTests.cs index b6a1b9ffd99..daf36028d06 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FormatStringDialogTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FormatStringDialogTests.cs @@ -23,7 +23,7 @@ public void Ctor_WithContext_DoesNotThrow() { Action action = () => { - FormatStringDialog dialog = new (_context.Object); + FormatStringDialog dialog = new(_context.Object); dialog.Dispose(); }; @@ -85,7 +85,7 @@ public void FormatControlFinishedLoading_AdjustsButtonPositionsCorrectly() int okButtonLeftOriginalState = okButtonField.Left; int cancelButtonLeftOriginalState = cancelButtonField.Left; - int GetRightSideOffset(Control ctl) + static int GetRightSideOffset(Control ctl) { int result = ctl.Width; Control? control = ctl; diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/GroupedContextMenuStripTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/GroupedContextMenuStripTests.cs index 2f2e004d26b..72bd973b80f 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/GroupedContextMenuStripTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/GroupedContextMenuStripTests.cs @@ -1,4 +1,7 @@ -namespace System.Windows.Forms.Design.Tests; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms.Design.Tests; public class GroupedContextMenuStripTests { @@ -42,4 +45,3 @@ public void Populate_WhenInitializedWithGroups_ItemsCountIsNotZeroAndHaveSeparat groupedContextMenuStrip.Items[1].Should().BeOfType(); } } - diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ListBoxDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ListBoxDesignerTests.cs index d4e28b304f9..08e260e2911 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ListBoxDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ListBoxDesignerTests.cs @@ -42,7 +42,7 @@ public void IntegralHeight_WhenDockStyleIsFillLeftOrRight_ShouldSetShadowPropert designer.IntegralHeight.Should().BeTrue(); - DockStyle dockStyle= (DockStyle)value[0]; + DockStyle dockStyle = (DockStyle)value[0]; bool integralHeight = (bool)value[1]; listBox.Dock = dockStyle; designer.IntegralHeight = integralHeight; diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskDescriptorComparerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskDescriptorComparerTests.cs index 65602f69433..c01287c057c 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskDescriptorComparerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskDescriptorComparerTests.cs @@ -48,7 +48,7 @@ internal void Compare_ShouldSortCorrectlyAccordingToSortTypeAndOrder(MaskDescrip [WinFormsTheory] [InlineData("Name", "Sample", typeof(int), "NameA", "SampleA", typeof(int), true)] - [InlineData("NameA", "SampleA", typeof(int), "NameB", "SampleB", typeof(string), false)] + [InlineData("NameA", "SampleA", typeof(int), "NameB", "SampleB", typeof(string), false)] public void GetHashCode_TestCases(string nameA, string sampleA, Type typeA, string nameB, string sampleB, Type typeB, bool expectSameHashCode) { TestMaskDescriptor maskDescriptorA = new(nameA, sampleA, typeA); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorDropDownTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorDropDownTests.cs index 061152ec707..0a932ece6e8 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorDropDownTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorDropDownTests.cs @@ -34,7 +34,7 @@ public void ProcessDialogKey_SetsCancel_WhenEscapePressed() using MaskedTextBox maskedTextBox = new(); using MaskedTextBoxTextEditorDropDown dropDown = new(maskedTextBox); bool processDialogKey = dropDown.TestAccessor().Dynamic.ProcessDialogKey(Keys.Escape); - bool cancel= dropDown.TestAccessor().Dynamic._cancel; + bool cancel = dropDown.TestAccessor().Dynamic._cancel; cancel.Should().BeTrue(); processDialogKey.Should().BeFalse(); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/PictureBoxActionListTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/PictureBoxActionListTests.cs index d2dc6419fd1..00ed840fc65 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/PictureBoxActionListTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/PictureBoxActionListTests.cs @@ -53,4 +53,3 @@ public void GetSortedActionItems_ShouldReturnCorrectItems() propertyItem.MemberName.Should().Be("SizeMode"); } } - diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/TabControlDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/TabControlDesignerTests.cs index ded4a975495..62edc7f0888 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/TabControlDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/TabControlDesignerTests.cs @@ -9,172 +9,172 @@ namespace System.Windows.Forms.Design.Tests; - public class TabControlDesignerTests +public class TabControlDesignerTests +{ + private (TabControlDesigner designer, TabControl tabControl) CreateInitializedDesignerWithServiceProvider(out Mock serviceProvider, out Mock designerHost) { - private (TabControlDesigner designer, TabControl tabControl) CreateInitializedDesignerWithServiceProvider(out Mock serviceProvider, out Mock designerHost) - { - TabControl tabControl = new(); - TabControlDesigner designer = new(); - serviceProvider = new(); - designerHost = new(); - serviceProvider.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(designerHost.Object); - designer.Initialize(tabControl); - return (designer, tabControl); - } + TabControl tabControl = new(); + TabControlDesigner designer = new(); + serviceProvider = new(); + designerHost = new(); + serviceProvider.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(designerHost.Object); + designer.Initialize(tabControl); + return (designer, tabControl); + } - private (TabControlDesigner designer, TabControl tabControl, TabPage tabPage) CreateDesignerWithMockedHost() - { - TabControlDesigner designer = new(); - TabControl tabControl = new(); - TabPage tabPage = new(); - Mock serviceProvider = new(); - Mock designerHost = new(); - serviceProvider.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(designerHost.Object); - designerHost.Setup(h => h.CreateComponent(typeof(TabPage))).Returns(tabPage); - designer.Initialize(tabControl); - return (designer, tabControl, tabPage); - } + private (TabControlDesigner designer, TabControl tabControl, TabPage tabPage) CreateDesignerWithMockedHost() + { + TabControlDesigner designer = new(); + TabControl tabControl = new(); + TabPage tabPage = new(); + Mock serviceProvider = new(); + Mock designerHost = new(); + serviceProvider.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(designerHost.Object); + designerHost.Setup(h => h.CreateComponent(typeof(TabPage))).Returns(tabPage); + designer.Initialize(tabControl); + return (designer, tabControl, tabPage); + } - [Fact] - public void InitializeNewComponent_ShouldAddTabPageToTabControl() + [Fact] + public void InitializeNewComponent_ShouldAddTabPageToTabControl() + { + var (designer, tabControl) = CreateInitializedDesignerWithServiceProvider(out _, out var designerHost); + using (designer) + using (tabControl) { - var (designer, tabControl) = CreateInitializedDesignerWithServiceProvider(out _, out var designerHost); - using (designer) - using (tabControl) - { - using TabPage tabPage = new(); - tabControl.TabPages.Add(tabPage); - designerHost.Setup(h => h.CreateComponent(typeof(TabPage))).Returns(tabPage); + using TabPage tabPage = new(); + tabControl.TabPages.Add(tabPage); + designerHost.Setup(h => h.CreateComponent(typeof(TabPage))).Returns(tabPage); - designer.InitializeNewComponent(new Hashtable()); + designer.InitializeNewComponent(new Hashtable()); - tabControl.TabPages.Count.Should().Be(1); - } + tabControl.TabPages.Count.Should().Be(1); } + } - [Theory] - [InlineData(typeof(TabPage), true)] - [InlineData(typeof(Button), false)] - public void CanParent_ReturnsExpectedResult(Type controlType, bool expected) + [Theory] + [InlineData(typeof(TabPage), true)] + [InlineData(typeof(Button), false)] + public void CanParent_ReturnsExpectedResult(Type controlType, bool expected) + { + var (designer, tabControl) = CreateInitializedDesignerWithServiceProvider(out _, out _); + using (designer) + using (tabControl) { - var (designer, tabControl) = CreateInitializedDesignerWithServiceProvider(out _, out _); - using (designer) - using (tabControl) - { - designer.Initialize(tabControl); - Control? control = Activator.CreateInstance(controlType) as Control; + designer.Initialize(tabControl); + Control? control = Activator.CreateInstance(controlType) as Control; - if (control is TabPage tabPage && expected == false) - { - tabControl.TabPages.Add(tabPage); - } + if (control is TabPage tabPage && !expected) + { + tabControl.TabPages.Add(tabPage); + } - bool result = designer.CanParent(control); + bool result = designer.CanParent(control); - result.Should().Be(expected); - } + result.Should().Be(expected); } + } - [Fact] - public void Verbs_ContainsAddAndRemoveVerbs() + [Fact] + public void Verbs_ContainsAddAndRemoveVerbs() + { + var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); + using (designer) + using (tabControl) + using (tabPage) { - var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); - using (designer) - using (tabControl) - using (tabPage) - { - var verbs = designer.Verbs.Cast(); + var verbs = designer.Verbs.Cast(); - verbs.Should().Contain(v => v.Text == SR.TabControlAdd); - verbs.Should().Contain(v => v.Text == SR.TabControlRemove); - } + verbs.Should().Contain(v => v.Text == SR.TabControlAdd); + verbs.Should().Contain(v => v.Text == SR.TabControlRemove); } + } - [Fact] - public void Verbs_RemoveVerbEnabledWhenTabPagesExist() + [Fact] + public void Verbs_RemoveVerbEnabledWhenTabPagesExist() + { + var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); + using (designer) + using (tabControl) + using (tabPage) { - var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); - using (designer) - using (tabControl) - using (tabPage) - { - tabControl.TabPages.Add(tabPage); + tabControl.TabPages.Add(tabPage); - var verbs = designer.Verbs; - var removeVerb = verbs.Cast().FirstOrDefault(v => v.Text == SR.TabControlRemove); + var verbs = designer.Verbs; + var removeVerb = verbs.Cast().FirstOrDefault(v => v.Text == SR.TabControlRemove); - removeVerb.Should().NotBeNull(); - removeVerb.Should().BeOfType().Which.Enabled.Should().BeTrue(); - } + removeVerb.Should().NotBeNull(); + removeVerb.Should().BeOfType().Which.Enabled.Should().BeTrue(); } + } - [Fact] - public void Verbs_RemoveVerbDisabledWhenNoTabPagesExist() + [Fact] + public void Verbs_RemoveVerbDisabledWhenNoTabPagesExist() + { + var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); + using (designer) + using (tabControl) + using (tabPage) { - var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); - using (designer) - using (tabControl) - using (tabPage) - { - var verbs = designer.Verbs; - var removeVerb = verbs.Cast().FirstOrDefault(v => v.Text == SR.TabControlRemove); + var verbs = designer.Verbs; + var removeVerb = verbs.Cast().FirstOrDefault(v => v.Text == SR.TabControlRemove); - removeVerb.Should().NotBeNull(); - removeVerb.Should().BeOfType().Which.Enabled.Should().BeFalse(); - } + removeVerb.Should().NotBeNull(); + removeVerb.Should().BeOfType().Which.Enabled.Should().BeFalse(); } + } - [Fact] - public void ParticipatesWithSnapLines_ReturnsFalseWhenNotForwardOnDrag() + [Fact] + public void ParticipatesWithSnapLines_ReturnsFalseWhenNotForwardOnDrag() + { + var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); + using (designer) + using (tabControl) + using (tabPage) { - var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); - using (designer) - using (tabControl) - using (tabPage) - { - bool result = designer.ParticipatesWithSnapLines; + bool result = designer.ParticipatesWithSnapLines; - result.Should().BeFalse(); - } + result.Should().BeFalse(); } + } - [Fact] - public void ParticipatesWithSnapLines_ReturnsTrueWhenForwardOnDragAndPageDesignerParticipates() + [Fact] + public void ParticipatesWithSnapLines_ReturnsTrueWhenForwardOnDragAndPageDesignerParticipates() + { + var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); + using (designer) + using (tabControl) + using (tabPage) { - var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); - using (designer) - using (tabControl) - using (tabPage) - { - tabControl.TabPages.Add(tabPage); + tabControl.TabPages.Add(tabPage); - Mock pageDesignerMock = new(MockBehavior.Strict); - pageDesignerMock.Setup(p => p.ParticipatesWithSnapLines).Returns(true); + Mock pageDesignerMock = new(MockBehavior.Strict); + pageDesignerMock.Setup(p => p.ParticipatesWithSnapLines).Returns(true); - designer.TestAccessor().Dynamic._forwardOnDrag = true; + designer.TestAccessor().Dynamic._forwardOnDrag = true; - bool result = designer.ParticipatesWithSnapLines; + bool result = designer.ParticipatesWithSnapLines; - result.Should().BeTrue(); - } + result.Should().BeTrue(); } + } - [Fact] - public void ParticipatesWithSnapLines_ReturnsTrueWhenForwardOnDragAndPageDesignerDoesNotParticipate() + [Fact] + public void ParticipatesWithSnapLines_ReturnsTrueWhenForwardOnDragAndPageDesignerDoesNotParticipate() + { + var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); + using (designer) + using (tabControl) + using (tabPage) { - var (designer, tabControl, tabPage) = CreateDesignerWithMockedHost(); - using (designer) - using (tabControl) - using (tabPage) - { - Mock pageDesignerMock = new(MockBehavior.Strict); - pageDesignerMock.Setup(p => p.ParticipatesWithSnapLines).Returns(false); + Mock pageDesignerMock = new(MockBehavior.Strict); + pageDesignerMock.Setup(p => p.ParticipatesWithSnapLines).Returns(false); - designer.TestAccessor().Dynamic._forwardOnDrag = true; + designer.TestAccessor().Dynamic._forwardOnDrag = true; - bool result = designer.ParticipatesWithSnapLines; + bool result = designer.ParticipatesWithSnapLines; - result.Should().BeTrue(); - } + result.Should().BeTrue(); } } +} diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDesignerTests.cs index e83bbe2bff6..7dd652c5164 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDesignerTests.cs @@ -60,7 +60,7 @@ public void ToolStripDesigner_InitialStateTest() Assert.Equal(-1, toolStripDesigner.IndexOfItemUnderMouseToDrag); Assert.Equal(-1, toolStripDesigner.IndexOfItemUnderMouseToDrag); Assert.Null(toolStripDesigner.InsertTransaction); - Assert.Equal(0, toolStripDesigner.Items.Count); + Assert.Empty(toolStripDesigner.Items); Assert.Null(toolStripDesigner.NewItemTransaction); Assert.NotNull(toolStripDesigner.SelectionService); Assert.True(toolStripDesigner.SerializePerformLayout); diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDropDownItemDesignerTest.cs b/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDropDownItemDesignerTest.cs index be8816ac49a..a50cac9353b 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDropDownItemDesignerTest.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripDropDownItemDesignerTest.cs @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. namespace System.Windows.Forms.Design.Tests; @@ -18,6 +17,6 @@ public void ToolStripDropDownItemDesignerTest_AssociatedComponentsTest() toolStripDropDown.DropDownItems.Add("123"); - Assert.Equal(1, toolStripDropDownItemDesigner.AssociatedComponents.Count); + Assert.Single(toolStripDropDownItemDesigner.AssociatedComponents); } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripMenuItemDesignerTest.cs b/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripMenuItemDesignerTest.cs index f0b82522ea7..546ed0d0f93 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripMenuItemDesignerTest.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/ToolStripMenuItemDesignerTest.cs @@ -23,7 +23,7 @@ public void ToolStripMenuItemDesignerTest_AssociatedComponentsTest() toolStripDropDown.DropDownItems.Add("123"); - Assert.Equal(1, toolStripMenuItemDesigner.AssociatedComponents.Count); + Assert.Single(toolStripMenuItemDesigner.AssociatedComponents); Assert.Null(toolStripMenuItemDesigner.Editor); Assert.Null(toolStripMenuItemDesigner.GetParentComponentProperty()); } diff --git a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.SetThreadDpiAwarenessContext.cs b/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.SetThreadDpiAwarenessContext.cs index 00301e084eb..38912c9b2a6 100644 --- a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.SetThreadDpiAwarenessContext.cs +++ b/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.SetThreadDpiAwarenessContext.cs @@ -18,7 +18,7 @@ public static DPI_AWARENESS_CONTEXT SetThreadDpiAwarenessContextInternal(DPI_AWA { if (dpiContext == DPI_AWARENESS_CONTEXT.UNSPECIFIED_DPI_AWARENESS_CONTEXT) { - throw new ArgumentException(nameof(dpiContext), dpiContext.ToString()); + throw new ArgumentException(dpiContext.ToString(), nameof(dpiContext)); } return SetThreadDpiAwarenessContext(dpiContext); diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/Metafiles/Validators/RepeatValidatorTests.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/Metafiles/Validators/RepeatValidatorTests.cs index a673d16c54d..834bf11d157 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/Metafiles/Validators/RepeatValidatorTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/Metafiles/Validators/RepeatValidatorTests.cs @@ -13,7 +13,7 @@ public unsafe void RepeatValidator_Validate_complete_should_be_expected() Mock emfValidator = new(); RepeatValidator repeatValidator = new(emfValidator.Object, 2); - EmfRecord emfRecord = new(); + EmfRecord emfRecord = default; repeatValidator.Validate(ref emfRecord, state: null!, out bool complete); Assert.False(complete); @@ -31,7 +31,7 @@ public unsafe void RepeatValidator_Validate_should_throw_IOE_if_count_not_positi Mock emfValidator = new(); RepeatValidator repeatValidator = new(emfValidator.Object, count); - EmfRecord emfRecord = new(); + EmfRecord emfRecord = default; Assert.Throws(() => repeatValidator.Validate(ref emfRecord, state: null!, out bool complete)); } diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/PathLengthTests.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/PathLengthTests.cs index 3e0c5c787d6..782fce7186e 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/PathLengthTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities.Tests/PathLengthTests.cs @@ -32,11 +32,11 @@ public void RepoPathsLeaveRoomForRoot() currentPath, (ref FileSystemEntry entry) => entry.ToFullPath(), new EnumerationOptions() { RecurseSubdirectories = true }) - { - ShouldIncludePredicate = (ref FileSystemEntry entry) => - // Directory doesn't contain a trailing slash - entry.Directory.Length + entry.FileName.Length > maxLength - }; + { + ShouldIncludePredicate = (ref FileSystemEntry entry) => + // Directory doesn't contain a trailing slash + entry.Directory.Length + entry.FileName.Length > maxLength + }; enumerable.Should().BeEmpty(); } diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs index 1226b4e85be..b6f57df563d 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs @@ -32,4 +32,3 @@ internal void LogEmfValidateToFile(EmfScope emf, string methodName, params objec File.AppendAllText(@$"c:\temp\{methodName}.md", sb.ToString()); } } - diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/RecordTypes/EMRPOLYPOLY16.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/RecordTypes/EMRPOLYPOLY16.cs index d2381c56b13..6bb0fdba6c1 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/RecordTypes/EMRPOLYPOLY16.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/RecordTypes/EMRPOLYPOLY16.cs @@ -57,7 +57,7 @@ public unsafe ReadOnlySpan aPolyCounts { get { - fixed(uint* c = &_aPolyCounts) + fixed (uint* c = &_aPolyCounts) { return new(c, checked((int)nPolys)); } diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/Validators/EmfValidator.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/Validators/EmfValidator.cs index 61f5f948f91..9833d0ab51c 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/Validators/EmfValidator.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/Validators/EmfValidator.cs @@ -64,54 +64,54 @@ internal static void Validate( private static bool IsRenderingRecord(ENHANCED_METAFILE_RECORD_TYPE recordType) => recordType switch { - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIER => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIERTO => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINETO => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYLINE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYGON => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_SETPIXELV => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_ANGLEARC => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_ELLIPSE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_RECTANGLE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_ROUNDRECT => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_ARC => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_CHORD => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_PIE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_EXTFLOODFILL => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_LINETO => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_ARCTO => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYDRAW => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_CLOSEFIGURE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_FILLPATH => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_STROKEANDFILLPATH => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_STROKEPATH => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_FILLRGN => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_FRAMERGN => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_INVERTRGN => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_PAINTRGN => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_BITBLT => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHBLT => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_MASKBLT => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_PLGBLT => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_SETDIBITSTODEVICE => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_EXTTEXTOUTA => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_EXTTEXTOUTW => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIER16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINE16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIERTO16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINETO16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYLINE16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYGON16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYDRAW16 => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYTEXTOUTA => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYTEXTOUTW => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_TRANSPARENTBLT => true, - ENHANCED_METAFILE_RECORD_TYPE.EMR_GRADIENTFILL => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIER => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIERTO => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINETO => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYLINE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYGON => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_SETPIXELV => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_ANGLEARC => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_ELLIPSE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_RECTANGLE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_ROUNDRECT => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_ARC => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_CHORD => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_PIE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_EXTFLOODFILL => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_LINETO => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_ARCTO => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYDRAW => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_CLOSEFIGURE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_FILLPATH => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_STROKEANDFILLPATH => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_STROKEPATH => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_FILLRGN => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_FRAMERGN => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_INVERTRGN => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_PAINTRGN => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_BITBLT => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHBLT => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_MASKBLT => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_PLGBLT => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_SETDIBITSTODEVICE => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_EXTTEXTOUTA => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_EXTTEXTOUTW => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIER16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINE16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYBEZIERTO16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYLINETO16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYLINE16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYGON16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYDRAW16 => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYTEXTOUTA => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYTEXTOUTW => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_TRANSPARENTBLT => true, + ENHANCED_METAFILE_RECORD_TYPE.EMR_GRADIENTFILL => true, _ => false }; } diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/ModuleInitializer.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/ModuleInitializer.cs index bd13bfb703c..2b071103d75 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/ModuleInitializer.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/ModuleInitializer.cs @@ -5,7 +5,7 @@ namespace System; -internal class ModuleInitializer +internal static class ModuleInitializer { [ModuleInitializer] [SuppressMessage("Usage", "CA2255:The 'ModuleInitializer' attribute should not be used in libraries", Justification = "Intentional use of module initializer to register trace listener.")] diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.Windows.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.Windows.cs index 7ab9464f037..75dfd755092 100644 --- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.Windows.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/PlatformDetection.Windows.cs @@ -110,10 +110,10 @@ public static bool IsInAppContainer // APPMODEL_ERROR_NO_APPLICATION 15703 => 0, // ERROR_SUCCESS - 0 or 122 => 1,// Success is actually insufficent buffer as we're really only looking for - // not NO_APPLICATION and we're not actually giving a buffer here. The - // API will always return NO_APPLICATION if we're not running under a - // WinRT process, no matter what size the buffer is. + 0 or 122 => 1, // Success is actually insufficent buffer as we're really only looking for + // not NO_APPLICATION and we're not actually giving a buffer here. The + // API will always return NO_APPLICATION if we're not running under a + // WinRT process, no matter what size the buffer is. _ => throw new InvalidOperationException($"Failed to get AppId, result was {result}."), }; } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs index 74247e36608..66b90d655e8 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/MCGRIDINFOTests.cs @@ -38,7 +38,7 @@ public unsafe void MCGRIDINFO_x32_ensure_layout() return; } - MCGRIDINFO sut = new(); + MCGRIDINFO sut = default; byte* addr = (byte*)&sut; Assert.Equal(0, (byte*)&sut.cbSize - addr); // 4, UINT @@ -107,7 +107,7 @@ public unsafe void MCGRIDINFO_x64_ensure_layout() return; } - MCGRIDINFO sut = new(); + MCGRIDINFO sut = default; byte* addr = (byte*)&sut; Assert.Equal(0, (byte*)&sut.cbSize - addr); // 4, UINT diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs index 01a53aa27b0..a1128048e06 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGIconUnionTests.cs @@ -26,7 +26,7 @@ public unsafe void TASKDIALOGCONFIGIconUnion_x32_ensure_layout() return; } - TASKDIALOGCONFIG_MainIcon icon = new(); + TASKDIALOGCONFIG_MainIcon icon = default; byte* addr = (byte*)&icon; Assert.Equal(0, (byte*)&icon.hMainIcon - addr); // 4, HICON @@ -52,7 +52,7 @@ public unsafe void TASKDIALOGCONFIGIconUnion_x64_ensure_layout() return; } - TASKDIALOGCONFIG_MainIcon icon = new(); + TASKDIALOGCONFIG_MainIcon icon = default; byte* addr = (byte*)&icon; Assert.Equal(0, (byte*)&icon.hMainIcon - addr); // 8, HICON diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs index 7f40e4c623d..f0b4c397fe9 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOGCONFIGTests.cs @@ -26,7 +26,7 @@ public unsafe void TASKDIALOGCONFIG_x32_ensure_layout() return; } - TASKDIALOGCONFIG sut = new(); + TASKDIALOGCONFIG sut = default; byte* addr = (byte*)&sut; fixed (void* mainIconPtr = &sut.mainIcon) fixed (void* footerIconPtr = &sut.footerIcon) @@ -37,7 +37,7 @@ public unsafe void TASKDIALOGCONFIG_x32_ensure_layout() Assert.Equal(12, (byte*)&sut.dwFlags - addr); // 4, TASKDIALOG_FLAGS Assert.Equal(16, (byte*)&sut.dwCommonButtons - addr); // 4, TASKDIALOG_COMMON_BUTTON_FLAGS Assert.Equal(20, (byte*)&sut.pszWindowTitle - addr); // 4, PCWSTR - Assert.Equal(24, (byte*)mainIconPtr - addr); // 4, union { HICON; PCWSTR; } + Assert.Equal(24, (byte*)mainIconPtr - addr); // 4, union { HICON; PCWSTR; } Assert.Equal(28, (byte*)&sut.pszMainInstruction - addr); // 4, PCWSTR Assert.Equal(32, (byte*)&sut.pszContent - addr); // 4, PCWSTR Assert.Equal(36, (byte*)&sut.cButtons - addr); // 4, UINT @@ -77,7 +77,7 @@ public unsafe void TASKDIALOGCONFIG_x64_ensure_layout() return; } - TASKDIALOGCONFIG sut = new(); + TASKDIALOGCONFIG sut = default; byte* addr = (byte*)&sut; fixed (void* mainIconPtr = &sut.mainIcon) fixed (void* footerIconPtr = &sut.footerIcon) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs index af87216de7e..d85a394a923 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/ComCtl32/TASKDIALOG_BUTTONTests.cs @@ -26,7 +26,7 @@ public unsafe void TASKDIALOG_BUTTON_x32_ensure_layout() return; } - TASKDIALOG_BUTTON sut = new(); + TASKDIALOG_BUTTON sut = default; byte* addr = (byte*)&sut; Assert.Equal(0, (byte*)&sut.nButtonID - addr); // 4, int @@ -52,7 +52,7 @@ public unsafe void TASKDIALOG_BUTTON_x64_ensure_layout() return; } - TASKDIALOG_BUTTON sut = new(); + TASKDIALOG_BUTTON sut = default; byte* addr = (byte*)&sut; Assert.Equal(0, (byte*)&sut.nButtonID - addr); // 4, int diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs index c8c7b384566..ca53b5dc23b 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Comdlg32/PRINTDLGWTests.cs @@ -26,7 +26,7 @@ public unsafe void PRINTDLGW_32_ensure_layout() return; } - PRINTDLGW_32 sut = new(); + PRINTDLGW_32 sut = default; byte* addr = (byte*)&sut; Assert.Equal(0, (byte*)&sut.lStructSize - addr); // 4, DWORD @@ -69,7 +69,7 @@ public unsafe void PRINTDLGW_64_ensure_layout() return; } - PRINTDLGW_64 sut = new(); + PRINTDLGW_64 sut = default; byte* addr = (byte*)&sut; Assert.Equal(0, (byte*)&sut.lStructSize - addr); // 8, DWORD diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/FILETIMETests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/FILETIMETests.cs index d966efc04da..7dcfbb0d752 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/FILETIMETests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/FILETIMETests.cs @@ -18,7 +18,7 @@ public unsafe void FILETIME_Sizeof_Invoke_ReturnsExpected() [Fact] public void FILETIME_Ctor_Default() { - FILETIME ft = new(); + FILETIME ft = default; Assert.Equal(0u, ft.dwLowDateTime); Assert.Equal(0u, ft.dwHighDateTime); } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/SYSTEMTIMETests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/SYSTEMTIMETests.cs index 9e764f2be75..1c8c329c4cd 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/SYSTEMTIMETests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Kernel32/SYSTEMTIMETests.cs @@ -17,7 +17,7 @@ public unsafe void SYSTEMTIME_Sizeof_ReturnsExpected() [Fact] public void SYSTEMTIME_Ctor_Default() { - SYSTEMTIME st = new(); + SYSTEMTIME st = default; Assert.Equal(0, st.wYear); Assert.Equal(0, st.wMonth); @@ -76,7 +76,7 @@ public void SYSTEMTIME_CastToDateTime_ThrowsException_IfArgumentsAreIncorrect() [Fact] public void SYSTEMTIME_CastToDateTime_ReturnsMinValue_IfValueIsDefault() { - SYSTEMTIME st = new(); + SYSTEMTIME st = default; DateTime dt; using (new NoAssertContext()) diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CADWORDTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CADWORDTests.cs index 6aa04748197..31c9a984ad4 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CADWORDTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CADWORDTests.cs @@ -14,7 +14,7 @@ public void CADWORD_ConvertAndFree_SingleItem() CADWORD ca = CreateIntVector(2020); uint[] values = ca.ConvertAndFree(); - Assert.Equal(1, values.Length); + Assert.Single(values); Assert.Equal(2020u, values[0]); } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CALPOLESTRTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CALPOLESTRTests.cs index 5d5abf2a5ec..af64ca8750f 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CALPOLESTRTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/CALPOLESTRTests.cs @@ -14,7 +14,7 @@ public void CALPOLESTR_ConvertAndFree_SingleItem() CALPOLESTR ca = CreateStringVector("Swizzle"); string?[] values = ca.ConvertAndFree(); - Assert.Equal(1, values.Length); + Assert.Single(values); Assert.Equal("Swizzle", values[0]); } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs index d74501ae288..80368a8c9b7 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Ole32/IPictureTests.cs @@ -52,7 +52,7 @@ public void GetIPictureDispFromImage() using Bitmap bitmap = icon.ToBitmap(); using var picture = IPictureDisp.CreateFromImage(bitmap); Assert.False(picture.IsNull); - using VARIANT variant = new(); + using VARIANT variant = default; IDispatch* dispatch = (IDispatch*)picture.Value; dispatch->TryGetProperty(PInvokeCore.DISPID_PICT_TYPE, &variant).ThrowOnFailure(); diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/DECIMALTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/DECIMALTests.cs index ecfbfffe195..2e0a29f9d4e 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/DECIMALTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/DECIMALTests.cs @@ -18,7 +18,7 @@ public unsafe void DECIMAL_Sizeof_Invoke_ReturnsExpected() [Fact] public void DECIMAL_ToDecimal_InvokeEmpty_ReturnsExpected() { - DECIMAL dec = new(); + DECIMAL dec = default; Assert.Equal(0m, dec.ToDecimal()); } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs index 2c2fad11448..2dc5baab52b 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/ITypeInfoTests.cs @@ -70,8 +70,8 @@ public unsafe void ITypeInfo_GetDllEntry_Invoke_Success() HRESULT hr = typeInfo.Value->GetDllEntry(6, INVOKEKIND.INVOKE_FUNC, &dllName, &name, &wOrdinal); Assert.Equal(HRESULT.TYPE_E_BADMODULEKIND, hr); - Assert.True(dllName.Length == 0); - Assert.True(name.Length == 0); + Assert.Equal(0, dllName.Length); + Assert.Equal(0, name.Length); Assert.Equal(0u, wOrdinal); } @@ -90,9 +90,9 @@ public unsafe void ITypeInfo_GetDocumentation_Invoke_Success() using BSTR helpFile = new("HelpFile"); typeInfo.Value->GetDocumentation(4, &name, &docString, &dwHelpContext, &helpFile); Assert.Equal("Width", name.ToString()); - Assert.True(docString.Length == 0); + Assert.Equal(0, docString.Length); Assert.Equal(0u, dwHelpContext); - Assert.True(helpFile.Length == 0); + Assert.Equal(0, helpFile.Length); } [StaFact] @@ -178,7 +178,7 @@ public unsafe void ITypeInfo_GetMops_Invoke_Success() using BSTR mops = new("Mops"); typeInfo.Value->GetMops(4, &mops); - Assert.True(mops.Length == 0); + Assert.Equal(0, mops.Length); } [StaFact] @@ -301,7 +301,7 @@ public unsafe void ITypeInfo_GetVarDesc_Invoke_Success() typeInfo.Value->GetVarDesc(3, &pVarDesc); Assert.Equal(4, pVarDesc->memid); Assert.True(pVarDesc->lpstrSchema.IsNull); - Assert.True(pVarDesc->Anonymous.lpvarValue is null); + Assert.True(pVarDesc->Anonymous.lpvarValue is null); Assert.Equal(VARENUM.VT_USERDEFINED, pVarDesc->elemdescVar.tdesc.vt); Assert.False(pVarDesc->elemdescVar.tdesc.Anonymous.lpadesc is null); Assert.True(pVarDesc->elemdescVar.Anonymous.paramdesc.pparamdescex is null); diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/SAFEARRAYTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/SAFEARRAYTests.cs index c2fac1f6043..ee995cd53e9 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/SAFEARRAYTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/SAFEARRAYTests.cs @@ -56,8 +56,9 @@ public void SAFEARRAY_CreateSingleDimension_GetProperties_Success(ushort vt, ush cElements = 10, lLbound = 1 }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate((VARENUM)vt, 1, &saBound); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { @@ -65,7 +66,7 @@ public void SAFEARRAY_CreateSingleDimension_GetProperties_Success(ushort vt, ush Assert.Equal((ADVANCED_FEATURE_FLAGS)expectedFeatures, psa->fFeatures); Assert.Equal(expectedCbElements, psa->cbElements); Assert.Equal(0u, psa->cLocks); - Assert.True(psa->pvData != null); + NativeAssert.NotNull(psa->pvData); Assert.Equal(10u, psa->rgsabound.AsSpan(1)[0].cElements); Assert.Equal(1, psa->rgsabound.AsSpan(1)[0].lLbound); @@ -93,7 +94,7 @@ public void SAFEARRAY_CreateSingleDimensionRECORD_GetProperties_Success() using ComScope recordInfo = new(new CustomRecordInfo().GetComInterface()); SAFEARRAY* psa = PInvokeCore.SafeArrayCreateEx(VT_RECORD, 1, &saBound, recordInfo); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { @@ -101,7 +102,7 @@ public void SAFEARRAY_CreateSingleDimensionRECORD_GetProperties_Success() Assert.Equal(FADF_RECORD, psa->fFeatures); Assert.Equal((uint)sizeof(int), psa->cbElements); Assert.Equal(0u, psa->cLocks); - Assert.True(psa->pvData != null); + NativeAssert.NotNull(psa->pvData); Assert.Equal(10u, psa->rgsabound.AsSpan(1)[0].cElements); Assert.Equal(1, psa->rgsabound.AsSpan(1)[0].lLbound); @@ -180,8 +181,9 @@ public void SAFEARRAY_CreateMultipleDimensions_GetProperties_Success(ushort vt, cElements = 20, lLbound = 0 }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate((VARENUM)vt, 2, saBounds); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { @@ -189,7 +191,7 @@ public void SAFEARRAY_CreateMultipleDimensions_GetProperties_Success(ushort vt, Assert.Equal((ADVANCED_FEATURE_FLAGS)expectedFeatures, psa->fFeatures); Assert.Equal(expectedCbElements, psa->cbElements); Assert.Equal(0u, psa->cLocks); - Assert.True(psa->pvData != null); + NativeAssert.NotNull(psa->pvData); Assert.Equal(20u, psa->rgsabound.AsSpan(1)[0].cElements); Assert.Equal(0, psa->rgsabound.AsSpan(1)[0].lLbound); Assert.Equal(10u, ((SAFEARRAYBOUND*)&psa->rgsabound)[1].cElements); @@ -215,8 +217,9 @@ public void SAFEARRAY_GetValue_InvokeSingleDimensional_ReturnsExpected() cElements = 10, lLbound = 0 }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate(VT_I4, 1, &saBound); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { @@ -261,8 +264,9 @@ public void SAFEARRAY_GetValue_InvokeSingleDimensionalNonZeroLowerBound_ReturnsE cElements = 10, lLbound = -5 }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate(VT_I4, 1, &saBound); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { @@ -308,13 +312,15 @@ public void SAFEARRAY_GetValue_InvokeMultiDimensional_ReturnsExpected() cElements = 10, lLbound = 0 }; + saBounds[1] = new SAFEARRAYBOUND { cElements = 20, lLbound = 0 }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate(VT_I4, 2, saBounds); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { @@ -360,13 +366,15 @@ public void SAFEARRAY_GetValue_InvokeMultiDimensionalNonZeroLowerBound_ReturnsEx cElements = 10, lLbound = -5 }; + saBounds[1] = new SAFEARRAYBOUND { cElements = 20, lLbound = -4 }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate(VT_I4, 2, saBounds); - Assert.True(psa != null); + NativeAssert.NotNull(psa); try { diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/VARIANTTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/VARIANTTests.cs index 9fd0f34611b..01294ac63e4 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/VARIANTTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/VARIANTTests.cs @@ -15,7 +15,7 @@ namespace System.Windows.Forms.Tests.Interop.Oleaut32; public unsafe class VARIANTTests { private static VARIANT Create(VARENUM type) - => new () { vt = type }; + => new() { vt = type }; private static VARIANT Create(VARENUM type, void* value) => new() @@ -716,7 +716,7 @@ public void VARIANT_ToObject_HRESULTBYREF_Success(nint data, int expected) [StaFact] public void VARIANT_ToObject_FILETIME_Success() { - using VARIANT variant = new(); + using VARIANT variant = default; DateTime dt = new(2020, 05, 13, 13, 3, 12); var ft = new FILETIME(dt); HRESULT hr = InitPropVariantFromFileTime(&ft, &variant); @@ -742,13 +742,13 @@ public void VARIANT_ToObject_InvalidFILETIME_ThrowsArgumentOutOfRangeException(i } }; - Assert.Throws("fileTime", () => variant.ToObject()); + Assert.Throws("fileTime", variant.ToObject); } [StaFact] public void VARIANT_ToObject_DateFromFILETIME_Success() { - using VARIANT variant = new(); + using VARIANT variant = default; DateTime dt = new DateTime(2020, 05, 13, 13, 3, 12, DateTimeKind.Utc).ToLocalTime(); var ft = new FILETIME(dt); HRESULT hr = InitVariantFromFileTime(&ft, &variant); @@ -1086,14 +1086,14 @@ public void VARIANT_ToObject_DecimalR8_ReturnsExpected(double r8, decimal expect public static IEnumerable Decimal_TestData() { - yield return new object[] { new DECIMAL(), 0.0m }; + yield return new object[] { default(DECIMAL), 0.0m }; } [StaTheory] [MemberData(nameof(Decimal_TestData))] public void VARIANT_ToObject_Decimal_ReturnsExpected(object d, decimal expected) { - VARIANT variant = new(); + VARIANT variant = default; *(DECIMAL*)(&variant) = (DECIMAL)d; variant.Anonymous.Anonymous.vt = VT_DECIMAL; AssertToObjectEqual(expected, variant); @@ -1112,7 +1112,7 @@ public void VARIANT_ToObject_DecimalBYREF_ReturnsExpected(object d, decimal expe public void VARIANT_ToObject_CLSID_ReturnsExpected() { var guid = Guid.NewGuid(); - using VARIANT variant = new(); + using VARIANT variant = default; HRESULT hr = InitPropVariantFromCLSID(&guid, &variant); Assert.Equal(HRESULT.S_OK, hr); Assert.Equal(VT_CLSID, variant.vt); @@ -1205,7 +1205,7 @@ public static IEnumerable VectorI1_TestData() [MemberData(nameof(VectorI1_TestData))] public void VARIANT_ToObject_VECTORI1_ReturnsExpected(sbyte[] result) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (sbyte* pResult = result) @@ -1242,7 +1242,7 @@ public static IEnumerable VectorUI1_TestData() [MemberData(nameof(VectorUI1_TestData))] public void VARIANT_ToObject_VECTORUI1_ReturnsExpected(byte[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (byte* pResult = result) { HRESULT hr = InitPropVariantFromBuffer(pResult, (uint)result.Length, &variant); @@ -1270,7 +1270,7 @@ public static IEnumerable VectorI2_TestData() [MemberData(nameof(VectorI2_TestData))] public void VARIANT_ToObject_VECTORI2_ReturnsExpected(short[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (short* pResult = result) { HRESULT hr = InitPropVariantFromInt16Vector(pResult, (uint)result.Length, &variant); @@ -1298,7 +1298,7 @@ public static IEnumerable VectorUI2_TestData() [MemberData(nameof(VectorUI2_TestData))] public void VARIANT_ToObject_VECTORUI2_ReturnsExpected(ushort[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (ushort* pResult = result) { HRESULT hr = InitPropVariantFromUInt16Vector(pResult, (uint)result.Length, &variant); @@ -1326,7 +1326,7 @@ public static IEnumerable VectorBOOL_TestData() [MemberData(nameof(VectorBOOL_TestData))] public void VARIANT_ToObject_VECTORBOOL_ReturnsExpected(object result, bool[] expected) { - using VARIANT variant = new(); + using VARIANT variant = default; BOOL[] boolResult = (BOOL[])result; fixed (BOOL* pResult = boolResult) { @@ -1355,7 +1355,7 @@ public static IEnumerable VectorI4_TestData() [MemberData(nameof(VectorI4_TestData))] public void VARIANT_ToObject_VECTORI4_ReturnsExpected(int[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (int* pResult = result) { HRESULT hr = InitPropVariantFromInt32Vector(pResult, (uint)result.Length, &variant); @@ -1383,7 +1383,7 @@ public static IEnumerable VectorUI4_TestData() [MemberData(nameof(VectorUI4_TestData))] public void VARIANT_ToObject_VECTORUI4_ReturnsExpected(uint[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (uint* pResult = result) { HRESULT hr = InitPropVariantFromUInt32Vector(pResult, (uint)result.Length, &variant); @@ -1411,7 +1411,7 @@ public static IEnumerable VectorINT_TestData() [MemberData(nameof(VectorINT_TestData))] public void VARIANT_ToObject_VECTORINT_ReturnsExpected(int[] result) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (int* pResult = result) @@ -1448,7 +1448,7 @@ public static IEnumerable VectorUINT_TestData() [MemberData(nameof(VectorUINT_TestData))] public void VARIANT_ToObject_VECTORUINT_ReturnsExpected(uint[] result) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (uint* pResult = result) @@ -1485,7 +1485,7 @@ public static IEnumerable VectorI8_TestData() [MemberData(nameof(VectorI8_TestData))] public void VARIANT_ToObject_VECTORI8_ReturnsExpected(long[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (long* pResult = result) { HRESULT hr = InitPropVariantFromInt64Vector(pResult, (uint)result.Length, &variant); @@ -1513,7 +1513,7 @@ public static IEnumerable VectorUI8_TestData() [MemberData(nameof(VectorUI8_TestData))] public void VARIANT_ToObject_VECTORUI8_ReturnsExpected(ulong[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (ulong* pResult = result) { HRESULT hr = InitPropVariantFromUInt64Vector(pResult, (uint)result.Length, &variant); @@ -1541,7 +1541,7 @@ public static IEnumerable VectorR4_TestData() [MemberData(nameof(VectorR4_TestData))] public void VARIANT_ToObject_VECTORR4_ReturnsExpected(float[] result) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (float* pResult = result) @@ -1578,7 +1578,7 @@ public static IEnumerable VectorR8_TestData() [MemberData(nameof(VectorR8_TestData))] public void VARIANT_ToObject_VECTORR8_ReturnsExpected(double[] result) { - using VARIANT variant = new(); + using VARIANT variant = default; fixed (double* pResult = result) { HRESULT hr = InitPropVariantFromDoubleVector(pResult, (uint)result.Length, &variant); @@ -1606,7 +1606,7 @@ public static IEnumerable VectorERROR_TestData() [MemberData(nameof(VectorERROR_TestData))] public void VARIANT_ToObject_VECTORERROR_ReturnsExpected(uint[] result) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (uint* pResult = result) @@ -1643,7 +1643,7 @@ public static IEnumerable VectorCY_TestData() [MemberData(nameof(VectorCY_TestData))] public void VARIANT_ToObject_VECTORCY_ReturnsExpected(long[] result, decimal[] expected) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (long* pResult = result) @@ -1684,7 +1684,7 @@ public static IEnumerable VectorDATE_TestData() [MemberData(nameof(VectorDATE_TestData))] public void VARIANT_ToObject_VECTORDATE_ReturnsExpected(double[] result, DateTime[] expected) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (double* pResult = result) @@ -1725,7 +1725,7 @@ public static IEnumerable VectorFILETIME_TestData() [MemberData(nameof(VectorFILETIME_TestData))] public void VARIANT_ToObject_VECTORFILETIME_ReturnsExpected(object result, DateTime[] expected) { - using VARIANT variant = new(); + using VARIANT variant = default; FILETIME[] fileTimeResult = (FILETIME[])result; fixed (FILETIME* pResult = fileTimeResult) { @@ -1754,7 +1754,7 @@ public static IEnumerable VectorCLSID_TestData() [MemberData(nameof(VectorCLSID_TestData))] public void VARIANT_ToObject_VECTORCLSID_ReturnsExpected(Guid[] result) { - VARIANT variant = new(); + VARIANT variant = default; try { fixed (Guid* pResult = result) @@ -1784,7 +1784,7 @@ public void VARIANT_ToObject_VECTORCLSIDNoData_ReturnsExpected() [StaFact] public void VARIANT_ToObject_VECTORBSTR_ReturnsExpected() { - VARIANT variant = new(); + VARIANT variant = default; BSTR ptr1 = new("text"); BSTR ptr2 = new(""); @@ -1827,7 +1827,7 @@ public void VARIANT_ToObject_VECTORBSTRNoData_ReturnsExpected() [StaFact] public void VARIANT_ToObject_VECTORLPWSTR_ReturnsExpected() { - VARIANT variant = new(); + VARIANT variant = default; nint ptr1 = Marshal.StringToCoTaskMemUni("text"); nint ptr2 = Marshal.StringToCoTaskMemUni(""); try @@ -1869,7 +1869,7 @@ public void VARIANT_ToObject_VECTORLPWSTRNoData_ReturnsExpected() [StaFact] public void VARIANT_ToObject_VECTORLPSTR_ReturnsExpected() { - VARIANT variant = new(); + VARIANT variant = default; nint ptr1 = Marshal.StringToCoTaskMemAnsi("text"); nint ptr2 = Marshal.StringToCoTaskMemAnsi(""); try @@ -1911,7 +1911,7 @@ public void VARIANT_ToObject_VECTORLPSTRNoData_ReturnsExpected() [StaFact] public void VARIANT_ToObject_VECTORVARIANT_ReturnsExpected() { - VARIANT variant = new(); + VARIANT variant = default; try { VARIANT variant1 = Create(VT_I4); @@ -1974,7 +1974,7 @@ public void VARIANT_ToObject_VECTORInvalidType_ThrowsArgumentException(ushort vt { vt = VT_VECTOR | (VARENUM)vt }; - Assert.Throws(() => variant.ToObject()); + Assert.Throws(variant.ToObject); } [StaTheory] @@ -5306,7 +5306,7 @@ public void VARIANT_ToObject_ARRAYVECTOR_ThrowsInvalidOleVariantTypeException() { vt = VT_ARRAY | VT_VECTOR | VT_I4 }; - Assert.Throws(() => variant.ToObject()); + Assert.Throws(variant.ToObject); } [StaFact] @@ -5419,8 +5419,9 @@ public void VARIANT_ARRAYBigRank_ThrowsTypeLoadException(int rank) cElements = (uint)result.Length, lLbound = lbound }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreate(vt, 1, &saBound); - Assert.True(psa != null); + NativeAssert.NotNull(psa); VARENUM arrayVt = VT_EMPTY; HRESULT hr = PInvokeCore.SafeArrayGetVartype(psa, &arrayVt); @@ -5431,15 +5432,11 @@ public void VARIANT_ARRAYBigRank_ThrowsTypeLoadException(int rank) { T value = result[i]; int index = i + lbound; + // Insert pointers directly. - if (value is nint valuePtr) - { - hr = PInvokeCore.SafeArrayPutElement(psa, &index, (void*)valuePtr); - } - else - { - hr = PInvokeCore.SafeArrayPutElement(psa, &index, &value); - } + hr = value is nint valuePtr + ? PInvokeCore.SafeArrayPutElement(psa, &index, (void*)valuePtr) + : PInvokeCore.SafeArrayPutElement(psa, &index, &value); Assert.Equal(HRESULT.S_OK, hr); } @@ -5463,7 +5460,7 @@ public void VARIANT_ARRAYBigRank_ThrowsTypeLoadException(int rank) }; SAFEARRAY* psa = PInvokeCore.SafeArrayCreate(vt, 2, saBounds); - Assert.True(psa != null); + NativeAssert.NotNull(psa); VARENUM arrayVt = VT_EMPTY; HRESULT hr = PInvokeCore.SafeArrayGetVartype(psa, &arrayVt); @@ -5474,17 +5471,15 @@ public void VARIANT_ARRAYBigRank_ThrowsTypeLoadException(int rank) { for (int j = 0; j < multiDimArray.GetLength(1); j++) { +#pragma warning disable CA2014 // Do not use stackalloc in loops int* indices = stackalloc int[] { i + lbound1, j + lbound2 }; +#pragma warning restore CA2014 T value = multiDimArray[i, j]; + // Insert pointers directly. - if (value is nint valuePtr) - { - hr = PInvokeCore.SafeArrayPutElement(psa, indices, (void*)valuePtr); - } - else - { - hr = PInvokeCore.SafeArrayPutElement(psa, indices, &value); - } + hr = value is nint valuePtr + ? PInvokeCore.SafeArrayPutElement(psa, indices, (void*)valuePtr) + : PInvokeCore.SafeArrayPutElement(psa, indices, &value); Assert.Equal(HRESULT.S_OK, hr); } @@ -5668,7 +5663,7 @@ public void ToObject_RECORDARRAYInvalidGetGuidHR_ThrowsArgumentException() VARIANT copy = variant; nint pv = (nint)(©); Assert.Throws(() => Marshal.GetObjectForNativeVariant(pv)); - Assert.Throws(() => variant.ToObject()); + Assert.Throws(variant.ToObject); } public static IEnumerable RECORDARRAY_InvalidGuid_TestData() @@ -5748,8 +5743,9 @@ public HRESULT GetSize(uint* pcbSize) cElements = (uint)result.Length, lLbound = lbound }; + SAFEARRAY* psa = PInvokeCore.SafeArrayCreateEx(VT_RECORD, 1, &saBound, recordInfo); - Assert.True(psa != null); + NativeAssert.NotNull(psa); VARENUM arrayVt = VT_EMPTY; HRESULT hr = PInvokeCore.SafeArrayGetVartype(psa, &arrayVt); @@ -5765,7 +5761,7 @@ private static void AssertToObjectThrows(VARIANT variant) where T : Exception nint pv = (nint)(©); Assert.Throws(() => Marshal.GetObjectForNativeVariant(pv)); - Assert.Throws(() => variant.ToObject()); + Assert.Throws(variant.ToObject); } private static void AssertToObjectEqual(object expected, VARIANT variant) @@ -5797,14 +5793,14 @@ public void MarshallingFromExchangeTypes() { // These are the common TypeConverter types we're using. - using (VARIANT variant = new()) + using (VARIANT variant = default) { byte[] bytes = [1, 2, 3]; Marshal.GetNativeVariantForObject(bytes, (nint)(void*)&variant); Assert.Equal(VT_UI1 | VT_ARRAY, variant.vt); } - using (VARIANT variant = new()) + using (VARIANT variant = default) { string value = "Testing"; Marshal.GetNativeVariantForObject(value, (nint)(void*)&variant); @@ -5816,7 +5812,7 @@ public void MarshallingFromExchangeTypes() public void MarshallingFromIntAndUint() { // Interop marshals as VT_I4/VT_UI4 and not VT_INT/VT_UINT - VARIANT variant = new(); + VARIANT variant = default; int intValue = 42; Marshal.GetNativeVariantForObject(intValue, (nint)(void*)&variant); variant.vt.Should().Be(VT_I4); diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextProviderTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextProviderTests.cs index 89f4b358ea9..27d1958cc47 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextProviderTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextProviderTests.cs @@ -21,7 +21,7 @@ public void UiaTextProvider_GetEditStyle_ContainsMultilineStyle_ForMultilineText Mock providerMock = new(MockBehavior.Strict); WINDOW_STYLE actual = UiaTextProvider.GetWindowStyle(textBox); - Assert.True(((int)actual & PInvoke.ES_MULTILINE) != 0); + Assert.NotEqual(0, ((int)actual & PInvoke.ES_MULTILINE)); } [StaFact] @@ -35,7 +35,7 @@ public void UiaTextProvider_GetEditStyle_DoesntContainMultilineStyle_ForSingleli Mock providerMock = new(MockBehavior.Strict); WINDOW_STYLE actual = UiaTextProvider.GetWindowStyle(textBox); - Assert.False(((int)actual & PInvoke.ES_MULTILINE) != 0); + Assert.Equal(0, ((int)actual & PInvoke.ES_MULTILINE)); } [StaFact] @@ -105,7 +105,7 @@ public void UiaTextProvider_RectArrayToDoubleArray_EmptyArrayParameter_ReturnsEm [StaFact] public unsafe void UiaTextProvider_SendInput_SendsOneInput() { - INPUT keyboardInput = new(); + INPUT keyboardInput = default; int actual = UiaTextProvider.SendInput(ref keyboardInput); Assert.Equal(1, actual); } diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextRangeTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextRangeTests.cs index c521c166d6f..3ad5056dce1 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextRangeTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Automation/UiaTextRangeTests.cs @@ -481,7 +481,7 @@ public static IEnumerable UiaTextRange_ITextRangeProvider_GetAttribute yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_FontNameAttributeId, "Segoe UI" }; yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_FontSizeAttributeId, 9.0 }; yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_FontWeightAttributeId, (int)FW.NORMAL }; - yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_ForegroundColorAttributeId, (int)(uint)new COLORREF() }; + yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_ForegroundColorAttributeId, (int)(uint)default(COLORREF) }; yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_HorizontalTextAlignmentAttributeId, (int)HorizontalTextAlignment.Left }; yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_IsItalicAttributeId, false }; yield return new object[] { UIA_TEXTATTRIBUTE_ID.UIA_IsReadOnlyAttributeId, false }; @@ -564,7 +564,7 @@ public void UiaTextRange_ITextRangeProvider_GetBoundingRectangles_ReturnsEmpty_f using SafeArrayScope actual = new((SAFEARRAY*)null); Assert.True(((ITextRangeProvider.Interface)textRange).GetBoundingRectangles(actual).Succeeded); using SafeArrayScope expectedRectArray = UiaTextProvider.BoundingRectangleAsArray(expected); - for(int i = 0; i < actual.Length; i++) + for (int i = 0; i < actual.Length; i++) { Assert.Equal(expectedRectArray[i], actual[i]); } @@ -1229,7 +1229,7 @@ public void UiaTextRange_private_GetFontWeight_ReturnsCorrectValue(object fontWe public void UiaTextRange_private_GetForegroundColor_ReturnsCorrectValue() { COLORREF actual = StaticNullTextRange.TestAccessor().GetForegroundColor(); - Assert.Equal(new COLORREF(), actual); + Assert.Equal(default, actual); } [StaTheory] diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/LocalAppContextSwitchesTest.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/LocalAppContextSwitchesTest.cs index a4cedca1bd8..a619f5d526d 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/LocalAppContextSwitchesTest.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/LocalAppContextSwitchesTest.cs @@ -1,4 +1,4 @@ -// Licensed to the.NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Windows.Forms.Primitives; diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/SinglyLinkedListTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/SinglyLinkedListTests.cs index f4b819df808..12a07139150 100644 --- a/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/SinglyLinkedListTests.cs +++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/SinglyLinkedListTests.cs @@ -107,10 +107,10 @@ public void MoveToFront_InvalidOperations() list.AddFirst(1); var enumerator = list.GetEnumerator(); - Assert.Throws(() => enumerator.MoveCurrentToFront()); + Assert.Throws(enumerator.MoveCurrentToFront); Assert.True(enumerator.MoveNext()); enumerator.MoveCurrentToFront(); - Assert.Throws(() => enumerator.MoveCurrentToFront()); + Assert.Throws(enumerator.MoveCurrentToFront); } [Fact] @@ -155,10 +155,10 @@ public void RemoveCurrent_InvalidOperations() list.AddLast(2); var enumerator = list.GetEnumerator(); - Assert.Throws(() => enumerator.RemoveCurrent()); + Assert.Throws(enumerator.RemoveCurrent); Assert.True(enumerator.MoveNext()); enumerator.RemoveCurrent(); - Assert.Throws(() => enumerator.RemoveCurrent()); + Assert.Throws(enumerator.RemoveCurrent); } } diff --git a/src/System.Windows.Forms/src/System/Resources/ResxFileRef.Converter.cs b/src/System.Windows.Forms/src/System/Resources/ResxFileRef.Converter.cs index e48ca0b6188..ab692de3a79 100644 --- a/src/System.Windows.Forms/src/System/Resources/ResxFileRef.Converter.cs +++ b/src/System.Windows.Forms/src/System/Resources/ResxFileRef.Converter.cs @@ -53,14 +53,14 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina int lastIndexOfQuote = stringValue.LastIndexOf('"'); if (lastIndexOfQuote - 1 < 0) { - throw new ArgumentException(nameof(stringValue)); + throw new ArgumentException(null, nameof(stringValue)); } // Remove the quotes in " ..... " fileName = stringValue[1..lastIndexOfQuote]; if (lastIndexOfQuote + 2 > stringValue.Length) { - throw new ArgumentException(nameof(stringValue)); + throw new ArgumentException(null, nameof(stringValue)); } remainingString = stringValue[(lastIndexOfQuote + 2)..]; @@ -70,13 +70,13 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina int nextSemiColumn = stringValue.IndexOf(';'); if (nextSemiColumn == -1) { - throw new ArgumentException(nameof(stringValue)); + throw new ArgumentException(null, nameof(stringValue)); } fileName = stringValue[..nextSemiColumn]; if (nextSemiColumn + 1 > stringValue.Length) { - throw new ArgumentException(nameof(stringValue)); + throw new ArgumentException(null, nameof(stringValue)); } remainingString = stringValue[(nextSemiColumn + 1)..]; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2AboutBoxPropertyDescriptor.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2AboutBoxPropertyDescriptor.cs index 942a46ab799..ed1a2f10066 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2AboutBoxPropertyDescriptor.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2AboutBoxPropertyDescriptor.cs @@ -59,7 +59,7 @@ public override void ResetValue(object? component) { } - public override void SetValue(object? component, object? value) => throw new ArgumentException(); + public override void SetValue(object? component, object? value) => throw new ArgumentException(null); public override bool ShouldSerializeValue(object component) => false; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control_InvokeAsync.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control_InvokeAsync.cs index cedced54dba..1cf3e850015 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control_InvokeAsync.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control_InvokeAsync.cs @@ -38,7 +38,7 @@ public async Task InvokeAsync(Action callback, CancellationToken cancellationTok TaskCompletionSource completion = new(TaskCreationOptions.RunContinuationsAsynchronously); - using (cancellationToken.Register(() => completion.SetCanceled(), useSynchronizationContext: false)) + using (cancellationToken.Register(completion.SetCanceled, useSynchronizationContext: false)) { BeginInvoke(WrappedAction); await completion.Task.ConfigureAwait(false); @@ -104,7 +104,7 @@ public async Task InvokeAsync(Func callback, CancellationToken cancella TaskCompletionSource completion = new(TaskCreationOptions.RunContinuationsAsynchronously); - using (cancellationToken.Register(() => completion.SetCanceled(), useSynchronizationContext: false)) + using (cancellationToken.Register(completion.SetCanceled, useSynchronizationContext: false)) { BeginInvoke(WrappedCallback); return await completion.Task.ConfigureAwait(false); @@ -169,7 +169,7 @@ public async Task InvokeAsync(Func callback, Cance TaskCompletionSource completion = new(TaskCreationOptions.RunContinuationsAsynchronously); - using (cancellationToken.Register(() => completion.SetCanceled(), useSynchronizationContext: false)) + using (cancellationToken.Register(completion.SetCanceled, useSynchronizationContext: false)) { BeginInvoke(async () => await WrappedCallbackAsync().ConfigureAwait(false)); await completion.Task.ConfigureAwait(false); @@ -233,7 +233,7 @@ public async Task InvokeAsync(Func> callba TaskCompletionSource completion = new(TaskCreationOptions.RunContinuationsAsynchronously); - using (cancellationToken.Register(() => completion.SetCanceled(), useSynchronizationContext: false)) + using (cancellationToken.Register(completion.SetCanceled, useSynchronizationContext: false)) { BeginInvoke(async () => await WrappedCallbackAsync().ConfigureAwait(false)); return await completion.Task.ConfigureAwait(false); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListBoxes/ListBox.IntegerCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListBoxes/ListBox.IntegerCollection.cs index 4b9494f03c3..421247d5b70 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListBoxes/ListBox.IntegerCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListBoxes/ListBox.IntegerCollection.cs @@ -152,7 +152,7 @@ int IList.Add(object? item) { if (item is not int) { - throw new ArgumentException(nameof(item)); + throw new ArgumentException(null, nameof(item)); } return Add((int)item); @@ -232,7 +232,7 @@ void IList.Remove(object? value) { if (value is not int) { - throw new ArgumentException(nameof(value)); + throw new ArgumentException(null, nameof(value)); } Remove((int)value); @@ -305,7 +305,7 @@ public int this[int index] { if (value is not int) { - throw new ArgumentException(nameof(value)); + throw new ArgumentException(null, nameof(value)); } else { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListView/ListView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListView/ListView.cs index 24a6688e4d7..d656f327e26 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListView/ListView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ListView/ListView.cs @@ -4006,7 +4006,7 @@ private void InsertItems(int displayIndex, ListViewItem[] items, bool checkHosti { if (items[i]._listView is not null) { - throw new ArgumentException(string.Format(SR.OnlyOneControl, items[i].Text), "item"); + throw new ArgumentException(string.Format(SR.OnlyOneControl, items[i].Text), nameof(items)); } } } @@ -4033,7 +4033,7 @@ private void InsertItems(int displayIndex, ListViewItem[] items, bool checkHosti if (checkHosting && item._listView is not null) { - throw new ArgumentException(string.Format(SR.OnlyOneControl, item.Text), "item"); + throw new ArgumentException(string.Format(SR.OnlyOneControl, item.Text), nameof(items)); } // create an ID.. diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs index b91bc84c02c..4a59a241b44 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs @@ -287,7 +287,7 @@ private static List UnsortedMerge( int result = string.Compare(entryName, sortString, ignoreCase: false, CultureInfo.InvariantCulture); if (result == 0) { - mergedEntries.Add([basePropertyDescriptor, ..propertyDescriptors]); + mergedEntries.Add([basePropertyDescriptor, .. propertyDescriptors]); break; } else if (result < 0) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabPageCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabPageCollection.cs index ba295fa6129..af3138d3992 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabPageCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.TabPageCollection.cs @@ -36,7 +36,7 @@ public virtual TabPage this[int index] { if (value is not TabPage tabPage) { - throw new ArgumentException(nameof(value)); + throw new ArgumentException(null, nameof(value)); } this[index] = tabPage; @@ -89,7 +89,7 @@ int IList.Add(object? value) { if (value is not TabPage tabPage) { - throw new ArgumentException(nameof(value)); + throw new ArgumentException(null, nameof(value)); } Add(tabPage); @@ -239,7 +239,7 @@ void IList.Insert(int index, object? tabPage) { if (tabPage is not TabPage actualTabPage) { - throw new ArgumentException(nameof(tabPage)); + throw new ArgumentException(null, nameof(tabPage)); } Insert(index, actualTabPage); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogProgressBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogProgressBar.cs index 7bcbbd5d408..937cdcb436e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogProgressBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/TaskDialog/TaskDialogProgressBar.cs @@ -313,7 +313,7 @@ state is TaskDialogProgressBarState.Marquee or TaskDialogProgressBarState.Normal => PInvoke.PBST_NORMAL, TaskDialogProgressBarState.Paused => PInvoke.PBST_PAUSED, TaskDialogProgressBarState.Error => PInvoke.PBST_ERROR, - _ => throw new ArgumentException() + _ => throw new ArgumentException(null, nameof(state)) }; private protected override TASKDIALOG_FLAGS BindCore() diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.SorterObjectArray.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.SorterObjectArray.cs index 410d95f6e13..231f5e30387 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.SorterObjectArray.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.SorterObjectArray.cs @@ -32,7 +32,7 @@ internal readonly void SwapIfGreaterWithItems(int a, int b) } catch (IndexOutOfRangeException) { - throw new ArgumentException(); + throw new ArgumentException(null); } catch (Exception) { @@ -76,7 +76,7 @@ internal void QuickSort(int left, int right) } catch (IndexOutOfRangeException) { - throw new ArgumentException(); + throw new ArgumentException(null); } catch (Exception) { diff --git a/src/System.Windows.Forms/tests/AccessibilityTests/Program.cs b/src/System.Windows.Forms/tests/AccessibilityTests/Program.cs index 725ce21f390..49bea18074e 100644 --- a/src/System.Windows.Forms/tests/AccessibilityTests/Program.cs +++ b/src/System.Windows.Forms/tests/AccessibilityTests/Program.cs @@ -1,4 +1,7 @@ -using System.Windows.Forms; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Windows.Forms; namespace Accessibility_Core_App; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButton.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButton.cs index d9d1c624572..2ea00244348 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButton.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButton.cs @@ -1,4 +1,7 @@ -using System.Windows.Forms; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Windows.Forms; using System.ComponentModel; namespace TestConsole; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesigner.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesigner.cs index 1978b5f8f73..10ec929605a 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesigner.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesigner.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.Windows.Forms.Design; namespace TestConsole; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesignerActionList.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesignerActionList.cs index 0e430af3661..c1750c1beae 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesignerActionList.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/CustomButtonDesignerActionList.cs @@ -1,4 +1,7 @@ -using System.ComponentModel; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/DesignerActionVerbItem.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/DesignerActionVerbItem.cs index fe0589dc868..e861ad8da41 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/DesignerActionVerbItem.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/CustomControls/DesignerActionVerbItem.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.Diagnostics; namespace TestConsole; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyScrollableControl.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyScrollableControl.cs index 67e21b9334c..c18e0787175 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyScrollableControl.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyScrollableControl.cs @@ -1,4 +1,7 @@ -using System.Drawing; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; using System.Windows.Forms; namespace TestConsole; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyUserControl.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyUserControl.cs index d49a0791630..719076a17b9 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyUserControl.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.MyUserControl.cs @@ -1,4 +1,7 @@ -using System.Drawing; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; using System.Windows.Forms; namespace TestConsole; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs index f39831134e9..1166aaef064 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs @@ -1,4 +1,7 @@ -using System.Drawing; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; using System.Windows.Forms; using System.ComponentModel.Design; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/Program.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/Program.cs index d89a4e56789..8dd27208b09 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/Program.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/Program.cs @@ -1,4 +1,7 @@ -using System.Windows.Forms; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Windows.Forms; namespace TestConsole; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignSurfaceExt.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignSurfaceExt.cs index fcc12086142..1f606f30da5 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignSurfaceExt.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignSurfaceExt.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; @@ -15,7 +18,7 @@ public class DesignSurfaceExt : DesignSurface, IDesignSurfaceExt public void SwitchTabOrder() { - if (IsTabOrderMode == false) + if (!IsTabOrderMode) { InvokeTabOrder(); } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerOptionServiceExt.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerOptionServiceExt.cs index eb0d39c6e90..6ae508cdb6c 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerOptionServiceExt.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerOptionServiceExt.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.Windows.Forms.Design; namespace DesignSurfaceExt; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerSerializationServiceImpl.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerSerializationServiceImpl.cs index ccf025156cb..e62921d8ec6 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerSerializationServiceImpl.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/DesignerSerializationServiceImpl.cs @@ -1,4 +1,7 @@ -using System.Windows.Forms; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Windows.Forms; using System.ComponentModel.Design.Serialization; using System.Collections; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/IDesignSurfaceExt.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/IDesignSurfaceExt.cs index 3cba7e5c929..f656409d3b7 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/IDesignSurfaceExt.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/IDesignSurfaceExt.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.Windows.Forms; using System.ComponentModel; using System.Drawing; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/NameCreationServiceImp.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/NameCreationServiceImp.cs index fce37cc89a8..4763a4a4fcf 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/NameCreationServiceImp.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/NameCreationServiceImp.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design.Serialization; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design.Serialization; using System.ComponentModel; // - NameCreationServiceImp - Implementing INameCreationService diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/Properties/AssemblyInfo.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/Properties/AssemblyInfo.cs index 02731fa1941..4b419b55ac7 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/Properties/AssemblyInfo.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/Properties/AssemblyInfo.cs @@ -1,6 +1,5 @@ -// using System.Reflection; -// using System.Runtime.CompilerServices; -// using System.Runtime.InteropServices; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. // // General Information about an assembly is controlled through the following // // set of attributes. Change these attribute values to modify the information diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/TabOrderHooker.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/TabOrderHooker.cs index 4e2827626b0..9a45afeb80c 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/TabOrderHooker.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/TabOrderHooker.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; using System.Reflection; namespace DesignSurfaceExt; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/UndoEngineExt.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/UndoEngineExt.cs index 5defdb41c96..1142baeaade 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/UndoEngineExt.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DesignSurfaceExt/UndoEngineExt.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.Design; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; namespace DesignSurfaceExt; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/ScratchProjectWithInternals/Program.cs b/src/System.Windows.Forms/tests/IntegrationTests/ScratchProjectWithInternals/Program.cs index 0f7477991d1..52f6a4cc389 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/ScratchProjectWithInternals/Program.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/ScratchProjectWithInternals/Program.cs @@ -9,7 +9,7 @@ namespace ScratchProjectWithInternals; internal static class Program { [STAThread] - public unsafe static void Main() + public static unsafe void Main() { Application.EnableVisualStyles(); Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); diff --git a/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Form1.cs b/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Form1.cs index 200073a0e3e..a8801f2060c 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Form1.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Form1.cs @@ -1,3 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + using System.ComponentModel; namespace TrimTestBinaryDeserialization diff --git a/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Program.cs b/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Program.cs index fa98acd98d7..cbbf9377d56 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Program.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/TrimTestBinaryDeserialization/Program.cs @@ -1,4 +1,7 @@ -namespace TrimTestBinaryDeserialization +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace TrimTestBinaryDeserialization { internal static class Program { diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/DragDropTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/DragDropTests.cs index 73c88c58016..b2c96314870 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/DragDropTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/DragDropTests.cs @@ -49,7 +49,7 @@ await InputSimulator.SendAsync( .MoveMouseTo(targetMousePosition.X + 4, targetMousePosition.Y + 4) .LeftButtonUp()); - Assert.Equal(1, form.ListDragTarget.Items.Count); + Assert.Single(form.ListDragTarget.Items); }); } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/FolderNameEditorTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/FolderNameEditorTests.cs index 01bb67927da..510567cc4f4 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/FolderNameEditorTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/FolderNameEditorTests.cs @@ -52,4 +52,3 @@ private class TestFolderNameEditor : FolderNameEditor } } } - diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/GlobalSuppressions.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/GlobalSuppressions.cs index 3865b67214b..54988ed8c75 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/GlobalSuppressions.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/GlobalSuppressions.cs @@ -1,6 +1,4 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods")] diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/ScreenRecordService.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/ScreenRecordService.cs index e3c9fb6927d..db5c5f74cdd 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/ScreenRecordService.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/ScreenRecordService.cs @@ -451,7 +451,7 @@ private static (ReadOnlyMemory signature, ReadOnlyMemory ihdr, Immut } Assert.False(ihdr.IsEmpty); - Assert.NotEqual(0, idat.Count); + Assert.NotEmpty(idat); Assert.False(iend.IsEmpty); return (signature, ihdr, idat.ToImmutableArray(), iend); diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Input/InputBuilder.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Input/InputBuilder.cs index 60d50ab96a8..e245e5123b3 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Input/InputBuilder.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Input/InputBuilder.cs @@ -54,7 +54,7 @@ public static INPUT CharacterDown(char character) // Handle extended keys: // If the scan code is preceded by a prefix byte that has the value 0xE0 (224), - // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property. + // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property. if ((scanCode & 0xFF00) == 0xE000) { input.Anonymous.ki.dwFlags |= KEYBD_EVENT_FLAGS.KEYEVENTF_EXTENDEDKEY; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/MenuStripTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/MenuStripTests.cs index 985b79f5cf1..7b6fea0e917 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/MenuStripTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/MenuStripTests.cs @@ -21,7 +21,7 @@ public void MenuStrip_ProcessCmdKey_InvokeSpaceKey(bool value) form.Controls.Add(menuStrip); form.Show(); - Message message = new(); + Message message = default; menuStrip.Focused.Should().Be(value); toolStripMenuItem1.ProcessCmdKey(ref message, keyData: Keys.Enter); diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/OpenFileDialogTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/OpenFileDialogTests.cs index ad6057608e5..45aa4babf81 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/OpenFileDialogTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/OpenFileDialogTests.cs @@ -38,7 +38,7 @@ public void OpenFileDialogTests_ResultWithMultiselect() using var tempFile = TempFile.Create(0); using AcceptDialogForm dialogOwnerForm = new(); using OpenFileDialog dialog = new(); - dialog.Multiselect= true; + dialog.Multiselect = true; dialog.InitialDirectory = Path.GetDirectoryName(tempFile.Path); dialog.FileName = tempFile.Path; Assert.Equal(DialogResult.OK, dialog.ShowDialog(dialogOwnerForm)); diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/PropertyGridTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/PropertyGridTests.cs index 438ded031c8..54c368a594d 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/PropertyGridTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/PropertyGridTests.cs @@ -97,7 +97,7 @@ public void PropertyGrid_AutoScroll_GetSet_ReturnsExpected() [WinFormsFact] public void PropertyGrid_RefreshEvent_Raised_ShouldNotThrowException() { - Action act = () => _propertyGrid.Refresh(); + Action act = _propertyGrid.Refresh; act.Should().NotThrow(); } @@ -300,7 +300,7 @@ public void PropertyGrid_SelectedObjects_GetSet_ReturnsExpected() using Button button1 = new(); using TextBox textBox1 = new(); using ComboBox comboBox1 = new(); - object[] objects = { button1, textBox1, comboBox1 }; + object[] objects = [button1, textBox1, comboBox1]; _propertyGrid.SelectedObjects = objects; _propertyGrid.SelectedObjects.Should().Contain(objects); @@ -494,5 +494,5 @@ public void PropertyGrid_SelectedGridItem_GetSet_ReturnsExpected() GridItem gridItem = _propertyGrid.SelectedGridItem.GridItems[0]; _propertyGrid.SelectedGridItem = gridItem; _propertyGrid.SelectedGridItem.Should().Be(gridItem); - } + } } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/RichTextBoxTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/RichTextBoxTests.cs index f53b15a4807..67981c31511 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/RichTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/RichTextBoxTests.cs @@ -137,9 +137,9 @@ public async Task RichTextBox_Click_On_Custom_Link_Followed_By_Hidden_Text_Provi { await RunTestAsync(async (form, richTextBox) => { - // This needs to be sufficiently different from the previous test so we don't click on the same location twice, - // otherwise the tests may execute fast enough for the second test to register as a double click. - richTextBox.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang4105{\fonttbl{\f0\fnil\fcharset0 Calibri;}} + // This needs to be sufficiently different from the previous test so we don't click on the same location twice, + // otherwise the tests may execute fast enough for the second test to register as a double click. + richTextBox.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang4105{\fonttbl{\f0\fnil\fcharset0 Calibri;}} {\*\generator Riched20 10.0.17134}\viewkind4\uc1\pard\sa200\sl276\slmult1\f0\fs22\lang9 This is a custom link\v #link1#\v0 which is followed by hidden text.\par This is a custom link\v #link2#\v0 which is followed by hidden text.\par @@ -222,7 +222,7 @@ private unsafe void MakeLink(RichTextBox control, string text) using ComScope range = new(null); textDocument.Value->Range(start, start + length, range).ThrowOnFailure(); transform?.Invoke((ITextRange*)range); - using BSTR text = new(); + using BSTR text = default; range.Value->GetText(&text).ThrowOnFailure(); return text.ToString(); } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabControlTests.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabControlTests.cs index c313b811acf..55d741df5c6 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabControlTests.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabControlTests.cs @@ -106,7 +106,7 @@ await RunSingleControlTestAsync( tabControl.SelectedIndex--; await Task.Yield(); - // The changes we made to SelectedIndex will result in a WM_WINDOWPOSCHANGED message which will + // The changes we made to SelectedIndex will result in a WM_WINDOWPOSCHANGED message which will // fire TabPage.WmWindowPosChanged, which will call TabControl.UpdateChildControlIndex. // This test ensures that the latter method short-circuits and does not call Controls.SetChildIndex diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ChartControl.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ChartControl.cs index 238907b271f..e9079444719 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ChartControl.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ChartControl.cs @@ -30,11 +30,11 @@ private void ChartControl_Load(object sender, EventArgs e) chart2.ChartAreas[0].AxisX.LabelStyle.Interval = 2; chart2.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Days; - // Fill series data for chart3 - double[] yValues = [32.4, 56.9, 89.7, 80.5, 59.3, 33.8, 78.8, 44.6, 76.4, 68.9]; - chart3.Series["DataSeries"].Points.DataBindY(yValues); - // Link error bar series with data series - chart3.Series["ErrorBar"]["ErrorBarSeries"] = "DataSeries"; + // Fill series data for chart3 + double[] yValues = [32.4, 56.9, 89.7, 80.5, 59.3, 33.8, 78.8, 44.6, 76.4, 68.9]; + chart3.Series["DataSeries"].Points.DataBindY(yValues); + // Link error bar series with data series + chart3.Series["ErrorBar"]["ErrorBarSeries"] = "DataSeries"; // Fill series data for chart4 chart4.Series[0].Font = new Font("Trebuchet MS", 8, FontStyle.Bold); diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/CustomComCtl32Button.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/CustomComCtl32Button.cs index 10997e04ae2..1203f656507 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/CustomComCtl32Button.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/CustomComCtl32Button.cs @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. using System.Drawing; using System.Drawing.Drawing2D; @@ -73,7 +72,7 @@ private void InitializeComponent() Controls.Add(control); } - void DrawRoundBorder(Control sender, Graphics g) + static void DrawRoundBorder(Control sender, Graphics g) { bool isPressed = false; if (sender.GetType().Name == "CheckBox") diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/FormShowInTaskbar.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/FormShowInTaskbar.cs index 5bb7b37f4da..f86b33963c2 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/FormShowInTaskbar.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/FormShowInTaskbar.cs @@ -48,7 +48,7 @@ private void BtnTest_Click(object sender, EventArgs e) IntPtr formHandle = form.Handle; form.ShowInTaskbar = !form.ShowInTaskbar; - if (form.IsHandleCreated == false) + if (!form.IsHandleCreated) throw new InvalidOperationException(); if (formHandle == form.Handle) diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ListBoxes.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ListBoxes.cs index 9039c34207f..a2613020ede 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ListBoxes.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ListBoxes.cs @@ -16,8 +16,8 @@ public ListBoxes() private void addButton_Click(object sender, EventArgs e) { var control = (Control)sender; - var listBox = (ListBox)((Object[])control.Tag)[0]; - var textBox = (TextBox)((Object[])control.Tag)[1]; + var listBox = (ListBox)((object[])control.Tag)[0]; + var textBox = (TextBox)((object[])control.Tag)[1]; listBox.Items.Add(textBox.Text); } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Program.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Program.cs index 96d88ac09d5..6e6337b4de8 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Program.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Program.cs @@ -27,4 +27,3 @@ } Environment.Exit(0); - diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ScrollBars.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ScrollBars.cs index 77a78041290..3e0825fd4be 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ScrollBars.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ScrollBars.cs @@ -14,16 +14,16 @@ public ScrollBars() private void numericMaximum_ValueChanged(object sender, EventArgs e) { - hScrollBar.Maximum = Decimal.ToInt32(numericMaximum.Value); - vScrollBar.Maximum = Decimal.ToInt32(numericMaximum.Value); + hScrollBar.Maximum = decimal.ToInt32(numericMaximum.Value); + vScrollBar.Maximum = decimal.ToInt32(numericMaximum.Value); numericMinimum.Maximum = numericMaximum.Value; SetValueLabels(); } private void numericMinimum_ValueChanged(object sender, EventArgs e) { - hScrollBar.Minimum = Decimal.ToInt32(numericMinimum.Value); - vScrollBar.Minimum = Decimal.ToInt32(numericMinimum.Value); + hScrollBar.Minimum = decimal.ToInt32(numericMinimum.Value); + vScrollBar.Minimum = decimal.ToInt32(numericMinimum.Value); numericMaximum.Minimum = numericMinimum.Value; SetValueLabels(); } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ToolStripSeparatorPreferredSize.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ToolStripSeparatorPreferredSize.cs index 07f40d3b83f..532202e82a5 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ToolStripSeparatorPreferredSize.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/ToolStripSeparatorPreferredSize.cs @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. namespace WinFormsControlsTest; @@ -29,17 +28,17 @@ private void SetLabelText() private void InitializeComponent() { - _toolStrip1 = new System.Windows.Forms.ToolStrip(); - _toolStripLabel1 = new System.Windows.Forms.ToolStripLabel(); - _toolStripLabel2 = new System.Windows.Forms.ToolStripLabel(); - _toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - _buttonChangeOrientation = new System.Windows.Forms.Button(); - _label1 = new System.Windows.Forms.Label(); + _toolStrip1 = new ToolStrip(); + _toolStripLabel1 = new ToolStripLabel(); + _toolStripLabel2 = new ToolStripLabel(); + _toolStripSeparator1 = new ToolStripSeparator(); + _buttonChangeOrientation = new Button(); + _label1 = new Label(); _toolStrip1.SuspendLayout(); SuspendLayout(); - // + // // toolStrip1 - // + // _toolStrip1.Items.AddRange((ToolStripItem[]) [ _toolStripLabel1, @@ -52,21 +51,21 @@ private void InitializeComponent() _toolStrip1.TabIndex = 0; _toolStrip1.Text = "toolStrip1"; _toolStrip1.TabStop = true; - // + // // toolStripLabel1 - // + // _toolStripLabel1.Name = "toolStripLabel1"; _toolStripLabel1.Size = new System.Drawing.Size(86, 22); _toolStripLabel1.Text = "ToolStripLabel"; - // + // // toolStripLabel2 - // + // _toolStripLabel2.Name = "toolStripLabel2"; _toolStripLabel2.Size = new System.Drawing.Size(86, 22); _toolStripLabel2.Text = "ToolStripLabel"; - // + // // buttonChangeOrientation - // + // _buttonChangeOrientation.AutoSizeMode = AutoSizeMode.GrowAndShrink; _buttonChangeOrientation.Name = "buttonChangeOrientation"; _buttonChangeOrientation.Location = new System.Drawing.Point(10, 75); @@ -74,15 +73,15 @@ private void InitializeComponent() _buttonChangeOrientation.TabIndex = 0; _buttonChangeOrientation.Text = "Change Orientation"; _buttonChangeOrientation.UseVisualStyleBackColor = true; - // + // // label1 // _label1.Name = "label1"; _label1.Location = new System.Drawing.Point(10, 50); _label1.AutoSize = true; - // + // // Form1 - // + // AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); AutoScaleMode = AutoScaleMode.Font; Size = new System.Drawing.Size(881, 150); diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs index c9eb7ebe8ec..2106e688d45 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs @@ -71,7 +71,7 @@ private void tickstyleNone_CheckedChanged(object sender, EventArgs e) private void numericMinimum_ValueChanged(object sender, EventArgs e) { trackBar1.Minimum = (int)Math.Max(numericMinimum.Value, int.MinValue); - numericMaximum.Minimum = numericMinimum.Value; + numericMaximum.Minimum = numericMinimum.Value; numericFrequency.Maximum = (int)Math.Min(numericMaximum.Value - numericMaximum.Minimum, int.MaxValue); if (numericFrequency.Maximum == 0) { diff --git a/src/System.Windows.Forms/tests/InteropTests/AccessibleObjectTests.cs b/src/System.Windows.Forms/tests/InteropTests/AccessibleObjectTests.cs index 235c03ddfe5..22886d76de9 100644 --- a/src/System.Windows.Forms/tests/InteropTests/AccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/InteropTests/AccessibleObjectTests.cs @@ -168,7 +168,7 @@ public void AccessibleObject_IRangeValueProviderSetValue_Invoke_GetReturnsExpect public void AccessibleObject_IRawElementProviderFragmentBoundingRectangle_Get_ReturnsExpected() { AccessibleObject o = new(); - AssertSuccess(Test_IRawElementProviderFragmentGetBoundingRectangle(o, new UiaRect())); + AssertSuccess(Test_IRawElementProviderFragmentGetBoundingRectangle(o, default)); } [WinFormsFact] @@ -448,13 +448,13 @@ public void SystemAccessibleObject_Enumeration() control.CreateControl(); ComboBox.ComboBoxAccessibleObject accessibleObject = new(control); - var enumVariant = (IEnumVARIANT.Interface)accessibleObject; - Assert.Equal(HRESULT.S_OK, enumVariant.Reset()); + var enumVariant = (IEnumVARIANT.Interface)accessibleObject; + Assert.Equal(HRESULT.S_OK, enumVariant.Reset()); - VARIANT variantObject; - uint retreivedCount; - var result = enumVariant.Next(1, &variantObject, &retreivedCount); - Assert.Equal(HRESULT.S_OK, result); + VARIANT variantObject; + uint retreivedCount; + var result = enumVariant.Next(1, &variantObject, &retreivedCount); + Assert.Equal(HRESULT.S_OK, result); object retreivedItem = variantObject.ToObject(); diff --git a/src/System.Windows.Forms/tests/InteropTests/PropertyGridTests.cs b/src/System.Windows.Forms/tests/InteropTests/PropertyGridTests.cs index c4d8888b1f1..75613864379 100644 --- a/src/System.Windows.Forms/tests/InteropTests/PropertyGridTests.cs +++ b/src/System.Windows.Forms/tests/InteropTests/PropertyGridTests.cs @@ -78,7 +78,7 @@ public void ISupportErrorInfo_Supported_WithIErrorInfoGiven() private unsafe void ExecuteWithActivationContext(string applicationManifest, Action action) { - ACTCTXW context = new(); + ACTCTXW context = default; HANDLE handle; fixed (char* p = applicationManifest) { diff --git a/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelperEx.cs b/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelperEx.cs index a2b6c1130eb..85050597cb6 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelperEx.cs +++ b/src/System.Windows.Forms/tests/TestUtilities/CommonTestHelperEx.cs @@ -76,7 +76,7 @@ public static TheoryData GetPaddingTheoryData() { TheoryData data = new() { - new(), + default, new(1, 2, 3, 4), new(1), new(-1, -2, -3, -4) @@ -88,7 +88,7 @@ public static TheoryData GetPaddingNormalizedTheoryData() { var data = new TheoryData { - { new Padding(), new Padding() }, + { default, default }, { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4) }, { new Padding(1), new Padding(1) }, { new Padding(-1, -2, -3, -4), Padding.Empty } diff --git a/src/System.Windows.Forms/tests/TestUtilities/KeyboardSimulator.cs b/src/System.Windows.Forms/tests/TestUtilities/KeyboardSimulator.cs index 9bda9fbfdc5..5eb5663da61 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/KeyboardSimulator.cs +++ b/src/System.Windows.Forms/tests/TestUtilities/KeyboardSimulator.cs @@ -28,6 +28,6 @@ private static (nint keyCode, nint lParam) GetKeyParameters(Keys key) int scanCode = (int)key; const int repeatCount = 1; nint lParam = PARAM.FromLowHighUnsigned(repeatCount, scanCode); - return (keyCode , lParam); + return (keyCode, lParam); } } diff --git a/src/System.Windows.Forms/tests/TestUtilities/ResxHelper.cs b/src/System.Windows.Forms/tests/TestUtilities/ResxHelper.cs index 660a6bfe84b..3b27dc36e55 100644 --- a/src/System.Windows.Forms/tests/TestUtilities/ResxHelper.cs +++ b/src/System.Windows.Forms/tests/TestUtilities/ResxHelper.cs @@ -1,4 +1,7 @@ -namespace System.Windows.Forms.TestUtilities; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms.TestUtilities; public static class ResxHelper { diff --git a/src/System.Windows.Forms/tests/UnitTests/CheckedListBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/CheckedListBoxTests.cs index 7e337ec08d8..7f2804856a3 100644 --- a/src/System.Windows.Forms/tests/UnitTests/CheckedListBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/CheckedListBoxTests.cs @@ -176,7 +176,7 @@ public void CheckedListBox_Padding_Set_GetReturnsExpected(Padding value, Padding public static IEnumerable Padding_SetWithHandle_TestData() { - yield return new object[] { new Padding(), new Padding(), 0, 0 }; + yield return new object[] { default(Padding), default(Padding), 0, 0 }; yield return new object[] { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 1 }; yield return new object[] { new Padding(1), new Padding(1), 1, 1 }; yield return new object[] { new Padding(-1, -2, -3, -4), Padding.Empty, 1, 2 }; @@ -508,24 +508,24 @@ public void CheckedListBox_Remove_NotSelectedItems(bool createControl) Assert.Equal(3, checkedListBox.Items.Count); Assert.Equal(checkedListBox.Items[0], checkedListBox.SelectedItem); Assert.Equal(0, checkedListBox.SelectedIndex); - Assert.Equal(1, checkedListBox.SelectedIndices.Count); - Assert.Equal(1, checkedListBox.SelectedItems.Count); + Assert.Single(checkedListBox.SelectedIndices); + Assert.Single(checkedListBox.SelectedItems); checkedListBox.Items.Remove(checkedListBox.Items[2]); Assert.Equal(2, checkedListBox.Items.Count); Assert.Equal(checkedListBox.Items[0], checkedListBox.SelectedItem); Assert.Equal(0, checkedListBox.SelectedIndex); - Assert.Equal(1, checkedListBox.SelectedIndices.Count); - Assert.Equal(1, checkedListBox.SelectedItems.Count); + Assert.Single(checkedListBox.SelectedIndices); + Assert.Single(checkedListBox.SelectedItems); checkedListBox.Items.Remove(checkedListBox.Items[1]); - Assert.Equal(1, checkedListBox.Items.Count); + Assert.Single(checkedListBox.Items); Assert.Equal(checkedListBox.Items[0], checkedListBox.SelectedItem); Assert.Equal(0, checkedListBox.SelectedIndex); - Assert.Equal(1, checkedListBox.SelectedIndices.Count); - Assert.Equal(1, checkedListBox.SelectedItems.Count); + Assert.Single(checkedListBox.SelectedIndices); + Assert.Single(checkedListBox.SelectedItems); Assert.Equal(createControl, checkedListBox.IsHandleCreated); } @@ -549,8 +549,8 @@ public void CheckedListBox_Remove_SelectedItem(bool createControl) Assert.Equal(checkedListBox.Items[0], checkedListBox.SelectedItem); Assert.Equal(0, checkedListBox.SelectedIndex); - Assert.Equal(1, checkedListBox.SelectedIndices.Count); - Assert.Equal(1, checkedListBox.SelectedItems.Count); + Assert.Single(checkedListBox.SelectedIndices); + Assert.Single(checkedListBox.SelectedItems); checkedListBox.Items.Remove(checkedListBox.Items[0]); count -= 1; @@ -558,8 +558,8 @@ public void CheckedListBox_Remove_SelectedItem(bool createControl) Assert.Equal(count, checkedListBox.Items.Count); Assert.Null(checkedListBox.SelectedItem); Assert.Equal(-1, checkedListBox.SelectedIndex); - Assert.Equal(0, checkedListBox.SelectedIndices.Count); - Assert.Equal(0, checkedListBox.SelectedItems.Count); + Assert.Empty(checkedListBox.SelectedIndices); + Assert.Empty(checkedListBox.SelectedItems); } } @@ -581,16 +581,16 @@ public void CheckedListBox_Remove_UncheckedItems(bool createControl) for (int count = checkedListBox.Items.Count; count > 1; count -= 1) { - Assert.Equal(1, checkedListBox.CheckedIndices.Count); - Assert.Equal(1, checkedListBox.CheckedItems.Count); + Assert.Single(checkedListBox.CheckedIndices); + Assert.Single(checkedListBox.CheckedItems); checkedListBox.Items.Remove(checkedListBox.Items[2]); count -= 1; Assert.Equal(count, checkedListBox.Items.Count); - Assert.Equal(1, checkedListBox.CheckedIndices.Count); - Assert.Equal(1, checkedListBox.CheckedItems.Count); + Assert.Single(checkedListBox.CheckedIndices); + Assert.Single(checkedListBox.CheckedItems); } } @@ -612,16 +612,16 @@ public void CheckedListBox_Remove_CheckedItems(bool createControl) { checkedListBox.SetItemChecked(0, true); - Assert.Equal(1, checkedListBox.CheckedIndices.Count); - Assert.Equal(1, checkedListBox.CheckedItems.Count); + Assert.Single(checkedListBox.CheckedIndices); + Assert.Single(checkedListBox.CheckedItems); checkedListBox.Items.Remove(checkedListBox.Items[0]); count -= 1; Assert.Equal(count, checkedListBox.Items.Count); - Assert.Equal(0, checkedListBox.CheckedIndices.Count); - Assert.Equal(0, checkedListBox.CheckedItems.Count); + Assert.Empty(checkedListBox.CheckedIndices); + Assert.Empty(checkedListBox.CheckedItems); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/GlobalSuppressions.cs b/src/System.Windows.Forms/tests/UnitTests/GlobalSuppressions.cs index 1e081bec5a1..c53e2f07e87 100644 --- a/src/System.Windows.Forms/tests/UnitTests/GlobalSuppressions.cs +++ b/src/System.Windows.Forms/tests/UnitTests/GlobalSuppressions.cs @@ -1,7 +1,5 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; diff --git a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs index 15dcdfbc98d..e7f0364aa71 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs @@ -89,7 +89,8 @@ public void MaskedTextBox_BeepOnError_Set_GetReturnsExpected(bool value) // Set different. control.BeepOnError = !value; - control.BeepOnError.Should().Be(!value);; + control.BeepOnError.Should().Be(!value); + ; control.IsHandleCreated.Should().BeFalse(); } @@ -642,7 +643,7 @@ public void MaskedTextBox_SelectedText_GetSet_ReturnsExpected(string mask, strin { Mask = mask, }; - + control.CreateControl(); control.Text = value; control.SelectionStart = 0; diff --git a/src/System.Windows.Forms/tests/UnitTests/NumericUpDownTests.cs b/src/System.Windows.Forms/tests/UnitTests/NumericUpDownTests.cs index 84838a6ddf2..2e899d735cc 100644 --- a/src/System.Windows.Forms/tests/UnitTests/NumericUpDownTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/NumericUpDownTests.cs @@ -672,7 +672,7 @@ public void NumericUpDown_DownButton_ValueEqualToMinimum_ValueRemainsSame() using NumericUpDown upDown = new() { Minimum = 10, - Value = 10 + Value = 10 }; upDown.DownButton(); diff --git a/src/System.Windows.Forms/tests/UnitTests/SerializableTypesTests.cs b/src/System.Windows.Forms/tests/UnitTests/SerializableTypesTests.cs index 7c6add1490a..d77e269a967 100644 --- a/src/System.Windows.Forms/tests/UnitTests/SerializableTypesTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/SerializableTypesTests.cs @@ -73,10 +73,10 @@ public void ImageListStreamer_RoundTripAndExchangeWithNet() string netBlob; using (ImageList imageList = new() - { - ImageSize = new Size(16, 16), - TransparentColor = Color.White - }) + { + ImageSize = new Size(16, 16), + TransparentColor = Color.White + }) { imageList.Images.Add(new Bitmap(16, 16)); netBlob = BinarySerialization.ToBase64String(imageList.ImageStream); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXResourceReaderTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXResourceReaderTests.cs index b3c0a489300..d09e8b38400 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXResourceReaderTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXResourceReaderTests.cs @@ -47,7 +47,7 @@ public void ResXResourceReader_Deserialize_AxHost_FormatterDisabled_Throws() using MemoryStream resourceStream = new(); using ResXResourceReader resxReader = new(resxPath); - Assert.Throws(() => resxReader.GetEnumerator()); + Assert.Throws(resxReader.GetEnumerator); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXSerializationBinderTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXSerializationBinderTests.cs index 681d0f8102b..a8f2d6d33b4 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXSerializationBinderTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResXSerializationBinderTests.cs @@ -10,7 +10,7 @@ namespace System.Resources.Tests; -public class ResXSerializationBinderTests +public class ResXSerializationBinderTests { [Fact] public void ResXSerializationBinder_BindToType_FullyQualifiedName() diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResxDataNodeTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResxDataNodeTests.cs index 9f845aad810..dd3d453f692 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResxDataNodeTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Resources/ResxDataNodeTests.cs @@ -86,8 +86,8 @@ public void ResxDataNode_RoundTrip_BinaryFormatted(object? value) Assert.Equal(value, deserializedDataNode.GetValue(typeResolver: null)); } - public static TheoryData RoundTrip_BinaryFormatted_TestData => new() - { + public static TheoryData RoundTrip_BinaryFormatted_TestData => + [ new RectangleF(10.0f, 20.0f, 30.0f, 40.0f), new PointF(1.0f, 2.0f), new List { "Jack", "Queen", "King" }, @@ -137,5 +137,5 @@ public void ResxDataNode_RoundTrip_BinaryFormatted(object? value) { DateTime.MinValue, DateTime.MaxValue }, { TimeSpan.MinValue, TimeSpan.MaxValue } }, - }; + ]; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs index 5ac09b4b4c8..24e12592c2b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs @@ -2638,7 +2638,7 @@ public unsafe void TestAccessibleObjectFromPoint_Button() IAccessible accessible = ppacc as IAccessible; Assert.NotNull(accessible); Assert.Equal("MSAA Button", accessible.accName); - Assert.True(((int)accessible.accState & 0x100000) != 0); // STATE_SYSTEM_FOCUSABLE + Assert.NotEqual(0, ((int)accessible.accState & 0x100000)); // STATE_SYSTEM_FOCUSABLE Assert.Equal(0x2b, accessible.accRole); // ROLE_SYSTEM_PUSHBUTTON Assert.Equal("Press", accessible.accDefaultAction); } @@ -2669,7 +2669,7 @@ public unsafe void TestAccessibleObjectFromPoint_ComboBox() IAccessible accessible = ppacc as IAccessible; Assert.NotNull(accessible); Assert.Null(accessible.accName); - Assert.True(((int)accessible.accState & 0x100000) != 0); // STATE_SYSTEM_FOCUSABLE + Assert.NotEqual(0, ((int)accessible.accState & 0x100000)); // STATE_SYSTEM_FOCUSABLE Assert.Equal(0x2a, accessible.accRole); // ROLE_SYSTEM_TEXT Assert.Null(accessible.accDefaultAction); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ButtonBase.ButtonBaseAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ButtonBase.ButtonBaseAccessibleObjectTests.cs index 490797935b6..9fa7d17d69d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ButtonBase.ButtonBaseAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ButtonBase.ButtonBaseAccessibleObjectTests.cs @@ -295,7 +295,7 @@ public ControlAccessibleObjectWithNotificationCounter(Control ownerControl, Func { _checkRaisedEvent = checkRaisedEvent; } - + internal int RaiseAutomationNotificationCallCount { get; private set; } internal override bool RaiseAutomationPropertyChangedEvent(UIA_PROPERTY_ID propertyId, VARIANT oldValue, VARIANT newValue) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/CheckBox.CheckBoxAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/CheckBox.CheckBoxAccessibleObjectTests.cs index ccb8a3b5eee..8822a6b274a 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/CheckBox.CheckBoxAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/CheckBox.CheckBoxAccessibleObjectTests.cs @@ -55,7 +55,7 @@ public void CheckBoxAccessibleObject_DefaultAction_CheckedIsTrue_ReturnsExpected using CheckBox checkBox = new(); checkBox.IsHandleCreated.Should().BeFalse(); - checkBox.AccessibilityObject.DefaultAction.Should().Be("Check"); + checkBox.AccessibilityObject.DefaultAction.Should().Be("Check"); checkBox.Checked = true; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ComboBox.ComboBoxAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ComboBox.ComboBoxAccessibleObjectTests.cs index b0e2d233460..f5e73cb6710 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ComboBox.ComboBoxAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ComboBox.ComboBoxAccessibleObjectTests.cs @@ -420,7 +420,7 @@ public void ComboBox_ReleaseUiaProvider_ClearsItemsAccessibleObjects() comboBox.ReleaseUiaProvider(comboBox.HWND); - Assert.Equal(0, accessibleObject.ItemAccessibleObjects.Count); + Assert.Empty(accessibleObject.ItemAccessibleObjects); Assert.True(comboBox.IsHandleCreated); } @@ -436,7 +436,7 @@ public void ComboBoxItems_Clear_ClearsItemsAccessibleObjects() comboBox.Items.Clear(); - Assert.Equal(0, accessibleObject.ItemAccessibleObjects.Count); + Assert.Empty(accessibleObject.ItemAccessibleObjects); Assert.True(comboBox.IsHandleCreated); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs index 04268534c4d..79a08c2e2a9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs @@ -225,14 +225,14 @@ public void ControlAccessibleObject_Description_GetWithAccessibleDescription_Ret public static TheoryData Handle_Set_DataTestData() { - return new TheoryData - { + return + [ null, IntPtr.Zero, new IntPtr(-1), new IntPtr(1), new IntPtr(250) - }; + ]; } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewAccessibleObjectTests.cs index d30cfa3dd30..aae4a8382e5 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewAccessibleObjectTests.cs @@ -1196,7 +1196,7 @@ public void DataGridViewAccessibleObject_GetColumnHeaders_ReturnEmptyArray_IfCol var columnHeaders = dataGridView.AccessibilityObject.GetColumnHeaders(); Assert.NotNull(columnHeaders); - Assert.Equal(0, columnHeaders.Length); + Assert.Empty(columnHeaders); Assert.False(dataGridView.IsHandleCreated); } @@ -1291,7 +1291,7 @@ public void DataGridViewAccessibleObject_GetRowHeaders_ReturnExpected_IfRowsHidd var rowHeaders = dataGridView.AccessibilityObject.GetRowHeaders(); Assert.NotNull(rowHeaders); - Assert.Equal(0, rowHeaders.Length); + Assert.Empty(rowHeaders); Assert.False(dataGridView.IsHandleCreated); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewButtonCellAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewButtonCellAccessibleObjectTests.cs index 150c55c85d5..a50e7a38cef 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewButtonCellAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewButtonCellAccessibleObjectTests.cs @@ -64,6 +64,6 @@ public void DataGridViewButtonCellAccessibleObject_DoDefaultAction_ThrowsExcepti AccessibleObject accessibleObject = cell.AccessibilityObject; Assert.Equal(-1, cell.RowIndex); - Assert.Throws(() => accessibleObject.DoDefaultAction()); + Assert.Throws(accessibleObject.DoDefaultAction); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs index f68dc944f2b..bf81bb6ff89 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs @@ -369,7 +369,7 @@ public void DataGridViewCellAccessibleObject_Value_NoOwner_ThrowsInvalidOperatio [MemberData(nameof(NoOwner_TestData))] public void DataGridViewCellAccessibleObject_DoDefaultAction_NoOwner_ThrowsInvalidOperationException(AccessibleObject accessibleObject) { - Assert.Throws(() => accessibleObject.DoDefaultAction()); + Assert.Throws(accessibleObject.DoDefaultAction); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCheckBoxCellAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCheckBoxCellAccessibleObjectTests.cs index d2c4fd4faed..0f7c78b19d9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCheckBoxCellAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCheckBoxCellAccessibleObjectTests.cs @@ -200,7 +200,7 @@ public void DataGridViewCheckBoxCellAccessibleObject_DoDefaultAction_ThrowsExcep using DataGridViewCheckBoxCell cell = new(); Assert.Equal(-1, cell.RowIndex); - Assert.Throws(() => cell.AccessibilityObject.DoDefaultAction()); + Assert.Throws(cell.AccessibilityObject.DoDefaultAction); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewLinkCellAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewLinkCellAccessibleObjectTests.cs index aecb22c38c9..08d982c0436 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewLinkCellAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewLinkCellAccessibleObjectTests.cs @@ -63,6 +63,6 @@ public void DataGridViewLinkCellAccessibleObject_DoDefaultAction_ThrowsException using DataGridViewLinkCell cell = new(); Assert.Equal(-1, cell.RowIndex); - Assert.Throws(() => cell.AccessibilityObject.DoDefaultAction()); + Assert.Throws(cell.AccessibilityObject.DoDefaultAction); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewRowAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewRowAccessibleObjectTests.cs index 4756fdf8619..f249f47c831 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewRowAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewRowAccessibleObjectTests.cs @@ -291,7 +291,7 @@ public void DataGridViewRowAccessibleObject_GetChildCount_NoDataGridView_Returns [MemberData(nameof(NoOwner_TestData))] public void DataGridViewRowAccessibleObject_GetFocused_NoOwner_ThrowsInvalidOperationException(AccessibleObject accessibleObject) { - Assert.Throws(() => accessibleObject.GetFocused()); + Assert.Throws(accessibleObject.GetFocused); } [Fact] @@ -322,7 +322,7 @@ public void DataGridViewRowAccessibleObject_GetSelected_Invoke_ReturnsSameInstan [MemberData(nameof(NoOwner_TestData))] public void DataGridViewRowAccessibleObject_GetSelected_NoOwner_ThrowsInvalidOperationException(AccessibleObject accessibleObject) { - Assert.Throws(() => accessibleObject.GetSelected()); + Assert.Throws(accessibleObject.GetSelected); } public static IEnumerable Navigate_TestData() diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DateTimePicker.DateTimePickerAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DateTimePicker.DateTimePickerAccessibleObjectTests.cs index bebc8bd658f..e6308dbdb9a 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DateTimePicker.DateTimePickerAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DateTimePicker.DateTimePickerAccessibleObjectTests.cs @@ -349,7 +349,7 @@ public void DateTimePickerAccessibleObject_KeyboardShortcut_ReturnsExpected() { using Form form = new(); using DateTimePicker dateTimePicker1 = new(); - using Label label1 = new (); + using Label label1 = new(); using DateTimePicker dateTimePicker2 = new(); dateTimePicker1.CustomFormat = "'Date&Time' hh:mm dd/MM"; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ErrorProviderAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ErrorProviderAccessibleObjectTests.cs index 4867932b73e..1d884b562f4 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ErrorProviderAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ErrorProviderAccessibleObjectTests.cs @@ -152,11 +152,11 @@ public void ErrorProvider_NameDoesNotEqualControlTypeOrChildName() // ToLower method used to be case insensitive. string errorWindowControlType = "group"; - string actualWindowAccessibleName = _errorWindow.AccessibilityObject.Name.ToLower(); + string actualWindowAccessibleName = _errorWindow.AccessibilityObject.Name.ToLowerInvariant(); Assert.NotEqual(errorWindowControlType, actualWindowAccessibleName); string controlItemControlType = "image"; - string actualItemAccessibleName = _controlItem1.AccessibilityObject.Name.ToLower(); + string actualItemAccessibleName = _controlItem1.AccessibilityObject.Name.ToLowerInvariant(); Assert.NotEqual(controlItemControlType, actualItemAccessibleName); Assert.NotEqual(actualWindowAccessibleName, actualItemAccessibleName); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/LabelAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/LabelAccessibleObjectTests.cs index 4d02d1a6417..65274a67634 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/LabelAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/LabelAccessibleObjectTests.cs @@ -168,7 +168,7 @@ public void LabelAccessibleObject_ThrowsArgumentNullException_WhenOwnerIsNull() [InlineData("Test Accessible Name", "Test Accessible Name", true)] [InlineData("", null, false)] [InlineData("", null, true)] - [InlineData(null, null, false)] + [InlineData(null, null, false)] [InlineData(null, null, true)] public void LabelAccessibleObject_Name_ReturnsExpected_WithVariousText(string labelText, string expectedName, bool useMnemonic) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBox.ListBoxItemAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBox.ListBoxItemAccessibleObjectTests.cs index ccacfbf6e06..c7cf6f35b7f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBox.ListBoxItemAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBox.ListBoxItemAccessibleObjectTests.cs @@ -200,4 +200,3 @@ public void Select_WithVariousFlags_ShouldNotThrow(AccessibleSelection flags) #nullable disable } - diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBoxAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBoxAccessibleObjectTests.cs index 20e1bb42e0d..102fe36c45e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBoxAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListBoxAccessibleObjectTests.cs @@ -212,7 +212,7 @@ public void ListBoxItemAccessibleObject_RemoveFromSelection() provider.RemoveFromSelection(); var indices = listBox.SelectedIndices; - Assert.Equal(1, indices.Count); + Assert.Single(indices); Assert.True(indices.Contains(2)); } @@ -353,5 +353,5 @@ public void TestHitTest_ListBoxNotCreated_ReturnsNull() listBox.IsHandleCreated.Should().BeFalse(); } - #nullable disable +#nullable disable } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListVIew.ListViewAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListVIew.ListViewAccessibleObjectTests.cs index 08635d23100..a59e368d9c2 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListVIew.ListViewAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListVIew.ListViewAccessibleObjectTests.cs @@ -958,7 +958,7 @@ public void ListViewAccessibleObject_GetSelectionInvoke_WithoutSelectedItems_Ret listView.Items.Add(listItem1); var listSelection = listView.AccessibilityObject.GetSelection(); - Assert.Equal(0, listSelection.Length); + Assert.Empty(listSelection); Assert.True(listView.IsHandleCreated); } @@ -976,7 +976,7 @@ public void ListViewAccessibleObject_GetSelectionInvoke_ReturnsExpected_IfHandle listView.Items.Add(listItem1); var listSelection = listView.AccessibilityObject.GetSelection(); - Assert.Equal(0, listSelection.Length); + Assert.Empty(listSelection); Assert.False(listView.IsHandleCreated); } @@ -1071,7 +1071,7 @@ public void ListViewAccessibleObject_GetSelectionInvoke_WithoutSelectedItems_Vir listItem1.SetItemIndex(listView, 0); var listSelection = listView.AccessibilityObject.GetSelection(); - Assert.Equal(0, listSelection.Length); + Assert.Empty(listSelection); Assert.True(listView.IsHandleCreated); } @@ -1101,7 +1101,7 @@ public void ListViewAccessibleObject_GetSelectionInvoke_VirtualMode_ReturnsExpec listItem1.SetItemIndex(listView, 0); var listSelection = listView.AccessibilityObject.GetSelection(); - Assert.Equal(0, listSelection.Length); + Assert.Empty(listSelection); Assert.False(listView.IsHandleCreated); } @@ -1304,7 +1304,7 @@ public void ListViewAccessibleObject_GetChild_ReturnsNull_IfIndexIsWrong(View vi [WinFormsTheory] [MemberData(nameof(ListViewAccessibleObject_GetChild_TestData))] - public void ListViewAccessibleObject_GetChild_ReturnsExpected_DetailsView(View view, bool showGroups, bool virtualMode) + public void ListViewAccessibleObject_GetChild_ReturnsExpected_DetailsView(View view, bool showGroups, bool virtualMode) { using ListView listView = GetListViewWithData(view, createControl: true, virtualMode, showGroups); List expectedValues = []; @@ -1773,4 +1773,3 @@ public void ListViewItemAccessibleObject_GetPropertyValue_CanSelectMultiple() Assert.True(result); } } - diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewGroup.ListViewGroupAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewGroup.ListViewGroupAccessibleObjectTests.cs index 46628ecd803..f9eef593d30 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewGroup.ListViewGroupAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewGroup.ListViewGroupAccessibleObjectTests.cs @@ -291,7 +291,7 @@ public void ListViewGroupAccessibleObject_Bounds_ReturnsCorrectValue() AccessibleObject group1AccObj = listGroup.AccessibilityObject; Assert.True(list.IsHandleCreated); - RECT groupRect = new(); + RECT groupRect = default; PInvokeCore.SendMessage(list, PInvoke.LVM_GETGROUPRECT, (WPARAM)listGroup.ID, ref groupRect); int actualWidth = group1AccObj.Bounds.Width; @@ -327,7 +327,7 @@ public void ListViewGroupAccessibleObject_Bounds_ReturnsCorrectValue_PostHandle( listView.Groups.Add(group); listView.Items.Add(new ListViewItem("a", group)); - RECT groupRect = new(); + RECT groupRect = default; PInvokeCore.SendMessage(listView, PInvoke.LVM_GETGROUPRECT, (WPARAM)group.ID, ref groupRect); AccessibleObject groupAccObj = group.AccessibilityObject; @@ -833,8 +833,8 @@ public void ListViewGroupAccessibleObject_GroupCollapsedStateChanged_IsExpected_ // GroupCollapsedStateChanged event should be raised // for the second group only in this specific case. - Assert.Equal(1, eventGroupIndices.Count); - Assert.Equal(1, eventGroupIndices[0]); + Assert.Single(eventGroupIndices); + Assert.Equal(1, eventGroupIndices[0]); // Make sure that we really cheched multiple selection case and the items // are still selected after keyboard navigation simulations. diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemAccessibleObjectTests.cs index fd7118e011f..590cdf04298 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemAccessibleObjectTests.cs @@ -486,8 +486,8 @@ public void ListViewItemAccessibleObject_FragmentNavigate_LastChild_ReturnsExpec Assert.NotNull(lastChild1); Assert.NotNull(lastChild2); - Assert.Equal(1, listView.Items[0].SubItems.Count); - Assert.Equal(1, listView.Items[1].SubItems.Count); + Assert.Single(listView.Items[0].SubItems); + Assert.Single(listView.Items[1].SubItems); listView.Items[0].SubItems.Add(new ListViewSubItem() { Text = $"SubItem 0" }); listView.Items[1].SubItems.Add(new ListViewSubItem() { Text = $"SubItem 0" }); @@ -526,8 +526,8 @@ public void ListViewItemAccessibleObject_FragmentNavigate_LastChild_ReturnsExpec Assert.NotNull(lastChild1); Assert.NotNull(lastChild2); - Assert.Equal(1, listView.Items[0].SubItems.Count); - Assert.Equal(1, listView.Items[1].SubItems.Count); + Assert.Single(listView.Items[0].SubItems); + Assert.Single(listView.Items[1].SubItems); Assert.Equal(createControl, listView.IsHandleCreated); } @@ -1624,7 +1624,7 @@ public void ListViewItemAccessibleObject_GetChildIndex_ReturnsExpected_Image(boo ListViewItem listViewItem = new("Item 1", imageIndex: hasImage ? 0 : -1); listView.Items.Add(listViewItem); var accessibleObject = (ListViewItemDetailsAccessibleObject)listView.Items[0].AccessibilityObject; - + Assert.Equal(expectedFirstSubItemIndex, accessibleObject.GetChildIndex(listView.Items[0].SubItems[0].AccessibilityObject)); Assert.False(listView.IsHandleCreated); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemBaseAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemBaseAccessibleObjectTests.cs index 826e4b57ea8..991cd174f1e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemBaseAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemBaseAccessibleObjectTests.cs @@ -83,12 +83,12 @@ public void ListViewItemBaseAccessibleObject_DoDefaultAction_DoesNothing_IfContr AccessibleObject accessibleObject = item.AccessibilityObject; - Assert.False((accessibleObject.State & AccessibleStates.Selected) != 0); + accessibleObject.State.Should().NotHaveFlag(AccessibleStates.Selected); accessibleObject.DoDefaultAction(); - Assert.False((accessibleObject.State & AccessibleStates.Selected) != 0); - Assert.False(control.IsHandleCreated); + accessibleObject.State.Should().NotHaveFlag(AccessibleStates.Selected); + control.IsHandleCreated.Should().BeFalse(); } [WinFormsFact] @@ -118,12 +118,12 @@ public void ListViewItemBaseAccessibleObject_DoDefaultAction_IfControlIsNotCreat AccessibleObject accessibleObject = item.AccessibilityObject; - Assert.False((accessibleObject.State & AccessibleStates.Selected) != 0); + accessibleObject.State.Should().NotHaveFlag(AccessibleStates.Selected); accessibleObject.DoDefaultAction(); - Assert.False((accessibleObject.State & AccessibleStates.Selected) != 0); - Assert.False(control.IsHandleCreated); + accessibleObject.State.Should().NotHaveFlag(AccessibleStates.Selected); + control.IsHandleCreated.Should().BeFalse(); } [WinFormsFact] @@ -136,12 +136,12 @@ public void ListViewItemBaseAccessibleObject_DoDefaultAction_WorksExpected() AccessibleObject accessibleObject = item.AccessibilityObject; - Assert.False((accessibleObject.State & AccessibleStates.Selected) != 0); + accessibleObject.State.Should().NotHaveFlag(AccessibleStates.Selected); accessibleObject.DoDefaultAction(); - Assert.True((accessibleObject.State & AccessibleStates.Selected) != 0); - Assert.True(control.IsHandleCreated); + accessibleObject.State.Should().HaveFlag(AccessibleStates.Selected); + control.IsHandleCreated.Should().BeTrue(); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemWithImageAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemWithImageAccessibleObjectTests.cs index b3bf8f83d77..c2536a35d71 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemWithImageAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewItemWithImageAccessibleObjectTests.cs @@ -37,7 +37,7 @@ public void ListViewItemListAccessibleObject_FragmentNavigate_Children_IsExpecte SmallImageList = imageCollection, LargeImageList = imageCollection }; - if(!control.IsHandleCreated) + if (!control.IsHandleCreated) { Assert.NotEqual(IntPtr.Zero, control.Handle); } @@ -130,10 +130,10 @@ public void ListViewItemListAccessibleObject_GetChildCount_WithImage(View view) public static TheoryData GetViewTheoryData() { - return new TheoryData - { + return + [ View.LargeIcon, View.SmallIcon - }; + ]; } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewSubItem.ListViewSubItemAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewSubItem.ListViewSubItemAccessibleObjectTests.cs index 0f09632baf0..96d8a566d7f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewSubItem.ListViewSubItemAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ListViewItem.ListViewSubItem.ListViewSubItemAccessibleObjectTests.cs @@ -1018,7 +1018,7 @@ private void ListViewSubItemAccessibleObject_GetColumnHeaderItems_IsExpected_Int AccessibleObject columnHeaderAccessibleObject = columns[i].AccessibilityObject; IRawElementProviderSimple.Interface[] columnHeaderItems = subItemAccessibleObject.GetColumnHeaderItems(); - Assert.Equal(1, columnHeaderItems.Length); + Assert.Single(columnHeaderItems); Assert.Same(columnHeaderAccessibleObject, columnHeaderItems[0]); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MenuStrip.MenuStripAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MenuStrip.MenuStripAccessibleObjectTests.cs index 187f1b0475d..bb49e76cd20 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MenuStrip.MenuStripAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MenuStrip.MenuStripAccessibleObjectTests.cs @@ -945,7 +945,7 @@ private MenuStrip CreateMenuStrip( return menuStrip; - ToolStripItem CreateMenuItem() + static ToolStripItem CreateMenuItem() { return new ToolStripMenuItem() { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarBodyAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarBodyAccessibleObjectTests.cs index 806f0eed61d..35c11415e0e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarBodyAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarBodyAccessibleObjectTests.cs @@ -312,8 +312,8 @@ public void CalendarBodyAccessibleObject_GetRowHeaders_ReturnsCorrectType() } [WinFormsTheory] - [InlineData(null, false)] - [InlineData("CustomName", false)] + [InlineData(null, false)] + [InlineData("CustomName", false)] [InlineData("AccessibleName", false, true)] public void CalendarBodyAccessibleObject_CanGetNameInternal_ShouldBeConsistentlyFalse(string name, bool expected, bool isAccessibleName = false) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarTodayLinkAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarTodayLinkAccessibleObjectTests.cs index 93d5c955b5c..2b154c21a63 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarTodayLinkAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/MonthCalendar.CalendarTodayLinkAccessibleObjectTests.cs @@ -14,7 +14,7 @@ public void CalendarTodayLinkAccessibleObject_ctor_default() using MonthCalendar control = new(); var controlAccessibleObject = (MonthCalendarAccessibleObject)control.AccessibilityObject; CalendarTodayLinkAccessibleObject todayLinkAccessibleObject = new(controlAccessibleObject); - + controlAccessibleObject.Should().BeEquivalentTo(todayLinkAccessibleObject.TestAccessor().Dynamic._monthCalendarAccessibleObject); control.IsHandleCreated.Should().BeFalse(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/PictureBox.PictureBoxAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/PictureBox.PictureBoxAccessibleObjectTests.cs index f7ded4d25f5..02b20bd4c83 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/PictureBox.PictureBoxAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/PictureBox.PictureBoxAccessibleObjectTests.cs @@ -147,4 +147,3 @@ public void PictureBoxAccessibleObject_GetPropertyValue_ControlType_IsExpected_F Assert.False(pictureBox.IsHandleCreated); } } - diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs index 36483e1c060..c6e64b5d683 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/StatusStrip.StatusStripAccessibleObjectTests.cs @@ -926,7 +926,7 @@ private StatusStrip CreateStatusStrip( return statusStrip; - ToolStripItem CreateStatusStripItem() + static ToolStripItem CreateStatusStripItem() { return new ToolStripStatusLabel() { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TabControl.TabControlAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TabControl.TabControlAccessibleObjectTests.cs index 2fee6f16117..078e38d4b34 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TabControl.TabControlAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TabControl.TabControlAccessibleObjectTests.cs @@ -459,7 +459,7 @@ public void TabControlAccessibleObject_GetSelection_ReturnsExpected(int selected TabControlAccessibleObject accessibleObject = Assert.IsType(tabControl.AccessibilityObject); IRawElementProviderSimple.Interface[] selectedAccessibleObjects = accessibleObject.GetSelection(); - Assert.Equal(1, selectedAccessibleObjects.Length); + Assert.Single(selectedAccessibleObjects); Assert.Equal(pages[selectedIndex].TabAccessibilityObject, selectedAccessibleObjects[0]); Assert.True(pages[0].IsHandleCreated); Assert.Equal(selectedIndex == 1, pages[1].IsHandleCreated); @@ -481,7 +481,7 @@ public void TabControlAccessibleObject_GetSelection_ReturnsEmptyArray_IfHandleIs TabControlAccessibleObject accessibleObject = Assert.IsType(tabControl.AccessibilityObject); IRawElementProviderSimple.Interface[] selectedAccessibleObjects = accessibleObject.GetSelection(); - Assert.Equal(0, selectedAccessibleObjects.Length); + Assert.Empty(selectedAccessibleObjects); Assert.False(pages[0].IsHandleCreated); Assert.False(pages[1].IsHandleCreated); Assert.False(pages[2].IsHandleCreated); @@ -497,7 +497,7 @@ public void TabControlAccessibleObject_GetSelection_ReturnsEmptyArray_IfTabPages TabControlAccessibleObject accessibleObject = Assert.IsType(tabControl.AccessibilityObject); IRawElementProviderSimple.Interface[] selectedAccessibleObjects = accessibleObject.GetSelection(); - Assert.Equal(0, selectedAccessibleObjects.Length); + Assert.Empty(selectedAccessibleObjects); Assert.True(tabControl.IsHandleCreated); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripAccessibleObjectTests.cs index a8ab0b663b6..11634f6397c 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripAccessibleObjectTests.cs @@ -986,7 +986,7 @@ private ToolStrip CreateToolStrip( return toolStrip; - ToolStripItem CreateToolStripItem() + static ToolStripItem CreateToolStripItem() { return new ToolStripButton() { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripDropDownButton.ToolStripDropDownButtonAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripDropDownButton.ToolStripDropDownButtonAccessibleObjectTests.cs index 986a7bda537..a22a16325c8 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripDropDownButton.ToolStripDropDownButtonAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripDropDownButton.ToolStripDropDownButtonAccessibleObjectTests.cs @@ -104,7 +104,7 @@ public void ToolStripDropDownButton_ConstructorParameters_ShouldInitializeCorrec string name = "Test name"; ToolStripItem[] dropDownItems = [new ToolStripMenuItem("Test item")]; - ToolStripDropDownButton CreateToolStripDropDownButton(string text = null, Bitmap image = null, EventHandler onClick = null, string name = null, ToolStripItem[] dropDownItems = null) + static ToolStripDropDownButton CreateToolStripDropDownButton(string text = null, Bitmap image = null, EventHandler onClick = null, string name = null, ToolStripItem[] dropDownItems = null) { ToolStripDropDownButton toolStripDropDownButton = new(text, image, dropDownItems); toolStripDropDownButton.Click += onClick; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripItemAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripItemAccessibleObjectTests.cs index b6644de0043..d82aca0716b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripItemAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripItemAccessibleObjectTests.cs @@ -309,7 +309,7 @@ public void ToolStripItemAccessibleObject_FragmentNavigate_Sibling_ReturnExpecte { using ToolStrip toolStrip = new() { AutoSize = false, Size = new(300, 30) }; - ToolStripItem CreateSkippedItem() + static ToolStripItem CreateSkippedItem() { return new ToolStripControlHost(new Label()); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripMenuItem.ToolStripMenuItemAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripMenuItem.ToolStripMenuItemAccessibleObjectTests.cs index 742eaf0b322..750ff37932f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripMenuItem.ToolStripMenuItemAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripMenuItem.ToolStripMenuItemAccessibleObjectTests.cs @@ -133,7 +133,7 @@ public void ToolStripMenuItemAccessibleObject_GetPropertyValue_PositionInSet_Ret menuStrip.Items.Add(item1); menuStrip.PerformLayout(); - Assert.Equal(1, menuStrip.Items.Count); + Assert.Single(menuStrip.Items); Assert.Equal(1, (int)item1.AccessibilityObject.GetPropertyValue(UIA_PROPERTY_ID.UIA_PositionInSetPropertyId)); using ToolStripSeparator separator = new(); @@ -173,7 +173,7 @@ public void ToolStripMenuItemAccessibleObject_GetPropertyValue_SizeOfSet_Returns menuStrip.Items.Add(item1); menuStrip.PerformLayout(); - Assert.Equal(1, menuStrip.Items.Count); + Assert.Single(menuStrip.Items); Assert.Equal(1, (int)item1.AccessibilityObject.GetPropertyValue(UIA_PROPERTY_ID.UIA_SizeOfSetPropertyId)); using ToolStripSeparator separator = new(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripOverflow.ToolStripOverflowAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripOverflow.ToolStripOverflowAccessibleObjectTests.cs index c815835a768..9d2ee56cdea 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripOverflow.ToolStripOverflowAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/ToolStripOverflow.ToolStripOverflowAccessibleObjectTests.cs @@ -209,7 +209,7 @@ private static ToolStrip CreateToolStripWithOverflow(int itemCount) return toolStrip; - ToolStripItem CreateItem(ToolStripItemAlignment align) + static ToolStripItem CreateItem(ToolStripItemAlignment align) { return new ToolStripButton { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs index 49ff3cfc123..c557ec7df6b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs @@ -70,7 +70,7 @@ public static IEnumerable TrackBarAccessibleObject_DecreaseButtonName_ { foreach (bool rightToLeftLayout in new[] { true, false }) { - if (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false) + if (rightToLeft == RightToLeft.Yes && !rightToLeftLayout) { continue; } @@ -105,7 +105,7 @@ public static IEnumerable TrackBarAccessibleObject_IncreaseButtonName_ { foreach (bool rightToLeftLayout in new[] { true, false }) { - if (orientation == Orientation.Vertical || (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false)) + if (orientation == Orientation.Vertical || (rightToLeft == RightToLeft.Yes && !rightToLeftLayout)) { foreach (bool createControl in new[] { true, false }) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs index 9970b4acb8c..783ef9a1595 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs @@ -70,7 +70,7 @@ public static IEnumerable TrackBarAccessibleObject_IncreaseButtonName_ { foreach (bool rightToLeftLayout in new[] { true, false }) { - if (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false) + if (rightToLeft == RightToLeft.Yes && !rightToLeftLayout) { continue; } @@ -105,7 +105,7 @@ public static IEnumerable TrackBarAccessibleObject_DecreaseButtonName_ { foreach (bool rightToLeftLayout in new[] { true, false }) { - if (orientation == Orientation.Vertical || (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false)) + if (orientation == Orientation.Vertical || (rightToLeft == RightToLeft.Yes && !rightToLeftLayout)) { foreach (bool createControl in new[] { true, false }) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeNode.TreeNodeAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeNode.TreeNodeAccessibleObjectTests.cs index d2f862740a1..123befe5b80 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeNode.TreeNodeAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeNode.TreeNodeAccessibleObjectTests.cs @@ -15,7 +15,7 @@ public void TreeNodeAccessibleObject_Ctor_Default() using TreeView control = new(); TreeNode node = new(control); - node.AccessibilityObject.Should().NotBeNull(); + node.AccessibilityObject.Should().NotBeNull(); node.AccessibilityObject.CanGetDefaultActionInternal.Should().BeFalse(); node.AccessibilityObject.CanGetNameInternal.Should().BeFalse(); node.AccessibilityObject.IsItemSelected.Should().BeFalse(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeView.TreeViewAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeView.TreeViewAccessibleObjectTests.cs index 2def0c36287..59af4a6e859 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeView.TreeViewAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/TreeView.TreeViewAccessibleObjectTests.cs @@ -267,7 +267,7 @@ public void TreeNodeAccessibleObject_HitTest_ReturnsNode() } [WinFormsTheory] - [InlineData(new string[] { "Node 1", "Node 2", "Node 3" }, 3, false)] + [InlineData(new string[] { "Node 1", "Node 2", "Node 3" }, 3, false)] [InlineData(new string[] { }, 0, false)] [InlineData(new string[] { "Node 1", "Node 2", "Node 3" }, 3, true)] [InlineData(new string[] { }, 0, true)] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs index 63d88c318f6..9a832be2150 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs @@ -387,7 +387,7 @@ public void Application_Exit_MDIFormClosing_Order(int mainMDIFormCountParam, int Application.EnableVisualStyles(); using Form mainForm = new Form(); - Assert.Equal(0, Application.OpenForms.Count); + Assert.Empty(Application.OpenForms); Dictionary formClosingProcessed = new(mainMDIFormCount); Dictionary formClosedProcessed = new(mainMDIFormCount); bool exitCalled = false; @@ -525,7 +525,7 @@ public void Application_Exit_OpenForms_Show_Close(int childFormCountParam, int r Application.EnableVisualStyles(); using Form mainForm = new Form(); - Assert.Equal(0, Application.OpenForms.Count); + Assert.Empty(Application.OpenForms); int formClosingProcessed = 0; Form lastChild = null; bool exitCalled = false; @@ -611,7 +611,7 @@ public void Application_Exit_OpenForms_Show_Close(int childFormCountParam, int r if (!cancel) { - Assert.Equal(0, Application.OpenForms.Count); + Assert.Empty(Application.OpenForms); Assert.Equal(1 + childFormCount + addFormCount, formClosingProcessed); } else diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AutoCompleteStringCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AutoCompleteStringCollectionTests.cs index bcfd5e14352..7df6b6c5c15 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AutoCompleteStringCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AutoCompleteStringCollectionTests.cs @@ -10,15 +10,15 @@ public class AutoCompleteStringCollectionTests [Fact] public void Ctor_Default() { - AutoCompleteStringCollection collection = new(); - Assert.Equal(0, collection.Count); + AutoCompleteStringCollection collection = []; + Assert.Empty(collection); Assert.False(collection.IsReadOnly); } [WinFormsFact] public void AutoCompleteStringCollection_AddRange_Invoke_Success() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; string[] values = ["1", "2", "3"]; collection.AddRange(values); @@ -31,7 +31,7 @@ public void AutoCompleteStringCollection_AddRange_Invoke_Success() [WinFormsFact] public void AutoCompleteStringCollection_AddRange_NullValue_ThrowsArgumentNullException() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; Assert.Throws("value", () => collection.AddRange(null)); } @@ -39,15 +39,14 @@ public void AutoCompleteStringCollection_AddRange_NullValue_ThrowsArgumentNullEx [WinFormsFact] public void AutoCompleteStringCollection_AddRange_NullValues_Nop() { - AutoCompleteStringCollection collection = new(); - collection.AddRange([null!]); + AutoCompleteStringCollection collection = [null!]; Assert.Empty(collection); } [WinFormsFact] public void AutoCompleteStringCollection_Add_NullValue_ThrowsArgumentNullException() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; Assert.Throws("value", () => collection.AddRange(null!)); } #nullable disable @@ -55,7 +54,7 @@ public void AutoCompleteStringCollection_Add_NullValue_ThrowsArgumentNullExcepti [WinFormsFact] public void AutoCompleteStringCollection_Contains_Invoke_ReturnsExpected() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; string s = "value"; collection.Add(s); @@ -67,7 +66,7 @@ public void AutoCompleteStringCollection_Contains_Invoke_ReturnsExpected() [WinFormsFact] public void AutoCompleteStringCollection_Contains_Empty_ReturnsFalse() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; Assert.False(collection.Contains("value")); Assert.False(collection.Contains(null)); @@ -95,7 +94,7 @@ public void AutoCompleteStringCollection_IListContains_Empty_ReturnsFalse() [WinFormsFact] public void AutoCompleteStringCollection_IndexOf_Invoke_ReturnsExpected() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; string s = "value"; collection.Add(s); @@ -107,7 +106,7 @@ public void AutoCompleteStringCollection_IndexOf_Invoke_ReturnsExpected() [WinFormsFact] public void AutoCompleteStringCollection_IndexOf_Empty_ReturnsFalse() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; Assert.Equal(-1, collection.IndexOf("value")); Assert.Equal(-1, collection.IndexOf(null)); @@ -135,7 +134,7 @@ public void AutoCompleteStringCollection_IListIndexOf_Empty_ReturnsMinusOne() [WinFormsFact] public void AutoCompleteStringCollection_Insert_String_Success() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; string s = "value1"; collection.Add("value2"); collection.Insert(1, s); @@ -146,10 +145,9 @@ public void AutoCompleteStringCollection_Insert_String_Success() [WinFormsFact] public void AutoCompleteStringCollection_Insert_AlreadyInOtherCollection_GetReturnsExpected() { - AutoCompleteStringCollection collection = new(); - collection.Add("value1"); + AutoCompleteStringCollection collection = ["value1"]; - AutoCompleteStringCollection otherCollection = new(); + AutoCompleteStringCollection otherCollection = []; string s = "value2"; otherCollection.Add(s); @@ -166,7 +164,7 @@ public void AutoCompleteStringCollection_Insert_AlreadyInOtherCollection_GetRetu [InlineData(1)] public void AutoCompleteStringCollection_Insert_InvalidIndex_ThrowsArgumentOutOfRangeException(int index) { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; Assert.Throws("index", () => collection.Insert(index, "value")); } @@ -211,8 +209,7 @@ public void AutoCompleteStringCollection_IListInsert_NullItem_Nop() [WinFormsFact] public void AutoCompleteStringCollection_Remove_String_Success() { - AutoCompleteStringCollection collection = new(); - collection.Add("value"); + AutoCompleteStringCollection collection = ["value"]; // Remove null. collection.Remove(null); @@ -255,8 +252,7 @@ public void AutoCompleteStringCollection_IListRemove_InvalidItem_Nop(object valu [WinFormsFact] public void AutoCompleteStringCollection_CopyTo_NonEmpty_Success() { - AutoCompleteStringCollection collection = new(); - collection.Add("value"); + AutoCompleteStringCollection collection = ["value"]; string[] array = ["1", "2", "3"]; collection.CopyTo(array, 1); @@ -266,7 +262,7 @@ public void AutoCompleteStringCollection_CopyTo_NonEmpty_Success() [WinFormsFact] public void AutoCompleteStringCollection_CopyTo_Empty_Nop() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; string[] array = ["1", "2", "3"]; collection.CopyTo(array, 0); Assert.Equal(new string[] { "1", "2", "3" }, array); @@ -275,7 +271,7 @@ public void AutoCompleteStringCollection_CopyTo_Empty_Nop() [WinFormsFact] public void AutoCompleteStringCollection_GetEnumerator_InvokeEmpty_ReturnsExpected() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; IEnumerator enumerator = collection.GetEnumerator(); for (int i = 0; i < 2; i++) @@ -297,8 +293,7 @@ public void AutoCompleteStringCollection_GetEnumerator_InvokeEmpty_ReturnsExpect [WinFormsFact] public void AutoCompleteStringCollection_GetEnumerator_InvokeNotEmpty_ReturnsExpected() { - AutoCompleteStringCollection collection = new(); - collection.Add("2"); + AutoCompleteStringCollection collection = ["2"]; IEnumerator enumerator = collection.GetEnumerator(); for (int i = 0; i < 2; i++) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHost.PropertyBagStreamTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHost.PropertyBagStreamTests.cs index 0a92c4373e0..9e701048f86 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHost.PropertyBagStreamTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHost.PropertyBagStreamTests.cs @@ -29,12 +29,12 @@ public void PropertyBagStream_WriteReadRoundTrip_FormatterEnabled() AxHost.PropertyBagStream newBag = new(stream); - VARIANT integer = new(); + VARIANT integer = default; hr = newBag.Read("Integer", ref integer, null); Assert.True(hr.Succeeded); Assert.Equal(42, (int)integer); - VARIANT dispatch = new(); + VARIANT dispatch = default; hr = newBag.Read("Object", ref dispatch, null); Assert.True(hr.Succeeded); Assert.Equal(obj.Name, ((NameClass)dispatch.ToObject()).Name); @@ -79,14 +79,14 @@ public void PropertyBagStream_WriteReadRoundTrip_Primitives_FormatterDisabled(ob stream.Position = 0; IPropertyBag.Interface newBag = new AxHost.PropertyBagStream(stream); - using VARIANT result = new(); + using VARIANT result = default; hr = newBag.Read(name, &result, null); Assert.True(hr.Succeeded); Assert.Equal(variant.ToObject(), result.ToObject()); } - public static TheoryData TestData_PrimitiveValues => new() - { + public static TheoryData TestData_PrimitiveValues => + [ int.MaxValue, uint.MaxValue, long.MaxValue, @@ -104,7 +104,7 @@ public void PropertyBagStream_WriteReadRoundTrip_Primitives_FormatterDisabled(ob DateTime.MaxValue, decimal.MaxValue, "RightRound" - }; + ]; [Serializable] private class NameClass diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHostTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHostTests.cs index 97b45434bd9..27ed2023e5b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHostTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxHostTests.cs @@ -1380,7 +1380,7 @@ public void AxHost_CreateControl_ValidClsid_Success() public void AxHost_CreateControl_InvalidClsid_ThrowsCOMException() { using SubAxHost control = new(EmptyClsidString); - Assert.Throws(() => control.CreateControl()); + Assert.Throws(control.CreateControl); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs index 352476de300..f19721e2579 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs @@ -1,4 +1,7 @@ -using System.ComponentModel; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; using System.Reflection; namespace System.Windows.Forms.Tests; @@ -34,7 +37,7 @@ public void AxSystemMonitor_WhenInitialized_ExpectsProperties() string assemblyNameFromType = assembly.GetName().Name; List testingControlProps = []; - foreach(PropertyDescriptor prop in properties) + foreach (PropertyDescriptor prop in properties) { string assemblyFromTestingControl = prop.ComponentType.Assembly.GetName().Name; if (!string.IsNullOrEmpty(assemblyFromTestingControl) @@ -45,7 +48,7 @@ public void AxSystemMonitor_WhenInitialized_ExpectsProperties() } List testingControlEvents = []; - foreach(EventDescriptor singleEvent in events) + foreach (EventDescriptor singleEvent in events) { string assemblyFromTestingControl = singleEvent.ComponentType.Assembly.GetName().Name; if (!string.IsNullOrEmpty(assemblyFromTestingControl) @@ -59,7 +62,7 @@ public void AxSystemMonitor_WhenInitialized_ExpectsProperties() TypeInfo assemblyTypeInfo = assembly.GetType(assemblyType.FullName).GetTypeInfo(); Assert.True(testingControlProps.All(p => assemblyTypeInfo.DeclaredProperties.Any(ap => ap.Name == p))); Assert.True(testingControlEvents.All(e => assemblyTypeInfo.DeclaredEvents.Any(ae => ae.Name == e))); - } + } public void Dispose() { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectTests.cs index b5f1f35fe42..143f7b6b6ae 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectTests.cs @@ -123,11 +123,11 @@ public void NrbfDecoder_SuccessfullyDecode(object value) } } - public static TheoryData BinaryFormattedObjects_TestData => new() - { - new PointF(), + public static TheoryData BinaryFormattedObjects_TestData => + [ + default(PointF), new PointF[] { default }, - new RectangleF(), + default(RectangleF), new RectangleF[] { default }, new DateTime[] { default }, new ImageListStreamer(new ImageList()), @@ -136,7 +136,7 @@ public void NrbfDecoder_SuccessfullyDecode(object value) new OwnerDrawPropertyBag(), new TreeNode(), new ListViewItem.ListViewSubItem() - }; + ]; [WinFormsTheory] [MemberData(nameof(Control_DesignerVisibleProperties_TestData))] @@ -148,7 +148,7 @@ public void Control_BinaryFormatted_DesignerVisibleProperties(object value, stri { var propertyDescriptors = TypeDescriptor.GetProperties(value, s_visible); - List binaryFormattedProperties = new(); + List binaryFormattedProperties = []; foreach (PropertyDescriptor property in propertyDescriptors) { Type propertyType = property.PropertyType; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormatUtilitiesTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormatUtilitiesTests.cs index 4261172e847..3459743c23b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormatUtilitiesTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormatUtilitiesTests.cs @@ -41,8 +41,8 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals // Primitive types as defined by the NRBF spec. // https://learn.microsoft.com/dotnet/api/system.formats.nrbf.primitivetyperecord - public static TheoryData PrimitiveObjects_TheoryData => new() - { + public static TheoryData PrimitiveObjects_TheoryData => + [ (byte)1, (sbyte)2, (short)3, @@ -55,10 +55,10 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals 10.0, 'a', true - }; + ]; - public static TheoryData KnownObjects_TheoryData => new() - { + public static TheoryData KnownObjects_TheoryData => + [ "string", DateTime.Now, TimeSpan.FromHours(1), @@ -72,10 +72,10 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals new Size(int.MaxValue, int.MinValue), new SizeF(float.MaxValue, float.MinValue), Color.Red - }; + ]; - public static TheoryData PrimitiveListObjects_TheoryData => new() - { + public static TheoryData PrimitiveListObjects_TheoryData => + [ new List { false, true }, new List { char.MinValue, char.MaxValue }, new List { byte.MinValue, byte.MaxValue }, @@ -92,10 +92,10 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals new List { DateTime.MinValue, DateTime.MaxValue }, new List { TimeSpan.MinValue, TimeSpan.MaxValue }, new List { "a", "b", "c" } - }; + ]; - public static TheoryData PrimitiveArrayObjects_TheoryData => new() - { + public static TheoryData PrimitiveArrayObjects_TheoryData => + [ new bool[] { false, true }, new char[] { char.MinValue, char.MaxValue }, new byte[] { byte.MinValue, byte.MaxValue }, @@ -112,10 +112,10 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals new DateTime[] { DateTime.MinValue, DateTime.MaxValue }, new TimeSpan[] { TimeSpan.MinValue, TimeSpan.MaxValue }, new string[] { "a", "b", "c" } - }; + ]; - public static TheoryData PrimitiveArrayListObjects_TheoryData => new() - { + public static TheoryData PrimitiveArrayListObjects_TheoryData => + [ new ArrayList { null }, new ArrayList { null, "something" }, new ArrayList { false, true }, @@ -134,10 +134,10 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals new ArrayList { DateTime.MinValue, DateTime.MaxValue }, new ArrayList { TimeSpan.MinValue, TimeSpan.MaxValue }, new ArrayList { "a", "b", "c" } - }; + ]; - public static TheoryData PrimitiveTypeHashtables_TheoryData => new() - { + public static TheoryData PrimitiveTypeHashtables_TheoryData => + [ new Hashtable { { "bool", true } }, new Hashtable { { "char", 'a' } }, new Hashtable { { "byte", (byte)1 } }, @@ -154,21 +154,21 @@ private void WriteObjectToStream(object value, bool restrictSerialization = fals new Hashtable { { "DateTime", DateTime.Now } }, new Hashtable { { "TimeSpan", TimeSpan.FromHours(1) } }, new Hashtable { { "string", "test" } } - }; + ]; - public static TheoryData NotSupportedException_TestData => new() - { + public static TheoryData NotSupportedException_TestData => + [ new NotSupportedException(), new NotSupportedException("Error message"), new NotSupportedException(null) - }; + ]; - public static TheoryData Lists_UnsupportedTestData => new() - { + public static TheoryData Lists_UnsupportedTestData => + [ new List(), new List(), new List<(int, int)>() - }; + ]; [Theory] [MemberData(nameof(PrimitiveObjects_TheoryData))] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingContextTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingContextTests.cs index becb3221843..4ac6d1ea272 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingContextTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingContextTests.cs @@ -25,7 +25,7 @@ public void BindingContext_ICollection_GetProperties_ReturnsExpected() ICollection context = new BindingContext(); Assert.False(context.IsSynchronized); Assert.Same(context, context.SyncRoot); - Assert.Equal(0, context.Count); + Assert.Empty(context); Assert.Empty(context); } @@ -525,7 +525,7 @@ public void BindingContext_Item_GetNoSuchDataSourceWithDataMember_AddsToCollecti Assert.Equal(0, manager.Position); Assert.Equal(expectedCount, ((ICollection)context).Count); Assert.Same(manager, context[dataSource, dataMember]); - Assert.Same(manager, context[dataSource, dataMember.ToLower()]); + Assert.Same(manager, context[dataSource, dataMember.ToLowerInvariant()]); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingMemberInfoTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingMemberInfoTests.cs index a767302aac1..7743442ed61 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingMemberInfoTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingMemberInfoTests.cs @@ -9,7 +9,7 @@ public class BindingMemberInfoTests [Fact] public void Ctor_Default() { - BindingMemberInfo info = new(); + BindingMemberInfo info = default; Assert.Empty(info.BindingPath); Assert.Empty(info.BindingField); Assert.Empty(info.BindingMember); @@ -39,16 +39,16 @@ public static IEnumerable Equals_TestData() yield return new object[] { new BindingMemberInfo("Some.Other"), new BindingMemberInfo("Some2.Other"), false }; yield return new object[] { new BindingMemberInfo("Some.Other"), new BindingMemberInfo("Some.Other2"), false }; yield return new object[] { new BindingMemberInfo("Some.Other"), new BindingMemberInfo("Some"), false }; - yield return new object[] { new BindingMemberInfo("Some.Other"), new BindingMemberInfo(), false }; + yield return new object[] { new BindingMemberInfo("Some.Other"), default(BindingMemberInfo), false }; yield return new object[] { new BindingMemberInfo("Some"), new BindingMemberInfo("Some"), true }; yield return new object[] { new BindingMemberInfo("Some"), new BindingMemberInfo("Some2"), false }; yield return new object[] { new BindingMemberInfo("Some"), new BindingMemberInfo("Some.Other"), false }; - yield return new object[] { new BindingMemberInfo("Some.Other"), new BindingMemberInfo(), false }; + yield return new object[] { new BindingMemberInfo("Some.Other"), default(BindingMemberInfo), false }; - yield return new object[] { new BindingMemberInfo(), new BindingMemberInfo(), true }; - yield return new object[] { new BindingMemberInfo(), new BindingMemberInfo(""), true }; - yield return new object[] { new BindingMemberInfo(), new BindingMemberInfo("Some.Other"), false }; + yield return new object[] { default(BindingMemberInfo), default(BindingMemberInfo), true }; + yield return new object[] { default(BindingMemberInfo), new BindingMemberInfo(""), true }; + yield return new object[] { default(BindingMemberInfo), new BindingMemberInfo("Some.Other"), false }; yield return new object[] { new BindingMemberInfo("Some.Other"), new(), false }; yield return new object[] { new BindingMemberInfo("Some.Other"), null, false }; @@ -69,7 +69,7 @@ public void Equals_Invoke_ReturnsExpected(BindingMemberInfo info, object other, public static IEnumerable GetHashCode_TestData() { - yield return new object[] { new BindingMemberInfo() }; + yield return new object[] { default(BindingMemberInfo) }; yield return new object[] { new BindingMemberInfo("Some") }; yield return new object[] { new BindingMemberInfo("Some.Other") }; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingSourceTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingSourceTests.cs index fcfda423b27..c7ed00eabf3 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingSourceTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/BindingSourceTests.cs @@ -64,7 +64,7 @@ public static IEnumerable Ctor_Object_String_Null_TestData() yield return new object[] { new DataClass { List = null }, nameof(DataClass.List), typeof(BindingList) }; yield return new object[] { new ObjectDataClass { List = null }, nameof(ObjectDataClass.List), typeof(BindingList) }; - yield return new object[] { new ObjectDataClass { List = null }, nameof(ObjectDataClass.List).ToLower(), typeof(BindingList) }; + yield return new object[] { new ObjectDataClass { List = null }, nameof(ObjectDataClass.List).ToLowerInvariant(), typeof(BindingList) }; } [WinFormsTheory] @@ -207,7 +207,7 @@ public static IEnumerable Ctor_Object_String_TestData() List list = [1, 2, 3]; DataClass listDataClass = new() { List = list }; yield return new object[] { listDataClass, nameof(DataClass.List), true, false, true, false, false, false, list }; - yield return new object[] { listDataClass, nameof(DataClass.List).ToLower(), true, false, true, false, false, false, list }; + yield return new object[] { listDataClass, nameof(DataClass.List).ToLowerInvariant(), true, false, true, false, false, false, list }; Mock mockListSource = new(MockBehavior.Strict); mockListSource @@ -215,7 +215,7 @@ public static IEnumerable Ctor_Object_String_TestData() .Returns(list); ListSourceDataClass listSourceDataClass = new() { ListSource = mockListSource.Object }; yield return new object[] { listSourceDataClass, nameof(ListSourceDataClass.ListSource), true, false, true, false, false, false, list }; - yield return new object[] { listSourceDataClass, nameof(ListSourceDataClass.ListSource).ToLower(), true, false, true, false, false, false, list }; + yield return new object[] { listSourceDataClass, nameof(ListSourceDataClass.ListSource).ToLowerInvariant(), true, false, true, false, false, false, list }; } [WinFormsTheory] @@ -282,10 +282,10 @@ public static IEnumerable Ctor_Object_String_BindingList_TestData() yield return new object[] { new ObjectDataClass { List = o1 }, nameof(ObjectDataClass.List), true, true, true, false, false, false, new BindingList { o1 }, typeof(BindingList) }; object o2 = new(); - yield return new object[] { new ObjectDataClass { List = o2 }, nameof(ObjectDataClass.List).ToLower(), true, true, true, false, false, false, new BindingList { o2 }, typeof(BindingList) }; + yield return new object[] { new ObjectDataClass { List = o2 }, nameof(ObjectDataClass.List).ToLowerInvariant(), true, true, true, false, false, false, new BindingList { o2 }, typeof(BindingList) }; yield return new object[] { new ObjectDataClass { List = 1 }, nameof(ObjectDataClass.List), true, true, true, false, false, false, new BindingList { 1 }, typeof(BindingList) }; - yield return new object[] { new ObjectDataClass { List = 1 }, nameof(ObjectDataClass.List).ToLower(), true, true, true, false, false, false, new BindingList { 1 }, typeof(BindingList) }; + yield return new object[] { new ObjectDataClass { List = 1 }, nameof(ObjectDataClass.List).ToLowerInvariant(), true, true, true, false, false, false, new BindingList { 1 }, typeof(BindingList) }; } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedIndexCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedIndexCollectionTests.cs index 51a5de48594..4f0021b4e6b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedIndexCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedIndexCollectionTests.cs @@ -5,7 +5,7 @@ namespace System.Windows.Forms.Tests; -public class CheckedListBox_CheckedIndexCollectionTests: IDisposable +public class CheckedListBox_CheckedIndexCollectionTests : IDisposable { private readonly CheckedListBox _checkedListBox; private readonly CheckedListBox.CheckedIndexCollection _collection; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedItemCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedItemCollectionTests.cs index a729deca17a..a07d6691b31 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedItemCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckedListBox.CheckedItemCollectionTests.cs @@ -108,7 +108,7 @@ public void CheckedItemCollection_GetEnumerator_ReturnsExpected(string[] items, AddItemsToCheckedListBox(items, checkedStates); IEnumerator enumerator = _collection.GetEnumerator(); - List result = new List(); + List result = []; while (enumerator.MoveNext()) { result.Add(enumerator.Current); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs index 62257c9c7f9..3dc59552ed1 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs @@ -46,13 +46,13 @@ public void Clipboard_Clear_InvokeMultipleTimes_Success() Clipboard.ContainsText().Should().BeFalse(); } - public static TheoryData> ContainsMethodsTheoryData => new() - { + public static TheoryData> ContainsMethodsTheoryData => + [ Clipboard.ContainsAudio, Clipboard.ContainsFileDropList, Clipboard.ContainsImage, Clipboard.ContainsText - }; + ]; [WinFormsTheory] [MemberData(nameof(ContainsMethodsTheoryData))] @@ -314,12 +314,12 @@ public void Clipboard_SetDataObject_InvokeObjectBoolIntIntNotIComDataObject_GetR Clipboard.ContainsData(data.GetType().FullName).Should().BeTrue(); } - public static TheoryData Clipboard_SetDataObject_Null_TheoryData => new() - { + public static TheoryData Clipboard_SetDataObject_Null_TheoryData => + [ () => Clipboard.SetDataObject(null!), () => Clipboard.SetDataObject(null!, copy: true), () => Clipboard.SetDataObject(null!, copy: true, retryTimes: 10, retryDelay: 0) - }; + ]; [WinFormsTheory] [MemberData(nameof(Clipboard_SetDataObject_Null_TheoryData))] @@ -342,8 +342,8 @@ public void Clipboard_SetDataObject_NegativeRetryDelay_ThrowsArgumentOutOfRangeE action.Should().Throw().WithParameterName("retryDelay"); } - public static TheoryData NotAnStaTheoryData => new() - { + public static TheoryData NotAnStaTheoryData => + [ Clipboard.Clear, () => Clipboard.SetAudio(Array.Empty()), () => Clipboard.SetAudio(new MemoryStream()), @@ -351,10 +351,10 @@ public void Clipboard_SetDataObject_NegativeRetryDelay_ThrowsArgumentOutOfRangeE () => Clipboard.SetDataObject(null!), () => Clipboard.SetDataObject(null!, copy: true), () => Clipboard.SetDataObject(null!, copy: true, retryTimes: 10, retryDelay: 0), - () => Clipboard.SetFileDropList(new StringCollection { "filePath" }), + () => Clipboard.SetFileDropList(["filePath"]), () => Clipboard.SetText("text"), () => Clipboard.SetText("text", TextDataFormat.Text) - }; + ]; [Theory] // x-thread [MemberData(nameof(NotAnStaTheoryData))] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderCollectionTests.cs index e87ca4404fc..c9be896c675 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderCollectionTests.cs @@ -27,7 +27,7 @@ public void ColumnHeaderCollection_IList_GetProperties_ReturnsExpected() { using ListView listView = new(); IList collection = new ListView.ColumnHeaderCollection(listView); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsFixedSize); Assert.False(collection.IsReadOnly); Assert.True(collection.IsSynchronized); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBox.ComboBoxUiaTextProviderTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBox.ComboBoxUiaTextProviderTests.cs index fcc74377b57..9dab02b5fa7 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBox.ComboBoxUiaTextProviderTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBox.ComboBoxUiaTextProviderTests.cs @@ -176,7 +176,7 @@ public void ComboBoxUiaTextProvider_DocumentRange_IsNull_ThrowException(ComboBox { using ComboBox comboBox = new() { DropDownStyle = dropDownStyle }; ComboBox.ComboBoxUiaTextProvider provider = new(comboBox); - Assert.Throws(() => _ = provider.DocumentRange); + Assert.Throws(() => _ = provider.DocumentRange); } } @@ -728,9 +728,9 @@ public void ComboBoxUiaTextProvider_EditStyle_ReturnsCorrectValue(ComboBoxStyle WINDOW_STYLE actual = provider.WindowStyle; - Assert.False(((int)actual & PInvoke.ES_RIGHT) != 0); - Assert.True(((int)actual & PInvoke.ES_NOHIDESEL) != 0); - Assert.True(((int)actual & PInvoke.ES_AUTOHSCROLL) != 0); + Assert.Equal(0, ((int)actual & PInvoke.ES_RIGHT)); + Assert.NotEqual(0, ((int)actual & PInvoke.ES_NOHIDESEL)); + Assert.NotEqual(0, ((int)actual & PInvoke.ES_AUTOHSCROLL)); Assert.True(comboBox.IsHandleCreated); Assert.NotNull(comboBox.TestAccessor().Dynamic._childEdit); } @@ -1099,7 +1099,7 @@ public void ComboBoxUiaTextProvider_GetLogfont_ReturnEmpty_WithoutHandle(ComboBo ComboBox.ComboBoxUiaTextProvider provider = new(comboBox); Assert.False(comboBox.IsHandleCreated); Assert.Null(comboBox.TestAccessor().Dynamic._childEdit); - Assert.Equal(new LOGFONTW(), provider.Logfont); + Assert.Equal(default, provider.Logfont); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs index ec5d334cc0b..fbf943b8265 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComboBoxTests.cs @@ -357,7 +357,7 @@ public void ComboBox_Paint_AddHandler_ShouldSubscribeEvent() PaintEventHandler handler = (sender, e) => callCount++; comboBox.Paint += handler; - comboBox.TestAccessor().Dynamic.OnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), new Rectangle())); + comboBox.TestAccessor().Dynamic.OnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), default)); callCount.Should().Be(1); } @@ -370,11 +370,11 @@ public void ComboBox_Paint_RemoveHandler_ShouldUnsubscribeEvent() PaintEventHandler handler = (sender, e) => callCount++; comboBox.Paint += handler; - comboBox.InvokeOnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), new Rectangle())); + comboBox.InvokeOnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), default)); callCount.Should().Be(1); comboBox.Paint -= handler; - comboBox.InvokeOnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), new Rectangle())); + comboBox.InvokeOnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), default)); callCount.Should().Be(1); } @@ -395,14 +395,13 @@ public void ComboBox_Paint_EventHandlerCalledOnPaint() [WinFormsFact] public void VerifyAutoCompleteEntries() { - void AssertAutoCompleteCustomSource(string[] items, bool isHandleCreated) + static void AssertAutoCompleteCustomSource(string[] items, bool isHandleCreated) { using ComboBox control = new(); if (items is not null) { - AutoCompleteStringCollection autoCompleteCustomSource = new(); - autoCompleteCustomSource.AddRange(items); + AutoCompleteStringCollection autoCompleteCustomSource = [.. items]; control.AutoCompleteCustomSource = autoCompleteCustomSource; control.AutoCompleteCustomSource.Should().BeEquivalentTo(autoCompleteCustomSource); } @@ -440,7 +439,7 @@ public void ComboBox_BeginEndUpdate() control3.IsHandleCreated.Should().BeTrue(); using ComboBox control4 = new(); - Exception exception = Record.Exception(() => control4.EndUpdate()); + Exception exception = Record.Exception(control4.EndUpdate); exception.Should().BeNull(); } @@ -728,7 +727,7 @@ public void ComboBox_DrawItem_AddHandler_ShouldCallHandler() DrawItemEventHandler handler = (sender, e) => callCount++; control.DrawItem += handler; - control.TestRaiseOnDrawItem(new DrawItemEventArgs(graphics, control.Font, new Rectangle(), 0, DrawItemState.Default)); + control.TestRaiseOnDrawItem(new DrawItemEventArgs(graphics, control.Font, default, 0, DrawItemState.Default)); callCount.Should().Be(1); control.DrawItem -= handler; @@ -745,7 +744,7 @@ public void ComboBox_DrawItem_RemoveHandler_ShouldNotCallHandler() control.DrawItem += handler; control.DrawItem -= handler; using Bitmap bitmap = new(1, 1); - control.TestRaiseOnDrawItem(new DrawItemEventArgs(Graphics.FromImage(bitmap), control.Font, new Rectangle(), 0, DrawItemState.Default)); + control.TestRaiseOnDrawItem(new DrawItemEventArgs(Graphics.FromImage(bitmap), control.Font, default, 0, DrawItemState.Default)); callCount.Should().Be(0); } @@ -774,13 +773,13 @@ public void ComboBox_DrawItem_AddRemoveMultipleHandlers_ShouldCallHandlers() control.DrawItem += handler1; control.DrawItem += handler2; - control.TestRaiseOnDrawItem(new DrawItemEventArgs(graphics, control.Font, new Rectangle(), 0, DrawItemState.Default)); + control.TestRaiseOnDrawItem(new DrawItemEventArgs(graphics, control.Font, default, 0, DrawItemState.Default)); callCount1.Should().Be(1); callCount2.Should().Be(1); control.DrawItem -= handler1; - control.TestRaiseOnDrawItem(new DrawItemEventArgs(graphics, control.Font, new Rectangle(), 0, DrawItemState.Default)); + control.TestRaiseOnDrawItem(new DrawItemEventArgs(graphics, control.Font, default, 0, DrawItemState.Default)); callCount1.Should().Be(1); // Should not increase callCount2.Should().Be(2); // Should increase @@ -816,7 +815,7 @@ public void ComboBox_DoubleClick_AddRemoveEvent_Success(int expectedCallCount) control.DoubleClick -= handler; control.TestTriggerDoubleClick(); callCount.Should().Be(expectedCallCount); - } + } [WinFormsTheory] [EnumData] @@ -1719,7 +1718,7 @@ public void ComboBox_FindStringExact_InvalidStartIndex_ThrowsArgumentOutOfRangeE private void SendCtrlBackspace(SubComboBox tb) { - Message message = new(); + Message message = default; tb.ProcessCmdKey(ref message, Keys.Control | Keys.Back); } @@ -2599,7 +2598,7 @@ public void OwnerDrawComboBox_Verify_OnMeasureItem_Receives_Correct_Arguments() public void ComboBox_Select_Item_By_Key(Keys key, int expectedKeyPressesCount, int selectedIndex) { using ComboBoxWithSelectCounter comboBox = new(); - comboBox.AddItems(expectedKeyPressesCount+1); + comboBox.AddItems(expectedKeyPressesCount + 1); comboBox.CreateControl(); comboBox.SelectedIndex = selectedIndex; comboBox.ResetEventsCount(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Combobox.ObjectCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Combobox.ObjectCollectionTests.cs index d707c8358ac..18285f3e091 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Combobox.ObjectCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Combobox.ObjectCollectionTests.cs @@ -416,8 +416,8 @@ public void ComboBoxObjectCollection_Clear_Invoke_Success(bool createControl) comboBoxObjectCollection.Clear(); - Assert.Equal(0, comboBoxObjectCollection.Count); - Assert.Equal(0, comboBoxObjectCollection.InnerList.Count); + Assert.Empty(comboBoxObjectCollection); + Assert.Empty(comboBoxObjectCollection.InnerList); Assert.Equal(createControl, comboBox.IsHandleCreated); } @@ -428,7 +428,7 @@ public void ComboBoxObjectCollection_Clear_Invoke_ClearItemAccessibleObjects() comboBox.CreateControl(); ObjectCollection comboBoxObjectCollection = comboBox.Items; comboBoxObjectCollection.AddRange(new string[] { "a", "b" }); - ComboBox.ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); + ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); // Adding ComboBoxItemAccessibleObject to the "ItemAccessibleObjects" list ComboBoxItemAccessibleObject firstAccessibleObjectItem = accessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBoxObjectCollection.InnerList[0]); @@ -439,8 +439,8 @@ public void ComboBoxObjectCollection_Clear_Invoke_ClearItemAccessibleObjects() comboBoxObjectCollection.Clear(); - Assert.Equal(0, comboBoxObjectCollection.Count); - Assert.Equal(0, accessibleObject.ItemAccessibleObjects.Count); + Assert.Empty(comboBoxObjectCollection); + Assert.Empty(accessibleObject.ItemAccessibleObjects); Assert.True(comboBox.IsHandleCreated); } @@ -461,7 +461,7 @@ public void ComboBoxObjectCollection_Clear_Invoke_DataSourceExists_ThrowsArgumen ObjectCollection comboBoxObjectCollection = new(comboBox); - Assert.Throws(() => comboBoxObjectCollection.Clear()); + Assert.Throws(comboBoxObjectCollection.Clear); Assert.Equal(createControl, comboBox.IsHandleCreated); } @@ -846,7 +846,7 @@ public void ComboBoxObjectCollection_RemoveAt_Invoke_Success(bool createControl) comboBoxObjectCollection.RemoveAt(0); - Assert.Equal(1, comboBoxObjectCollection.Count); + Assert.Single(comboBoxObjectCollection); Assert.Equal("b", comboBoxObjectCollection[0]); Assert.Equal(createControl, comboBox.IsHandleCreated); } @@ -860,16 +860,16 @@ public void ComboBoxObjectCollection_RemoveAt_Invoke_RemoveItemAccessibleObject( comboBox.CreateControl(); ObjectCollection comboBoxObjectCollection = comboBox.Items; comboBoxObjectCollection.Add("a"); - ComboBox.ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); + ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); // Adding ComboBoxItemAccessibleObject to the "ItemAccessibleObjects" list ComboBoxItemAccessibleObject firstAccessibleObjectItem = accessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBoxObjectCollection.InnerList[0]); - Assert.Equal(1, accessibleObject.ItemAccessibleObjects.Count); + Assert.Single(accessibleObject.ItemAccessibleObjects); comboBoxObjectCollection.RemoveAt(0); - Assert.Equal(0, comboBoxObjectCollection.Count); - Assert.Equal(0, accessibleObject.ItemAccessibleObjects.Count); + Assert.Empty(comboBoxObjectCollection); + Assert.Empty(accessibleObject.ItemAccessibleObjects); Assert.True(comboBox.IsHandleCreated); } @@ -947,7 +947,7 @@ public void ComboBoxObjectCollection_Remove_Invoke_Success(bool createControl) comboBoxObjectCollection.Remove("a"); - Assert.Equal(1, comboBoxObjectCollection.Count); + Assert.Single(comboBoxObjectCollection); Assert.Equal("b", comboBoxObjectCollection[0]); Assert.Equal(createControl, comboBox.IsHandleCreated); } @@ -1001,7 +1001,7 @@ public void ComboBoxObjectCollection_Remove_Object_Invoke_Success(bool createCon // Remove existing object comboBoxObjectCollection.Remove(person1); - Assert.Equal(1, comboBoxObjectCollection.Count); + Assert.Single(comboBoxObjectCollection); Assert.Equal(person2, comboBoxObjectCollection[0]); Assert.Equal(createControl, comboBox.IsHandleCreated); } @@ -1025,7 +1025,7 @@ public void ComboBoxObjectCollection_Remove_Entry_Invoke_Success(bool createCont comboBoxObjectCollection.Remove(comboBoxObjectCollection[0]); - Assert.Equal(1, comboBoxObjectCollection.Count); + Assert.Single(comboBoxObjectCollection); Assert.Equal("b", comboBoxObjectCollection[0]); Assert.Equal(createControl, comboBox.IsHandleCreated); } @@ -1039,16 +1039,16 @@ public void ComboBoxObjectCollection_Remove_Invoke_RemoveItemAccessibleObject() comboBox.CreateControl(); ObjectCollection comboBoxObjectCollection = comboBox.Items; comboBoxObjectCollection.Add("a"); - ComboBox.ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); + ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); // Adding ComboBoxItemAccessibleObject to the "ItemAccessibleObjects" list ComboBoxItemAccessibleObject firstAccessibleObjectItem = accessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBoxObjectCollection.InnerList[0]); - Assert.Equal(1, accessibleObject.ItemAccessibleObjects.Count); + Assert.Single(accessibleObject.ItemAccessibleObjects); comboBoxObjectCollection.Remove("a"); - Assert.Equal(0, comboBoxObjectCollection.Count); - Assert.Equal(0, accessibleObject.ItemAccessibleObjects.Count); + Assert.Empty(comboBoxObjectCollection); + Assert.Empty(accessibleObject.ItemAccessibleObjects); Assert.True(comboBox.IsHandleCreated); } @@ -1286,11 +1286,12 @@ public void ComboBoxObjectCollection_SetItem_DoesNotAffect_ItemsAccessibleObject { using ComboBox comboBox = new(); comboBox.CreateControl(); - ComboBox.ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); + ComboBoxAccessibleObject accessibleObject = GetComboBoxAccessibleObject(comboBox); ObjectCollection comboBoxObjectCollection = new(comboBox) { "a" }; + ComboBoxItemAccessibleObject oldAccessibleObjectItem = accessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBoxObjectCollection.InnerList[0]); comboBoxObjectCollection[0] = "b"; ComboBoxItemAccessibleObject newAccessibleObjectItem = accessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBoxObjectCollection.InnerList[0]); @@ -1483,8 +1484,8 @@ public void ComboBox_Item_Clear_DoesNotCreateAccessibilityObject() Assert.False(comboBox.IsHandleCreated); } - private ComboBox.ComboBoxAccessibleObject GetComboBoxAccessibleObject(ComboBox comboBox) + private static ComboBoxAccessibleObject GetComboBoxAccessibleObject(ComboBox comboBox) { - return (ComboBox.ComboBoxAccessibleObject)comboBox.AccessibilityObject; + return (ComboBoxAccessibleObject)comboBox.AccessibilityObject; } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComponentModel/Com2Interop/Com2PropertyDescriptorTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComponentModel/Com2Interop/Com2PropertyDescriptorTests.cs index ad5a418853c..0791559edb5 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComponentModel/Com2Interop/Com2PropertyDescriptorTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ComponentModel/Com2Interop/Com2PropertyDescriptorTests.cs @@ -8,13 +8,11 @@ namespace System.Windows.Forms.ComponentModel.Com2Interop.Tests; // NB: doesn't require thread affinity public class Com2PropertyDescriptorTests { - private static readonly MethodInfo s_miVersionInfo; - private static readonly Type s_typeCom2PropertyDescriptor; + private static readonly Type s_typeCom2PropertyDescriptor = typeof(Com2PropertyDescriptor); + private static readonly MethodInfo s_miVersionInfo = s_typeCom2PropertyDescriptor.GetMethod("TrimNewline", BindingFlags.Static | BindingFlags.NonPublic); static Com2PropertyDescriptorTests() { - s_typeCom2PropertyDescriptor = typeof(Com2PropertyDescriptor); - s_miVersionInfo = s_typeCom2PropertyDescriptor.GetMethod("TrimNewline", BindingFlags.Static | BindingFlags.NonPublic); Assert.NotNull(s_miVersionInfo); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Methods.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Methods.cs index 00bcc3f3934..923287ddf1e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Methods.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Methods.cs @@ -594,7 +594,7 @@ public void Control_CreateControl_InvokeWithHandler_CallsHandleCreated() public void Control_CreateControl_InvokeCantCreate_ThrowsWin32Exception() { using NoCreateControl control = new(); - Assert.Throws(() => control.CreateControl()); + Assert.Throws(control.CreateControl); } [WinFormsFact] @@ -602,7 +602,7 @@ public void Control_CreateControl_InvokeDisposed_ThrowsObjectDisposedException() { using SubControl control = new(); control.Dispose(); - Assert.Throws(() => control.CreateControl()); + Assert.Throws(control.CreateControl); } [WinFormsFact] @@ -754,7 +754,7 @@ public void Control_CreateHandle_InvokeWithHandler_CallsHandleCreated() public void Control_CreateHandle_InvokeCantCreate_ThrowsWin32Exception() { using NoCreateControl control = new(); - Assert.Throws(() => control.CreateHandle()); + Assert.Throws(control.CreateHandle); } [WinFormsFact] @@ -762,7 +762,7 @@ public void Control_CreateHandle_InvokeDisposed_ThrowsObjectDisposedException() { using SubControl control = new(); control.Dispose(); - Assert.Throws(() => control.CreateHandle()); + Assert.Throws(control.CreateHandle); } [WinFormsFact] @@ -770,7 +770,7 @@ public void Control_CreateHandle_InvokeAlreadyCreated_ThrowsInvalidOperationExce { using SubControl control = new(); control.CreateHandle(); - Assert.Throws(() => control.CreateHandle()); + Assert.Throws(control.CreateHandle); } [WinFormsFact] @@ -2976,7 +2976,7 @@ public void Control_InitLayout_NullLayoutEngine_ThrowsNullReferenceException() { using CustomLayoutEngineControl control = new(); control.SetLayoutEngine(null); - Assert.Throws(() => control.InitLayout()); + Assert.Throws(control.InitLayout); } private class CustomLayoutEngineControl : Control @@ -5281,7 +5281,7 @@ public void Control_PerformLayout_NullLayoutEngine_ThrowsNullReferenceException( { using CustomLayoutEngineControl control = new(); control.SetLayoutEngine(null); - Assert.Throws(() => control.PerformLayout()); + Assert.Throws(control.PerformLayout); Assert.Throws(() => control.PerformLayout(new Control(), "AffectedProperty")); } @@ -5528,7 +5528,7 @@ private class CustomProcessControl : Control public void Control_ProcessCmdKey_InvokeWithoutParent_ReturnsFalse(Keys keyData) { using SubControl control = new(); - Message m = new(); + Message m = default; Assert.False(control.ProcessCmdKey(ref m, keyData)); Assert.False(control.IsHandleCreated); } @@ -5542,7 +5542,7 @@ public void Control_ProcessCmdKey_InvokeWithParent_ReturnsFalse(Keys keyData) { Parent = parent }; - Message msg = new(); + Message msg = default; Assert.False(control.ProcessCmdKey(ref msg, keyData)); Assert.False(control.IsHandleCreated); } @@ -6230,7 +6230,7 @@ bool action(Message actualM) public void Control_ProcessKeyPreview_InvokeWithoutParent_ReturnsFalse() { using SubControl control = new(); - Message m = new(); + Message m = default; Assert.False(control.ProcessKeyPreview(ref m)); } @@ -6242,7 +6242,7 @@ public void Control_ProcessKeyPreview_InvokeWithParent_ReturnsFalse() { Parent = parent }; - Message m = new(); + Message m = default; Assert.False(control.ProcessKeyPreview(ref m)); Assert.False(control.IsHandleCreated); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs index a9764cdc269..1b0a55b14ce 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs @@ -7694,7 +7694,7 @@ private class ZeroDefaultMarginControl : Control public static IEnumerable Margin_Set_TestData() { - yield return new object[] { new Padding(), new Padding() }; + yield return new object[] { default(Padding), default(Padding) }; yield return new object[] { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4) }; yield return new object[] { new Padding(1), new Padding(1) }; yield return new object[] { new Padding(-1, -2, -3, -4), Padding.Empty }; @@ -9400,7 +9400,7 @@ private class NonZeroDefaultPaddingControl : Control public static IEnumerable Padding_Set_TestData() { - yield return new object[] { new Padding(), new Padding(), 0, 0 }; + yield return new object[] { default(Padding), default(Padding), 0, 0 }; yield return new object[] { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 1 }; yield return new object[] { new Padding(1), new Padding(1), 1, 1 }; yield return new object[] { new Padding(-1, -2, -3, -4), Padding.Empty, 1, 2 }; @@ -9480,11 +9480,11 @@ void parentHandler(object sender, LayoutEventArgs e) public static IEnumerable Padding_SetWithHandle_TestData() { - yield return new object[] { false, new Padding(), new Padding(), 0, 0, 0, 0 }; + yield return new object[] { false, default(Padding), default(Padding), 0, 0, 0, 0 }; yield return new object[] { false, new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 0, 1, 0 }; yield return new object[] { false, new Padding(1), new Padding(1), 1, 0, 1, 0 }; yield return new object[] { false, new Padding(-1, -2, -3, -4), Padding.Empty, 1, 0, 2, 0 }; - yield return new object[] { true, new Padding(), new Padding(), 0, 0, 0, 0 }; + yield return new object[] { true, default(Padding), default(Padding), 0, 0, 0, 0 }; yield return new object[] { true, new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 1, 1, 1 }; yield return new object[] { true, new Padding(1), new Padding(1), 1, 1, 1, 1 }; yield return new object[] { true, new Padding(-1, -2, -3, -4), Padding.Empty, 1, 1, 2, 2 }; @@ -9901,13 +9901,13 @@ public void Control_Region_SetWithNonNullOldValue_GetReturnsExpected(Region valu control.Region = value; Assert.Same(value, control.Region); - Assert.Throws(() => oldValue.MakeEmpty()); + Assert.Throws(oldValue.MakeEmpty); Assert.False(control.IsHandleCreated); // Set same. control.Region = value; Assert.Same(value, control.Region); - Assert.Throws(() => oldValue.MakeEmpty()); + Assert.Throws(oldValue.MakeEmpty); Assert.False(control.IsHandleCreated); } @@ -9960,7 +9960,7 @@ public void Control_Region_SetWithNonNullOldValueWithHandle_GetReturnsExpected(R control.Region = value; Assert.Same(value, control.Region); - Assert.Throws(() => oldValue.MakeEmpty()); + Assert.Throws(oldValue.MakeEmpty); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); @@ -9969,7 +9969,7 @@ public void Control_Region_SetWithNonNullOldValueWithHandle_GetReturnsExpected(R // Set same. control.Region = value; Assert.Same(value, control.Region); - Assert.Throws(() => oldValue.MakeEmpty()); + Assert.Throws(oldValue.MakeEmpty); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataFormatsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataFormatsTests.cs index 5fe07436f4d..b8b630c5dcb 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataFormatsTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataFormatsTests.cs @@ -65,7 +65,7 @@ public static IEnumerable GetFormat_KnownString_TestData() public void DataFormats_GetFormat_InvokeKnownString_ReturnsExpected(string format, string expectedName, int expectedId) { DataFormats.Format result = DataFormats.GetFormat(format); - Assert.Same(result, DataFormats.GetFormat(format.ToLower())); + Assert.Same(result, DataFormats.GetFormat(format.ToLowerInvariant())); Assert.Equal(expectedName, result.Name); Assert.Equal(expectedId, result.Id); @@ -89,7 +89,7 @@ public void DataFormats_GetFormat_InvokeUnknownFormatString_ReturnsExpected(stri { DataFormats.Format result = DataFormats.GetFormat(format); Assert.Same(result, DataFormats.GetFormat(format)); - Assert.Same(result, DataFormats.GetFormat(format.ToLower())); + Assert.Same(result, DataFormats.GetFormat(format.ToLowerInvariant())); Assert.Equal(expectedName, result.Name); // Internally the format is registered with RegisterClipboardFormat. diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs index 2497849fa00..757d2c10bf8 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs @@ -1687,7 +1687,7 @@ public void SubDataGridViewCell_ReadOnly_SetWithRow_GetReturnsExpected(bool valu cell.ReadOnly = !value; Assert.True(cell.ReadOnly); Assert.False(row.ReadOnly); - Assert.True((cell.State & DataGridViewElementStates.ReadOnly) != 0); + cell.State.Should().HaveFlag(DataGridViewElementStates.ReadOnly); } [WinFormsTheory] @@ -3416,7 +3416,7 @@ public class CreateAccessibilityInstanceTests : DataGridViewCell public void DataGridViewCell_AccessibilityObject_Get_ReturnsExpected() { using SubDataGridViewCell cell = new(); - DataGridViewCell.DataGridViewCellAccessibleObject accessibleObject = Assert.IsType(cell.AccessibilityObject); + DataGridViewCellAccessibleObject accessibleObject = Assert.IsType(cell.AccessibilityObject); Assert.Same(accessibleObject, cell.AccessibilityObject); Assert.Same(cell, accessibleObject.Owner); } @@ -3424,8 +3424,8 @@ public void DataGridViewCell_AccessibilityObject_Get_ReturnsExpected() public static IEnumerable AccessibilityObject_CustomCreateAccessibilityInstance_TestData() { yield return new object[] { new AccessibleObject() }; - yield return new object[] { new DataGridViewCell.DataGridViewCellAccessibleObject(null) }; - yield return new object[] { new DataGridViewCell.DataGridViewCellAccessibleObject(new SubDataGridViewCell()) }; + yield return new object[] { new DataGridViewCellAccessibleObject(null) }; + yield return new object[] { new DataGridViewCellAccessibleObject(new SubDataGridViewCell()) }; } [WinFormsTheory] @@ -3444,7 +3444,7 @@ public void DataGridViewCell_AccessibilityObject_GetCustomCreateAccessibilityIns public void DataGridViewCell_CreateAccessibilityInstance_Invoke_ReturnsExpected() { using SubDataGridViewCell cell = new(); - DataGridViewCell.DataGridViewCellAccessibleObject instance = Assert.IsAssignableFrom(cell.CreateAccessibilityInstance()); + DataGridViewCellAccessibleObject instance = Assert.IsAssignableFrom(cell.CreateAccessibilityInstance()); Assert.NotNull(instance); Assert.Same(cell, instance.Owner); Assert.Equal(AccessibleRole.Cell, instance.Role); @@ -3464,7 +3464,7 @@ private class CustomCreateAccessibilityInstanceDataGridViewCell : DataGridViewCe public void DataGridViewCell_DetachEditingDataGridViewCell_InvokeNoDataGridView_ThrowsInvalidOperationException() { using SubDataGridViewCell cell = new(); - Assert.Throws(() => cell.DetachEditingControl()); + Assert.Throws(cell.DetachEditingControl); } [WinFormsFact] @@ -3478,7 +3478,7 @@ public void DataGridViewCell_DetachEditingDataGridViewCell_InvokeNoEditingContro using DataGridView control = new(); control.Columns.Add(column); SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0]; - Assert.Throws(() => cell.DetachEditingControl()); + Assert.Throws(cell.DetachEditingControl); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewColumnCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewColumnCollectionTests.cs index a9c3b7e3ba3..0116ab7cc61 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewColumnCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewColumnCollectionTests.cs @@ -14,7 +14,7 @@ public void DataGridViewColumnCollection_Ctor_DataGridView() using DataGridView control = new(); SubDataGridViewColumnCollection collection = new(control); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Same(control, collection.DataGridView); Assert.False(collection.IsReadOnly); Assert.False(collection.IsSynchronized); @@ -420,7 +420,7 @@ public void DataGridViewColumnCollection_Add_ColumnAutomaticSortModeColumnSelect collection.Add(column); // End init. - Assert.Throws(() => iSupportInitialize.EndInit()); + Assert.Throws(iSupportInitialize.EndInit); Assert.Equal(DataGridViewSelectionMode.RowHeaderSelect, control.SelectionMode); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedCellCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedCellCollectionTests.cs index d93bb32f975..a5c47859157 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedCellCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedCellCollectionTests.cs @@ -12,7 +12,7 @@ public void DataGridViewSelectedCellCollection_Properties_GetEmpty_ReturnsExpect { using DataGridView control = new(); DataGridViewSelectedCellCollection collection = control.SelectedCells; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsReadOnly); Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); @@ -91,7 +91,7 @@ public void DataGridViewSelectedCellCollection_Clear_Invoke_ThrowsNotSupportedEx { using DataGridView control = new(); DataGridViewSelectedCellCollection collection = control.SelectedCells; - Assert.Throws(() => collection.Clear()); + Assert.Throws(collection.Clear); } [WinFormsFact] @@ -183,7 +183,7 @@ public void DataGridViewSelectedCellCollection_IListProperties_GetEmpty_ReturnsE using DataGridView control = new(); DataGridViewSelectedCellCollection collection = control.SelectedCells; IList iList = collection; - Assert.Equal(0, iList.Count); + Assert.Empty(iList); Assert.True(iList.IsFixedSize); Assert.True(iList.IsReadOnly); Assert.False(iList.IsSynchronized); @@ -303,7 +303,7 @@ public void DataGridViewSelectedCellCollection_IListClear_Invoke_ThrowsNotSuppor using DataGridView control = new(); DataGridViewSelectedCellCollection collection = control.SelectedCells; IList iList = collection; - Assert.Throws(() => iList.Clear()); + Assert.Throws(iList.Clear); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedColumnCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedColumnCollectionTests.cs index 9e6803b46a6..c97922daccc 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedColumnCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedColumnCollectionTests.cs @@ -12,7 +12,7 @@ public void DataGridViewSelectedColumnCollection_Properties_GetEmpty_ReturnsExpe { using DataGridView control = new(); DataGridViewSelectedColumnCollection collection = control.SelectedColumns; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsReadOnly); Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); @@ -103,7 +103,7 @@ public void DataGridViewSelectedColumnCollection_Clear_Invoke_ThrowsNotSupported { using DataGridView control = new(); DataGridViewSelectedColumnCollection collection = control.SelectedColumns; - Assert.Throws(() => collection.Clear()); + Assert.Throws(collection.Clear); } [WinFormsFact] @@ -203,7 +203,7 @@ public void DataGridViewSelectedColumnCollection_IListProperties_GetEmpty_Return using DataGridView control = new(); DataGridViewSelectedColumnCollection collection = control.SelectedColumns; IList iList = collection; - Assert.Equal(0, iList.Count); + Assert.Empty(iList); Assert.True(iList.IsFixedSize); Assert.True(iList.IsReadOnly); Assert.False(iList.IsSynchronized); @@ -335,7 +335,7 @@ public void DataGridViewSelectedColumnCollection_IListClear_Invoke_ThrowsNotSupp using DataGridView control = new(); DataGridViewSelectedColumnCollection collection = control.SelectedColumns; IList iList = collection; - Assert.Throws(() => iList.Clear()); + Assert.Throws(iList.Clear); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedRowCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedRowCollectionTests.cs index 1536e066172..8667941b185 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedRowCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewSelectedRowCollectionTests.cs @@ -12,7 +12,7 @@ public void DataGridViewSelectedRowCollection_Properties_GetEmpty_ReturnsExpecte { using DataGridView control = new(); DataGridViewSelectedRowCollection collection = control.SelectedRows; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsReadOnly); Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); @@ -88,7 +88,7 @@ public void DataGridViewSelectedRowCollection_Clear_Invoke_ThrowsNotSupportedExc { using DataGridView control = new(); DataGridViewSelectedRowCollection collection = control.SelectedRows; - Assert.Throws(() => collection.Clear()); + Assert.Throws(collection.Clear); } [WinFormsFact] @@ -178,7 +178,7 @@ public void DataGridViewSelectedRowCollection_IListProperties_GetEmpty_ReturnsEx using DataGridView control = new(); DataGridViewSelectedRowCollection collection = control.SelectedRows; IList iList = collection; - Assert.Equal(0, iList.Count); + Assert.Empty(iList); Assert.True(iList.IsFixedSize); Assert.True(iList.IsReadOnly); Assert.False(iList.IsSynchronized); @@ -295,7 +295,7 @@ public void DataGridViewSelectedRowCollection_IListClear_Invoke_ThrowsNotSupport using DataGridView control = new(); DataGridViewSelectedRowCollection collection = control.SelectedRows; IList iList = collection; - Assert.Throws(() => iList.Clear()); + Assert.Throws(iList.Clear); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.Rendering.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.Rendering.cs index db61bb21375..c104287529b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.Rendering.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.Rendering.cs @@ -177,24 +177,24 @@ public void DataGridView_DefaultCellStyles_Rendering() Validate.SkipTo( Validate.TextOut(column2.HeaderText, stateValidators: State.FontFace(customColumnHeaderFont.Name))), - // Row1 - Validate.SkipTo( + // Row1 + Validate.SkipTo( Validate.TextOut("Row 1", stateValidators: State.FontFace(customRowHeaderFont.Name))), Validate.SkipTo( Validate.TextOut(nameof(DataGridView.DefaultCellStyle), stateValidators: State.FontFace(customCellStyleFont.Name))), Validate.SkipTo( Validate.TextOut(customCellStyleFont.ToString(), stateValidators: State.FontFace(customCellStyleFont.Name))), - // Row2 - Validate.SkipTo( + // Row2 + Validate.SkipTo( Validate.TextOut("Row 2", stateValidators: State.FontFace(customRowHeaderFont.Name))), Validate.SkipTo( Validate.TextOut(nameof(DataGridView.ColumnHeadersDefaultCellStyle), stateValidators: State.FontFace(customCellStyleFont.Name))), Validate.SkipTo( Validate.TextOut(customColumnHeaderFont.ToString(), stateValidators: State.FontFace(customCellStyleFont.Name))), - // Row3 - Validate.SkipTo( + // Row3 + Validate.SkipTo( Validate.TextOut("Row 3", stateValidators: State.FontFace(customRowHeaderFont.Name))), Validate.SkipTo( Validate.TextOut(nameof(DataGridView.RowHeadersDefaultCellStyle), stateValidators: State.FontFace(customCellStyleFont.Name))), diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.cs index f15aad301c1..b7d9135cd51 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.cs @@ -1912,8 +1912,7 @@ public static IEnumerable OnColumnHeadersHeightChanged_TestData() // Skip verification of DataGridViewColumnHeadersHeightSizeMode = DisableResizing and columnHeadersVisible = true // in X86 due to the active issue "https://github.com/dotnet/winforms/issues/11322" if (columnHeadersWidthSizeMode == DataGridViewColumnHeadersHeightSizeMode.DisableResizing - && columnHeadersVisible is true - && RuntimeInformation.ProcessArchitecture == Architecture.X86) + && columnHeadersVisible && RuntimeInformation.ProcessArchitecture == Architecture.X86) continue; yield return new object[] { columnHeadersWidthSizeMode, columnHeadersVisible, null }; @@ -4059,7 +4058,7 @@ public void DataGridView_DefaultValuesNeededEvent_Raised_Success() _dataGridView.Columns.Add("Column1", "Column 1"); _dataGridView.Columns.Add("Column2", "Column 2"); - _dataGridView.AllowUserToAddRows = true; + _dataGridView.AllowUserToAddRows = true; _dataGridView.DefaultValuesNeeded += handler; _dataGridView.CurrentCell = _dataGridView.Rows[_dataGridView.NewRowIndex].Cells[0]; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.ClipboardTests.cs index 329aa532c32..3cbb053e55a 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.ClipboardTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.ClipboardTests.cs @@ -16,7 +16,7 @@ public class ClipboardTests { public static TheoryData GetData_StringBool_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string format in s_restrictedClipboardFormats) { theoryData.Add(format, false); @@ -28,7 +28,7 @@ public static TheoryData GetData_StringBool_TheoryData() public static TheoryData GetData_StringBool_Unbounded_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string format in s_unboundedClipboardFormats) { theoryData.Add(format, false); @@ -49,7 +49,7 @@ public void DataObject_GetData_InvokeStringBoolDefault_ReturnsNull(string format public static TheoryData GetDataPresent_StringBool_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (bool autoConvert in new bool[] { true, false }) { foreach (string format in s_restrictedClipboardFormats) @@ -76,7 +76,7 @@ public void DataObject_GetDataPresent_InvokeStringBoolDefault_ReturnsFalse(strin public static TheoryData SetData_StringObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string format in s_restrictedClipboardFormats) { if (string.IsNullOrWhiteSpace(format) || format == typeof(Bitmap).FullName || format.StartsWith("FileName", StringComparison.Ordinal)) @@ -128,7 +128,7 @@ private void DataObject_SetData_InvokeStringObject_GetReturnsExpected(string for public static TheoryData SetData_StringBoolObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string format in s_restrictedClipboardFormats) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.cs index 7571ec8c96b..b83564711eb 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObjectTests.cs @@ -155,7 +155,7 @@ public void DataObject_ContainsText_InvokeTextDataFormat_ReturnsFalse(TextDataFo public static TheoryData ContainsText_TextDataFormat_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (bool result in new bool[] { true, false }) { theoryData.Add(TextDataFormat.Text, DataFormats.UnicodeText, result); @@ -252,7 +252,7 @@ public void DataObject_GetData_InvokeStringDefault_ReturnsNull(string format) public static TheoryData GetData_InvokeStringMocked_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (object result in new object[] { new(), null }) { theoryData.Add("format", result); @@ -296,7 +296,7 @@ public void DataObject_GetData_InvokeStringIDataObject_ReturnsExpected(string fo public static TheoryData GetData_StringBoolIDataObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (bool autoConvert in new bool[] { true, false }) { foreach (object result in new object[] { new(), null }) @@ -374,7 +374,7 @@ public void DataObject_GetDataPresent_InvokeStringDefault_ReturnsFalse(string fo public static TheoryData GetDataPresent_StringMocked_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (bool result in new bool[] { true, false }) { theoryData.Add("format", result); @@ -418,7 +418,7 @@ public void DataObject_GetDataPresent_InvokeStringIDataObject_ReturnsExpected(st public static TheoryData GetDataPresent_StringBoolIDataObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (bool autoConvert in new bool[] { true, false }) { foreach (bool result in new bool[] { true, false }) @@ -458,7 +458,7 @@ public void DataObject_GetDataPresentPresent_InvokeTypeDefault_ReturnsFalse(Type public static TheoryData GetDataPresent_InvokeTypeMocked_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (bool result in new bool[] { true, false }) { theoryData.Add(typeof(int), result, 1, result, typeof(int).FullName); @@ -1066,7 +1066,7 @@ public void DataObject_SetData_InvokeStringObjectDibBitmapAutoConvert_GetDataRet public static TheoryData SetData_StringObjectIDataObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string format in new string[] { "format", " ", string.Empty, null }) { theoryData.Add(format, null); @@ -1146,7 +1146,7 @@ public void DataObject_SetData_InvokeStringBoolObjectDibBitmapAutoConvert_GetDat public static TheoryData SetData_StringBoolObjectIDataObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string format in new string[] { "format", " ", string.Empty, null }) { foreach (bool autoConvert in new bool[] { true, false }) @@ -1174,7 +1174,7 @@ public void DataObject_SetData_InvokeStringBoolObjectIDataObject_CallsSetData(st public static TheoryData SetData_TypeObjectIDataObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (Type format in new Type[] { typeof(int), null }) { theoryData.Add(format, null); @@ -1435,7 +1435,7 @@ public void DataObject_SetText_InvokeStringIDataObject_CallsSetData(string textD public static TheoryData SetText_StringTextDataFormat_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string textData in new string[] { "textData", " " }) { theoryData.Add(textData, TextDataFormat.Text, textData, null, null, null); @@ -1486,7 +1486,7 @@ public void DataObject_SetText_InvokeStringTextDataFormat_GetReturnsExpected(str public static TheoryData SetText_StringTextDataFormatMocked_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; foreach (string textData in new string[] { "textData", " " }) { theoryData.Add(textData, TextDataFormat.Text, DataFormats.UnicodeText); @@ -1610,7 +1610,7 @@ public void DataObject_DAdvise_InvokeDefault_Success(ADVF advf, IAdviseSink advi { DataObject dataObject = new(); IComDataObject comDataObject = dataObject; - FORMATETC formatetc = new(); + FORMATETC formatetc = default; ((HRESULT)comDataObject.DAdvise(ref formatetc, advf, adviseSink, out int connection)).Should().Be(HRESULT.E_NOTIMPL); connection.Should().Be(0); } @@ -1632,7 +1632,7 @@ public void DataObject_DAdvise_InvokeCustomComDataObject_Success(ADVF advf, IAdv .Returns(1); DataObject dataObject = new(mockComDataObject.Object); IComDataObject comDataObject = dataObject; - FORMATETC formatetc = new(); + FORMATETC formatetc = default; comDataObject.DAdvise(ref formatetc, advf, adviseSink, out int connection).Should().Be(1); connection.Should().Be(2); formatetc.cfFormat.Should().Be(3); @@ -1678,7 +1678,7 @@ public void DataObject_EnumDAdvise_InvokeDefault_Success() public static TheoryData EnumDAdvise_CustomComDataObject_TheoryData() { - TheoryData theoryData = new() { null }; + TheoryData theoryData = [null]; Mock mockEnumStatData = new(MockBehavior.Strict); theoryData.Add(mockEnumStatData.Object); @@ -2058,7 +2058,7 @@ public void DataObject_EnumFormatEtc_InvokeNotGet_ThrowsExternalException(DATADI public static TheoryData EnumFormatEtc_CustomComDataObject_TheoryData() { - TheoryData theoryData = new(); + TheoryData theoryData = []; Mock mockEnumFormatEtc = new(MockBehavior.Strict); theoryData.Add(DATADIR.DATADIR_GET, mockEnumFormatEtc.Object); @@ -2500,6 +2500,6 @@ public unsafe void DataObject_Native_GetFormats_ReturnsExpected() data.GetDataPresent(typeof(Bitmap)).Should().BeTrue(); data.GetDataPresent(customFormat).Should().BeTrue(); data.GetDataPresent("notExist").Should().BeFalse(); - data.GetFormats().Should().BeEquivalentTo([typeof(Bitmap).FullName, typeof(Bitmap).Name, customFormat]); + data.GetFormats().Should().BeEquivalentTo([typeof(Bitmap).FullName, nameof(Bitmap), customFormat]); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObject_BitmapBinderTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObject_BitmapBinderTests.cs index 04ae109a421..e3bf137f682 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObject_BitmapBinderTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataObject_BitmapBinderTests.cs @@ -56,7 +56,7 @@ public unsafe void BitmapBinder_BindToType_AllowedSerializationTypes(object valu }; // cs/dangerous-binary-deserialization - object deserialized = formatter.Deserialize(stream); // CodeQL [SM03722] : Testing legacy feature. Safe use because input stream is controlled contains strings and Bitmap which is instantiated by a binder. + object deserialized = formatter.Deserialize(stream); // CodeQL [SM03722] : Testing legacy feature. Safe use because input stream is controlled contains strings and Bitmap which is instantiated by a binder. deserialized.Should().NotBeNull(); if (value is not Bitmap bitmap) @@ -83,12 +83,12 @@ public unsafe void BitmapBinder_BindToType_AllowedSerializationTypes(object valu } } - public static TheoryData AllowedSerializationTypes => new() - { + public static TheoryData AllowedSerializationTypes => + [ "Information At your Fingertips", new string[] { "Hello" }, new Bitmap(5, 5) - }; + ]; [WinFormsTheory] [MemberData(nameof(DisallowedSerializationTypes))] @@ -130,9 +130,9 @@ public void BitmapBinder_BindToType_DisallowedSerializationTypes(object value) action.Should().Throw(); } - public static TheoryData DisallowedSerializationTypes => new() - { + public static TheoryData DisallowedSerializationTypes => + [ new List() { "Hello" }, new Hashtable() { { "Silver", "Hammer" } } - }; + ]; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DateTimePickerTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DateTimePickerTests.cs index 6feb220bd93..df325c2bba4 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DateTimePickerTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DateTimePickerTests.cs @@ -9,7 +9,7 @@ namespace System.Windows.Forms.Tests; -public class DateTimePickerTests: IDisposable +public class DateTimePickerTests : IDisposable { private readonly DateTimePicker _dateTimePicker; @@ -543,7 +543,7 @@ public void DateTimePicker_PaintEvent_Raised_Success() control.Paint += handler; using (Bitmap bmp = new(1, 1)) { - control.OnPaint(new(Graphics.FromImage(bmp), new())); + control.OnPaint(new(Graphics.FromImage(bmp), default)); } callCount.Should().Be(1); @@ -551,7 +551,7 @@ public void DateTimePicker_PaintEvent_Raised_Success() control.Paint -= handler; using (Bitmap bmp = new(1, 1)) { - control.OnPaint(new(Graphics.FromImage(bmp), new())); + control.OnPaint(new(Graphics.FromImage(bmp), default)); } callCount.Should().Be(1); @@ -903,7 +903,7 @@ public void DateTimePicker_SysTimeToDateTime_DoesnThrowException_If_SYSTEMTIME_I { // An empty SYSTEMTIME has year, month and day as 0, but DateTime can't have these parameters. // So an empty SYSTEMTIME is incorrect in this case. - SYSTEMTIME systemTime = new(); + SYSTEMTIME systemTime = default; DateTime dateTime = (DateTime)systemTime; Assert.Equal(DateTime.MinValue, dateTime); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/ComponentEditorPageTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/ComponentEditorPageTests.cs index a34edef008e..7b401733779 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/ComponentEditorPageTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/ComponentEditorPageTests.cs @@ -631,7 +631,7 @@ public void ComponentEditorPage_IsLoading_Invoke_ReturnsFalse() public void ComponentEditorPage_IsPageMessage_Invoke_ReturnsExpected() { using SubComponentEditorPage control = new(); - Message message = new(); + Message message = default; Assert.True(control.IsPageMessage(ref message)); Assert.Equal(1, control.PreProcessMessageCallCount); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DomainUpDownTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DomainUpDownTests.cs index 210e4905ae6..26cef05cf48 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DomainUpDownTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DomainUpDownTests.cs @@ -20,10 +20,10 @@ public DomainUpDownTests() public void Dispose() { - _control.Items.Clear(); - _control.Dispose(); - _sub.Items.Clear(); - _sub.Dispose(); + _control.Items.Clear(); + _control.Dispose(); + _sub.Items.Clear(); + _sub.Dispose(); } [WinFormsFact] @@ -323,7 +323,7 @@ public void DomainUpDown_SelectedIndex_SetNotEmpty_GetReturnsExpected(int value, [InlineData(-1, null, "", false)] public void DomainUpDown_SelectedIndex_SetUserEdit_GetReturnsExpected(int value, object expected, string expectedText, bool expectedUserEdit) { - _sub.UserEdit=true; + _sub.UserEdit = true; _sub.Items.Add("Item1"); _sub.Items.Add("Item2"); @@ -354,7 +354,7 @@ public void DomainUpDown_SelectedIndex_SetUserEdit_GetReturnsExpected(int value, _sub.IsHandleCreated.Should().BeFalse(); } - [WinFormsFact] + [WinFormsFact] public void DomainUpDown_SelectedIndex_SetWithHandler_CallsSelectedItemChanged() { _control.Items.Add("Item1"); @@ -947,7 +947,7 @@ public void DomainUpDown_CreateAccessibilityInstance_InvokeWithCustomRole_Return { _sub.AccessibleRole = AccessibleRole.HelpBalloon; var instance = _sub.CreateAccessibilityInstance() as UpDownBase.UpDownBaseAccessibleObject; - + instance.Should().NotBeNull().And.BeOfType(); instance.Owner.Should().Be(_sub); instance.Role.Should().Be(AccessibleRole.HelpBalloon); @@ -1346,8 +1346,8 @@ public void DomainUpDown_UpdateEditText_InvokeNotEmptyWithSelection_Success(bool [WinFormsTheory] [InlineData(0, 1, false)] [InlineData(1, 2, false)] - [InlineData(2, 2, false)] - [InlineData(2, 0, true)] + [InlineData(2, 2, false)] + [InlineData(2, 0, true)] public void DomainUpDown_DownButton_InvokeWithItems_ChangesSelectedIndex(int initialIndex, int expectedIndex, bool wrap) { _control.Items.AddRange(new string[] { "Item1", "Item2", "Item3" }); @@ -1363,8 +1363,8 @@ public void DomainUpDown_DownButton_InvokeWithItems_ChangesSelectedIndex(int ini [WinFormsTheory] [InlineData(0, 2, false)] [InlineData(1, 2, false)] - [InlineData(2, 2, false)] - [InlineData(2, 1, true)] + [InlineData(2, 2, false)] + [InlineData(2, 1, true)] public void DomainUpDown_DownButton_InvokeMultipleTimes_ChangesSelectedIndex(int initialIndex, int expectedIndex, bool wrap) { _control.Items.AddRange(new string[] { "Item1", "Item2", "Item3" }); @@ -1373,7 +1373,7 @@ public void DomainUpDown_DownButton_InvokeMultipleTimes_ChangesSelectedIndex(int _control.Wrap = wrap; _control.DownButton(); - _control.DownButton(); + _control.DownButton(); _control.SelectedIndex.Should().Be(expectedIndex); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DragDropHelperTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DragDropHelperTests.cs index 0b6513cd67a..4d7752ca9f0 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DragDropHelperTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DragDropHelperTests.cs @@ -101,7 +101,7 @@ public void IsInDragLoopFormat_ReturnsExpected(string format, bool expectedIsInD Assert.Equal(expectedIsInDragLoopFormat, DragDropHelper.IsInDragLoopFormat(Unsafe.As(ref formatEtc))); } - [WinFormsTheory(Skip ="Causing issues with other tests on x86 from the command line")] + [WinFormsTheory(Skip = "Causing issues with other tests on x86 from the command line")] [MemberData(nameof(DragImage_DataObject_Bitmap_Point_bool_TestData))] public unsafe void SetDragImage_DataObject_Bitmap_Point_bool_ReturnsExpected(DataObject dataObject, Bitmap dragImage, Point cursorOffset, bool useDefaultDragImage) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/FontDialogTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/FontDialogTests.cs index 471af91d1f0..b07a98949f1 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/FontDialogTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/FontDialogTests.cs @@ -696,7 +696,7 @@ protected override unsafe void WndProc(ref Message m) { using Font font = new("Arial", 8.25f); LOGFONTW* pLogfont = (LOGFONTW*)m.LParam; - object lf = new LOGFONTW(); + object lf = default(LOGFONTW); font.ToLogFont(lf); *pLogfont = (LOGFONTW)lf; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/GridItemCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/GridItemCollectionTests.cs index 385a2c2ac89..9274b936e08 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/GridItemCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/GridItemCollectionTests.cs @@ -21,7 +21,7 @@ public void GridItemCollection_Empty_Get_ReturnsExpected() public void GridItemCollection_ICollection_GetProperties_ReturnsExpected() { ICollection collection = GridItemCollection.Empty; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlDocumentTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlDocumentTests.cs index f52a9821cb2..f78b989f63f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlDocumentTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlDocumentTests.cs @@ -613,7 +613,7 @@ public async Task HtmlDocument_Encoding_GetCustomValueSet_ReturnsExpected() validate(); unsafe void validate() { - using var iHTMLDocument2 = ComHelpers.GetComScope (document.DomDocument); + using var iHTMLDocument2 = ComHelpers.GetComScope(document.DomDocument); using BSTR charSet = new("UTF-8"); Assert.True(iHTMLDocument2.Value->put_charset(charSet).Succeeded); Assert.Equal("utf-8", document.Encoding); @@ -1963,9 +1963,9 @@ public async Task HtmlDocument_OperatorEquals_Invoke_ReturnsExpected() Assert.True(document == document); Assert.False(document == newDocument); - Assert.False(document == null); - Assert.False(document == null); - Assert.True(null == (HtmlDocument)null); + Assert.NotNull(document); + Assert.NotNull(document); + Assert.Null((HtmlDocument)null); } [WinFormsFact] @@ -1983,9 +1983,9 @@ public async Task HtmlDocument_OperatorNotEquals_Invoke_ReturnsExpected() Assert.False(document != document); Assert.True(document != newDocument); - Assert.True(document != null); - Assert.True(document != null); - Assert.False(null != (HtmlDocument)null); + Assert.NotNull(document); + Assert.NotNull(document); + Assert.Null((HtmlDocument)null); } #pragma warning restore CS1718, CSIsNull001, CSIsNull002 diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlElementTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlElementTests.cs index e3318db5225..d98b0981ac5 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlElementTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/HtmlElementTests.cs @@ -1288,7 +1288,7 @@ unsafe void validate() using BSTR bstrStyle = new(style); Assert.True(htmlStyle.Value->put_cssText(bstrStyle).Succeeded); Assert.Equal(expected, element.Style); - } + } } [WinFormsTheory] @@ -1326,7 +1326,7 @@ unsafe string GetStyleCssText() using BSTR cssText = default; Assert.True(htmlStyle.Value->get_cssText(&cssText).Succeeded); return cssText.ToString(); - } + } } [WinFormsFact] @@ -2352,7 +2352,7 @@ public async Task HtmlElement_InvokeMember_MemberExists_ReturnsExpected() Assert.Equal("value", element.InvokeMember("getAttribute", "attribute", 1)); Assert.Equal(Convert.DBNull, element.InvokeMember("getAttribute", "ATTRIBUTE", 1)); Assert.Equal(Convert.DBNull, element.InvokeMember("getAttribute", "NoSuchAttribute")); - Assert.Null(element.InvokeMember("getAttribute", new TimeSpan())); + Assert.Null(element.InvokeMember("getAttribute", default(TimeSpan))); } [WinFormsFact] @@ -2507,9 +2507,9 @@ public async Task HtmlElement_OperatorEquals_Invoke_ReturnsExpected() Assert.True(element1 == element1); Assert.True(element1 == element2); Assert.False(element1 == element3); - Assert.False(element1 == null); - Assert.False(element1 == null); - Assert.True(null == (HtmlElement)null); + Assert.NotNull(element1); + Assert.NotNull(element1); + Assert.Null((HtmlElement)null); } [WinFormsFact] @@ -2530,9 +2530,9 @@ public async Task HtmlElement_OperatorNotEquals_Invoke_ReturnsExpected() Assert.False(element1 != element1); Assert.False(element1 != element2); Assert.True(element1 != element3); - Assert.True(element1 != null); - Assert.True(element1 != null); - Assert.False(null != (HtmlElement)null); + Assert.NotNull(element1); + Assert.NotNull(element1); + Assert.Null((HtmlElement)null); } #pragma warning restore CS1718, CSIsNull001, CSIsNull002 @@ -2618,7 +2618,7 @@ unsafe void validate() } } - [WinFormsFact] + [WinFormsFact] public async Task HtmlElement_Drag_InvokeEvent_Success() { using Control parent = new(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageList.ImageCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageList.ImageCollectionTests.cs index eda22712394..c51b1711033 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageList.ImageCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageList.ImageCollectionTests.cs @@ -18,7 +18,7 @@ public void ImageCollection_Count_GetEmptyWithHandle_ReturnsExpected() Assert.NotEqual(IntPtr.Zero, list.Handle); ImageList.ImageCollection collection = list.Images; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); } [WinFormsFact] @@ -443,7 +443,7 @@ public void ImageCollection_Add_InvokeStringImage_Success(Color transparentColor ImageList.ImageCollection collection = list.Images; collection.Add("Key1", value); - Assert.Equal(1, collection.Count); + collection.Count.Should().Be(1); Assert.False(collection.Empty); Assert.Equal("Key1", Assert.Single(collection.Keys)); Assert.False(list.HandleCreated); @@ -488,7 +488,7 @@ public void ImageCollection_Add_InvokeStringImageWithHandle_Success(Color transp Assert.NotEqual(IntPtr.Zero, list.Handle); collection.Add("Key1", value); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal("Key1", Assert.Single(collection.Keys)); Assert.True(list.HandleCreated); @@ -532,7 +532,7 @@ public void ImageCollection_Add_InvokeImage_Success(Color transparentColor, Imag ImageList.ImageCollection collection = list.Images; collection.Add(value); - Assert.Equal(1, collection.Count); + collection.Count.Should().Be(1); Assert.False(collection.Empty); Assert.Equal(string.Empty, Assert.Single(collection.Keys)); Assert.False(list.HandleCreated); @@ -557,7 +557,7 @@ public void ImageCollection_Add_InvokeImageWithHandle_Success(Color transparentC Assert.NotEqual(IntPtr.Zero, list.Handle); collection.Add(value); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal(string.Empty, Assert.Single(collection.Keys)); Assert.True(list.HandleCreated); @@ -601,7 +601,7 @@ public void ImageCollection_Add_InvokeImageColor_Success(Color listTransparentCo ImageList.ImageCollection collection = list.Images; collection.Add(value, transparentColor); - Assert.Equal(1, collection.Count); + collection.Count.Should().Be(1); Assert.False(collection.Empty); Assert.Equal(string.Empty, Assert.Single(collection.Keys)); Assert.False(list.HandleCreated); @@ -626,7 +626,7 @@ public void ImageCollection_Add_InvokeImageColorWithHandle_Success(Color listTra Assert.NotEqual(IntPtr.Zero, list.Handle); collection.Add(value, transparentColor); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal(string.Empty, Assert.Single(collection.Keys)); Assert.True(list.HandleCreated); @@ -658,7 +658,7 @@ public void ImageCollection_Add_InvokeStringIcon_Success(Color transparentColor, ImageList.ImageCollection collection = list.Images; collection.Add("Key1", value); - Assert.Equal(1, collection.Count); + collection.Count.Should().Be(1); Assert.False(collection.Empty); Assert.Equal("Key1", Assert.Single(collection.Keys)); Assert.False(list.HandleCreated); @@ -703,7 +703,7 @@ public void ImageCollection_Add_InvokeStringIconWithHandle_Success(Color transpa Assert.NotEqual(IntPtr.Zero, list.Handle); collection.Add("Key1", value); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal("Key1", Assert.Single(collection.Keys)); Assert.True(list.HandleCreated); @@ -747,7 +747,7 @@ public void ImageCollection_Add_InvokeIcon_Success(Color transparentColor, Icon ImageList.ImageCollection collection = list.Images; collection.Add(value); - Assert.Equal(1, collection.Count); + collection.Count.Should().Be(1); Assert.False(collection.Empty); Assert.Equal(string.Empty, Assert.Single(collection.Keys)); Assert.False(list.HandleCreated); @@ -772,7 +772,7 @@ public void ImageCollection_Add_InvokeIconWithHandle_Success(Color transparentCo Assert.NotEqual(IntPtr.Zero, list.Handle); collection.Add(value); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal(string.Empty, Assert.Single(collection.Keys)); Assert.True(list.HandleCreated); @@ -973,14 +973,14 @@ public void ImageCollection_Clear_InvokeEmpty_Nop() collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.False(list.HandleCreated); // Clear again. collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.False(list.HandleCreated); } @@ -995,14 +995,14 @@ public void ImageCollection_Clear_InvokeNotEmpty_Success() collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.False(list.HandleCreated); // Clear again. collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.False(list.HandleCreated); } @@ -1016,14 +1016,14 @@ public void ImageCollection_Clear_InvokeEmptyWithHandle_Nop() collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.True(list.HandleCreated); // Clear again. collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.True(list.HandleCreated); } @@ -1039,14 +1039,14 @@ public void ImageCollection_Clear_InvokeNotEmptyWithHandle_Success() collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.True(list.HandleCreated); // Clear again. collection.Clear(); Assert.Empty(collection); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); Assert.True(list.HandleCreated); } @@ -1321,13 +1321,13 @@ public void ImageListCollection_RemoveAt_InvokeWithoutHandleNotEmpty_Success() // Remove first. collection.RemoveAt(0); Assert.True(list.HandleCreated); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); // Remove last. collection.RemoveAt(0); Assert.True(list.HandleCreated); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); } @@ -1361,14 +1361,14 @@ public void ImageListCollection_RemoveAt_InvokeWithHandleNotEmpty_Success() // Remove first. collection.RemoveAt(0); Assert.True(list.HandleCreated); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal(color3, ((Bitmap)collection[0]).GetPixel(0, 0)); // Remove last. collection.RemoveAt(0); Assert.True(list.HandleCreated); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); } @@ -1425,13 +1425,13 @@ public void ImageListCollection_RemoveByKey_InvokeWithoutHandleNotEmpty_Success( // Remove first. collection.RemoveByKey("image1"); Assert.True(list.HandleCreated); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); // Remove last. collection.RemoveByKey("IMAGE3"); Assert.True(list.HandleCreated); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); } @@ -1473,14 +1473,14 @@ public void ImageListCollection_RemoveByKey_InvokeWithHandleNotEmpty_Success() // Remove first. collection.RemoveByKey("image1"); Assert.True(list.HandleCreated); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.False(collection.Empty); Assert.Equal(color3, ((Bitmap)collection[0]).GetPixel(0, 0)); // Remove last. collection.RemoveByKey("IMAGE3"); Assert.True(list.HandleCreated); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.Empty); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs index 7cbca8b5ec0..957b0c531dc 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs @@ -835,8 +835,8 @@ public void ImageList_Dispose_InvokeWithIconsWithoutHandle_Success() list.Dispose(); Assert.False(list.HandleCreated); - Assert.Throws(() => list.Images.GetEnumerator()); - Assert.Equal(0, list.Images.Count); + Assert.Throws(list.Images.GetEnumerator); + list.Images.Count.Should().Be(0); Assert.True(list.HandleCreated); // Call again. diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LabelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LabelTests.cs index 2277aa88d08..587358df16d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LabelTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LabelTests.cs @@ -343,7 +343,7 @@ public void Label_BorderStyle_Set_GetReturnsExpected(bool autoSize, BorderStyle Assert.Equal(0, layoutCallCount); Assert.Equal(autoSize, control.AutoSize); Assert.False(control.IsHandleCreated); - } + } } [WinFormsTheory] @@ -373,7 +373,7 @@ public void Label_FlatStyle_Set_GetReturnsExpected(FlatStyle style) label.FlatStyle = FlatStyle.Flat; label.CreateControl(); Assert.True(label.IsHandleCreated); - Assert.Equal(FlatStyle.Flat, label.FlatStyle); + Assert.Equal(FlatStyle.Flat, label.FlatStyle); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs index 096397d77fb..cb3cc3e1865 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTests.cs @@ -645,7 +645,7 @@ public void TableLayoutSettings_SetCellPosition_NullControl_ThrowsArgumentNullEx { using TableLayoutPanel control = new(); TableLayoutSettings settings = control.LayoutSettings; - Assert.Throws("control", () => settings.SetCellPosition(null, new TableLayoutPanelCellPosition())); + Assert.Throws("control", () => settings.SetCellPosition(null, default)); } [WinFormsFact] @@ -653,7 +653,7 @@ public void TableLayoutSettings_SetCellPosition_NullControlStub_ThrowsArgumentNu { TableLayoutSettingsTypeConverter converter = new(); TableLayoutSettings settings = Assert.IsType(converter.ConvertFrom(@"")); - Assert.Throws("control", () => settings.SetCellPosition(null, new TableLayoutPanelCellPosition())); + Assert.Throws("control", () => settings.SetCellPosition(null, default)); } [WinFormsFact] @@ -661,7 +661,7 @@ public void TableLayoutSettings_SetCellPosition_InvalidControl_ThrowsNotSupporte { using TableLayoutPanel control = new(); TableLayoutSettings settings = control.LayoutSettings; - Assert.Throws(() => settings.SetCellPosition("control", new TableLayoutPanelCellPosition())); + Assert.Throws(() => settings.SetCellPosition("control", default)); } [WinFormsFact] @@ -669,8 +669,8 @@ public void TableLayoutSettings_SetCellPosition_InvalidControlStub_GetReturnsExp { TableLayoutSettingsTypeConverter converter = new(); TableLayoutSettings settings = Assert.IsType(converter.ConvertFrom(@"")); - settings.SetCellPosition("control", new TableLayoutPanelCellPosition()); - Assert.Equal(new TableLayoutPanelCellPosition(), settings.GetCellPosition("control")); + settings.SetCellPosition("control", default); + Assert.Equal(default, settings.GetCellPosition("control")); } [WinFormsTheory] @@ -1631,7 +1631,7 @@ public void TableLayoutSettings_ISerializableGetObjectData_InvokeSimple_Success( TableLayoutSettings settings = control.LayoutSettings; ISerializable iSerializable = settings; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal(@"", info.GetString("SerializedString")); @@ -1644,7 +1644,7 @@ public void TableLayoutSettings_ISerializableGetObjectData_InvokeSimpleStub_Succ TableLayoutSettings settings = Assert.IsType(converter.ConvertFrom(@"")); ISerializable iSerializable = settings; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal(@"", info.GetString("SerializedString")); @@ -1676,7 +1676,7 @@ public void TableLayoutSettings_ISerializableGetObjectData_InvokeAdvanced_Succes // Serialize. ISerializable iSerializable = settings; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal(@"", info.GetString("SerializedString")); @@ -1712,7 +1712,7 @@ public void TableLayoutSettings_ISerializableGetObjectData_InvokeAdvancedStub_Su // Serialize. ISerializable iSerializable = settings; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal(@"", info.GetString("SerializedString")); @@ -1728,7 +1728,7 @@ public void TableLayoutSettings_ISerializableGetObjectData_InvokeToolStrip_Succe TableLayoutSettings settings = Assert.IsType(control.LayoutSettings); ISerializable iSerializable = settings; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal(@"", info.GetString("SerializedString")); @@ -1759,7 +1759,7 @@ public void TableLayoutSettings_ISerializableGetObjectData_InvokeInvalidStringCo ISerializable iSerializable = settings; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Throws(() => info.GetString("SerializedString")); @@ -1837,7 +1837,7 @@ public void TableLayoutSettings_Deserialize_InvalidConverterResult_Success(Type using MemoryStream stream = new(); #pragma warning disable SYSLIB0011 // Type or member is obsolete // cs/binary-formatter-without-binder - BinaryFormatter formatter = new(); // CodeQL [SM04191] : This is a test. Safe use because the deserialization process is performed on trusted data and the types are controlled and validated. + BinaryFormatter formatter = new(); // CodeQL [SM04191] : This is a test. Safe use because the deserialization process is performed on trusted data and the types are controlled and validated. formatter.Serialize(stream, settings); stream.Seek(0, SeekOrigin.Begin); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs index 83b48e7394d..81ef556981f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs @@ -107,7 +107,7 @@ public void LinkAreaConverter_ConvertTo_ValueNotLinkArea_ThrowsNotSupportedExcep public void LinkAreaConverter_ConvertTo_InvalidDestinationType_ThrowsNotSupportedException(Type destinationType) { var converter = new LinkArea.LinkAreaConverter(); - Assert.Throws(() => converter.ConvertTo(new LinkArea(), destinationType)); + Assert.Throws(() => converter.ConvertTo(default(LinkArea), destinationType)); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaTests.cs index d032c48b41c..0aeae06df17 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaTests.cs @@ -11,7 +11,7 @@ public class LinkAreaTests [Fact] public void LinkArea_Ctor_Default() { - LinkArea area = new(); + LinkArea area = default; Assert.Equal(0, area.Start); Assert.Equal(0, area.Length); Assert.True(area.IsEmpty); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBindingHelperTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBindingHelperTests.cs index 8adcf9f1eb5..8c1468629d8 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBindingHelperTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBindingHelperTests.cs @@ -375,7 +375,7 @@ public static IEnumerable GetListItemProperties_Object_PropertyDescrip yield return new object[] { new IEnumerableWrapper(new object[] { new NonEnumerableITypedListImplementor() }), TypeDescriptor.GetProperties(typeof(NonEnumerableITypedListImplementor)).Cast().ToArray(), Array.Empty() }; yield return new object[] { typeof(NonEnumerableITypedListImplementor[]), descriptors, new string[] { "Property" } }; - ITypedListDataClass typedListDataClass = new () { ListProperty = [new()] }; + ITypedListDataClass typedListDataClass = new() { ListProperty = [new()] }; yield return new object[] { new ITypedListDataClass(), TypeDescriptor.GetProperties(typeof(ITypedListDataClass)).Cast().ToArray(), new string[] { "OtherProperty" } }; yield return new object[] { typedListDataClass, TypeDescriptor.GetProperties(typeof(ITypedListDataClass)).Cast().ToArray(), new string[] { "OtherProperty" } }; yield return new object[] { typeof(ITypedListDataClass), TypeDescriptor.GetProperties(typeof(ITypedListDataClass)).Cast().ToArray(), new string[] { "OtherProperty" } }; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.IntegerCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.IntegerCollectionTests.cs index 1bea8763143..847c0b4d640 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.IntegerCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.IntegerCollectionTests.cs @@ -12,7 +12,7 @@ public void ListBoxIntegerCollection_Ctor_ListBox() { using ListBox owner = new(); var collection = new ListBox.IntegerCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); } [WinFormsFact] @@ -27,7 +27,7 @@ public void ListBoxIntegerCollection_ICollection_Properties_GetReturnsExpected() { using ListBox owner = new(); ICollection collection = new ListBox.IntegerCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); } @@ -37,7 +37,7 @@ public void ListBoxIntegerCollection_IList_Properties_GetReturnsExpected() { using ListBox owner = new(); IList collection = new ListBox.IntegerCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsFixedSize); Assert.False(collection.IsReadOnly); Assert.True(collection.IsSynchronized); @@ -258,7 +258,7 @@ public void ListBoxIntegerCollection_Add_Invoke_Success(bool sorted, bool useCus // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -301,7 +301,7 @@ public void ListBoxIntegerCollection_Add_InvokeCustomTabOffsets_Success(bool sor // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.CustomTabOffsets.Cast()); Assert.False(owner.IsHandleCreated); @@ -351,7 +351,7 @@ public void ListBoxIntegerCollection_Add_InvokeWithHandle_Success(bool sorted, b // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -413,7 +413,7 @@ public void ListBoxIntegerCollection_Add_InvokeCustomTabOffsetsWithHandle_Succes // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.CustomTabOffsets.Cast()); Assert.True(owner.IsHandleCreated); @@ -787,16 +787,16 @@ public void ListBoxIntegerCollection_Clear_InvokeEmpty_Success() using ListBox owner = new(); var collection = new ListBox.IntegerCollection(owner); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -808,16 +808,16 @@ public void ListBoxIntegerCollection_Clear_InvokeCustomTabOffsetsEmpty_Success() using ListBox owner = new(); ListBox.IntegerCollection collection = owner.CustomTabOffsets; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -833,16 +833,16 @@ public void ListBoxIntegerCollection_Clear_InvokeNotEmpty_Success() }; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -856,16 +856,16 @@ public void ListBoxIntegerCollection_Clear_InvokeCustomTabOffsetNotEmpty_Success collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -885,8 +885,8 @@ public void ListBoxIntegerCollection_Clear_InvokeEmptyWithHandle_Success() owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -896,8 +896,8 @@ public void ListBoxIntegerCollection_Clear_InvokeEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -920,8 +920,8 @@ public void ListBoxIntegerCollection_Clear_InvokeCustomTabOffsetsEmptyWithHandle owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -931,8 +931,8 @@ public void ListBoxIntegerCollection_Clear_InvokeCustomTabOffsetsEmptyWithHandle // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -956,8 +956,8 @@ public void ListBoxIntegerCollection_Clear_InvokeNotEmptyWithHandle_Success() collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -967,8 +967,8 @@ public void ListBoxIntegerCollection_Clear_InvokeNotEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -992,8 +992,8 @@ public void ListBoxIntegerCollection_Clear_InvokeCustomTabOffsetNotEmptyWithHand collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1003,8 +1003,8 @@ public void ListBoxIntegerCollection_Clear_InvokeCustomTabOffsetNotEmptyWithHand // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1112,21 +1112,21 @@ public void ListBoxIntegerCollection_Remove_Invoke_Success(bool sorted, bool use // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -1156,21 +1156,21 @@ public void ListBoxIntegerCollection_Remove_InvokeCustomTabOffsets_Success(bool // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -1210,7 +1210,7 @@ public void ListBoxIntegerCollection_Remove_InvokeWithHandle_Success(bool sorted // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1220,7 +1220,7 @@ public void ListBoxIntegerCollection_Remove_InvokeWithHandle_Success(bool sorted // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1230,7 +1230,7 @@ public void ListBoxIntegerCollection_Remove_InvokeWithHandle_Success(bool sorted // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1273,7 +1273,7 @@ public void ListBoxIntegerCollection_Remove_InvokeCustomTabOffsetsWithHandle_Suc // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.True(owner.IsHandleCreated); @@ -1283,7 +1283,7 @@ public void ListBoxIntegerCollection_Remove_InvokeCustomTabOffsetsWithHandle_Suc // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1293,7 +1293,7 @@ public void ListBoxIntegerCollection_Remove_InvokeCustomTabOffsetsWithHandle_Suc // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1326,14 +1326,14 @@ public void ListBoxIntegerCollection_RemoveAt_Invoke_Success(bool sorted, bool u // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -1363,14 +1363,14 @@ public void ListBoxIntegerCollection_RemoveAt_InvokeCustomTabOffsets_Success(boo // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -1410,7 +1410,7 @@ public void ListBoxIntegerCollection_RemoveAt_InvokeWithHandle_Success(bool sort // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1420,7 +1420,7 @@ public void ListBoxIntegerCollection_RemoveAt_InvokeWithHandle_Success(bool sort // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1463,7 +1463,7 @@ public void ListBoxIntegerCollection_RemoveAt_InvokeCustomTabOffsetsWithHandle_S // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.True(owner.IsHandleCreated); @@ -1473,7 +1473,7 @@ public void ListBoxIntegerCollection_RemoveAt_InvokeCustomTabOffsetsWithHandle_S // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1756,7 +1756,7 @@ public void ListBoxIntegerCollection_IListAdd_Invoke_Success(bool sorted, bool u // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -1799,7 +1799,7 @@ public void ListBoxIntegerCollection_IListAdd_InvokeCustomTabOffsets_Success(boo // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.CustomTabOffsets.Cast()); Assert.False(owner.IsHandleCreated); @@ -1849,7 +1849,7 @@ public void ListBoxIntegerCollection_IListAdd_InvokeWithHandle_Success(bool sort // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -1911,7 +1911,7 @@ public void ListBoxIntegerCollection_IListAdd_InvokeCustomTabOffsetsWithHandle_S // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.CustomTabOffsets.Cast()); Assert.True(owner.IsHandleCreated); @@ -2004,16 +2004,16 @@ public void ListBoxIntegerCollection_IListClear_InvokeEmpty_Success() using ListBox owner = new(); IList collection = new ListBox.IntegerCollection(owner); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2025,16 +2025,16 @@ public void ListBoxIntegerCollection_IListClear_InvokeCustomTabOffsetsEmpty_Succ using ListBox owner = new(); IList collection = owner.CustomTabOffsets; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2050,16 +2050,16 @@ public void ListBoxIntegerCollection_IListClear_InvokeNotEmpty_Success() }; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2073,16 +2073,16 @@ public void ListBoxIntegerCollection_IListClear_InvokeCustomTabOffsetNotEmpty_Su collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2102,8 +2102,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeEmptyWithHandle_Success() owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2113,8 +2113,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2137,8 +2137,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeCustomTabOffsetsEmptyWithH owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2148,8 +2148,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeCustomTabOffsetsEmptyWithH // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2173,8 +2173,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeNotEmptyWithHandle_Success collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2184,8 +2184,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeNotEmptyWithHandle_Success // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2209,8 +2209,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeCustomTabOffsetNotEmptyWit collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2220,8 +2220,8 @@ public void ListBoxIntegerCollection_IListClear_InvokeCustomTabOffsetNotEmptyWit // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.CustomTabOffsets.Count); + Assert.Empty(collection); + Assert.Empty(owner.CustomTabOffsets); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2349,21 +2349,21 @@ public void ListBoxIntegerCollection_IListRemove_Invoke_Success(bool sorted, boo // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2396,21 +2396,21 @@ public void ListBoxIntegerCollection_IListRemove_InvokeCustomTabOffsets_Success( // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2455,7 +2455,7 @@ public void ListBoxIntegerCollection_IListRemove_InvokeWithHandle_Success(bool s // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2465,7 +2465,7 @@ public void ListBoxIntegerCollection_IListRemove_InvokeWithHandle_Success(bool s // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2475,7 +2475,7 @@ public void ListBoxIntegerCollection_IListRemove_InvokeWithHandle_Success(bool s // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2521,7 +2521,7 @@ public void ListBoxIntegerCollection_IListRemove_InvokeCustomTabOffsetsWithHandl // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.True(owner.IsHandleCreated); @@ -2531,7 +2531,7 @@ public void ListBoxIntegerCollection_IListRemove_InvokeCustomTabOffsetsWithHandl // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2541,7 +2541,7 @@ public void ListBoxIntegerCollection_IListRemove_InvokeCustomTabOffsetsWithHandl // Remove no such. collection.Remove(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2589,14 +2589,14 @@ public void ListBoxIntegerCollection_IListRemoveAt_Invoke_Success(bool sorted, b // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2629,14 +2629,14 @@ public void ListBoxIntegerCollection_IListRemoveAt_InvokeCustomTabOffsets_Succes // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.False(owner.IsHandleCreated); @@ -2681,7 +2681,7 @@ public void ListBoxIntegerCollection_IListRemoveAt_InvokeWithHandle_Success(bool // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2691,7 +2691,7 @@ public void ListBoxIntegerCollection_IListRemoveAt_InvokeWithHandle_Success(bool // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); @@ -2737,7 +2737,7 @@ public void ListBoxIntegerCollection_IListRemoveAt_InvokeCustomTabOffsetsWithHan // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.CustomTabOffsets.Cast()); Assert.True(owner.IsHandleCreated); @@ -2747,7 +2747,7 @@ public void ListBoxIntegerCollection_IListRemoveAt_InvokeCustomTabOffsetsWithHan // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.CustomTabOffsets); Assert.True(owner.IsHandleCreated); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.ObjectCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.ObjectCollectionTests.cs index 206cbecb879..8330dc61a80 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.ObjectCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.ObjectCollectionTests.cs @@ -12,7 +12,7 @@ public void ListBoxObjectCollection_Ctor_ListBox() { using ListBox owner = new(); var collection = new ListBox.ObjectCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(collection.IsReadOnly); @@ -63,7 +63,7 @@ public void ListBoxObjectCollection_Ctor_OwnerHasDataSource_ThrowsArgumentExcept var emptyCollection = new ListBox.ObjectCollection(owner); Assert.Empty(emptyCollection); - Assert.Equal(0, emptyCollection.Count); + Assert.Empty(emptyCollection); Assert.Empty(emptyCollection); Assert.Empty(owner.Items); Assert.False(emptyCollection.IsReadOnly); @@ -84,7 +84,7 @@ public void ListBoxObjectCollection_ICollection_Properties_GetReturnsExpected() { using ListBox owner = new(); ICollection collection = new ListBox.ObjectCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); } @@ -94,7 +94,7 @@ public void ListBoxObjectCollection_IList_Properties_GetReturnsExpected() { using ListBox owner = new(); IList collection = new ListBox.ObjectCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsFixedSize); Assert.False(collection.IsReadOnly); Assert.False(collection.IsSynchronized); @@ -1303,7 +1303,7 @@ public void ListBoxObjectCollection_Add_NotSorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -1344,7 +1344,7 @@ public void ListBoxObjectCollection_Add_ItemsNotSorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -1388,7 +1388,7 @@ public void ListBoxObjectCollection_Add_Sorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -1432,7 +1432,7 @@ public void ListBoxObjectCollection_Add_ItemsSorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -1479,7 +1479,7 @@ public unsafe void ListBoxObjectCollection_Add_NotSortedWithHandle_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -1558,7 +1558,7 @@ public unsafe void ListBoxObjectCollection_Add_ItemsNotSortedWithHandle_Success( // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -1640,7 +1640,7 @@ public unsafe void ListBoxObjectCollection_Add_SortedWithHandle_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -1722,7 +1722,7 @@ public unsafe void ListBoxObjectCollection_Add_ItemsSortedWithHandle_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -3701,16 +3701,16 @@ public void ListBoxObjectCollection_Clear_InvokeEmpty_Success() using ListBox owner = new(); var collection = new ListBox.ObjectCollection(owner); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -3722,16 +3722,16 @@ public void ListBoxObjectCollection_Clear_InvokeItemsEmpty_Success() using ListBox owner = new(); ListBox.ObjectCollection collection = owner.Items; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -3747,16 +3747,16 @@ public void ListBoxObjectCollection_Clear_InvokeNotEmpty_Success() }; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -3770,16 +3770,16 @@ public void ListBoxObjectCollection_Clear_InvokeItemsNotEmpty_Success() collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -3799,8 +3799,8 @@ public void ListBoxObjectCollection_Clear_InvokeEmptyWithHandle_Success() owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3811,8 +3811,8 @@ public void ListBoxObjectCollection_Clear_InvokeEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3836,8 +3836,8 @@ public void ListBoxObjectCollection_Clear_InvokeItemsEmptyWithHandle_Success() owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3848,8 +3848,8 @@ public void ListBoxObjectCollection_Clear_InvokeItemsEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3874,8 +3874,8 @@ public void ListBoxObjectCollection_Clear_InvokeNotEmptyWithHandle_Success() collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3886,8 +3886,8 @@ public void ListBoxObjectCollection_Clear_InvokeNotEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3912,8 +3912,8 @@ public void ListBoxObjectCollection_Clear_InvokeItemsNotEmptyWithHandle_Success( collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -3924,8 +3924,8 @@ public void ListBoxObjectCollection_Clear_InvokeItemsNotEmptyWithHandle_Success( // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -4126,7 +4126,7 @@ public void ListBoxObjectCollection_Insert_NotSorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -4167,7 +4167,7 @@ public void ListBoxObjectCollection_Insert_ItemsNotSorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -4211,7 +4211,7 @@ public void ListBoxObjectCollection_Insert_Sorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -4255,7 +4255,7 @@ public void ListBoxObjectCollection_Insert_ItemsSorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -4302,7 +4302,7 @@ public unsafe void ListBoxObjectCollection_Insert_NotSortedWithHandle_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -4381,7 +4381,7 @@ public unsafe void ListBoxObjectCollection_Insert_ItemsNotSortedWithHandle_Succe // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -4463,7 +4463,7 @@ public unsafe void ListBoxObjectCollection_Insert_SortedWithHandle_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -4545,7 +4545,7 @@ public unsafe void ListBoxObjectCollection_Insert_ItemsSortedWithHandle_Success( // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -5081,7 +5081,7 @@ public void ListBoxObjectCollection_Remove_NotSorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5089,7 +5089,7 @@ public void ListBoxObjectCollection_Remove_NotSorted_Success() // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5123,14 +5123,14 @@ public void ListBoxObjectCollection_Remove_ItemsNotSorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5171,7 +5171,7 @@ public void ListBoxObjectCollection_Remove_Sorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5179,7 +5179,7 @@ public void ListBoxObjectCollection_Remove_Sorted_Success() // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5216,14 +5216,14 @@ public void ListBoxObjectCollection_Remove_ItemsSorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5279,7 +5279,7 @@ public unsafe void ListBoxObjectCollection_Remove_NotSortedWithHandle_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -5292,7 +5292,7 @@ public unsafe void ListBoxObjectCollection_Remove_NotSortedWithHandle_Success() // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -5355,7 +5355,7 @@ public unsafe void ListBoxObjectCollection_Remove_ItemsNotSortedWithHandle_Succe // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5369,7 +5369,7 @@ public unsafe void ListBoxObjectCollection_Remove_ItemsNotSortedWithHandle_Succe // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -5431,7 +5431,7 @@ public unsafe void ListBoxObjectCollection_Remove_SortedWithHandle_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -5444,7 +5444,7 @@ public unsafe void ListBoxObjectCollection_Remove_SortedWithHandle_Success() // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -5510,7 +5510,7 @@ public unsafe void ListBoxObjectCollection_Remove_ItemsSortedWithHandle_Success( // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -5524,7 +5524,7 @@ public unsafe void ListBoxObjectCollection_Remove_ItemsSortedWithHandle_Success( // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -6020,7 +6020,7 @@ public void ListBoxObjectCollection_RemoveAt_NotSorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6028,7 +6028,7 @@ public void ListBoxObjectCollection_RemoveAt_NotSorted_Success() // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6055,14 +6055,14 @@ public void ListBoxObjectCollection_RemoveAt_ItemsNotSorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6095,7 +6095,7 @@ public void ListBoxObjectCollection_RemoveAt_Sorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6103,7 +6103,7 @@ public void ListBoxObjectCollection_RemoveAt_Sorted_Success() // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6133,14 +6133,14 @@ public void ListBoxObjectCollection_RemoveAt_ItemsSorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6181,7 +6181,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_NotSortedWithHandle_Success( // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -6194,7 +6194,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_NotSortedWithHandle_Success( // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -6241,7 +6241,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_ItemsNotSortedWithHandle_Suc // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6255,7 +6255,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_ItemsNotSortedWithHandle_Suc // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -6302,7 +6302,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_SortedWithHandle_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -6315,7 +6315,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_SortedWithHandle_Success() // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -6365,7 +6365,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_ItemsSortedWithHandle_Succes // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -6379,7 +6379,7 @@ public unsafe void ListBoxObjectCollection_RemoveAt_ItemsSortedWithHandle_Succes // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -8108,7 +8108,7 @@ public void ListBoxObjectCollection_IListAdd_NotSorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -8149,7 +8149,7 @@ public void ListBoxObjectCollection_IListAdd_ItemsNotSorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -8193,7 +8193,7 @@ public void ListBoxObjectCollection_IListAdd_Sorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -8237,7 +8237,7 @@ public void ListBoxObjectCollection_IListAdd_ItemsSorted_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -8284,7 +8284,7 @@ public unsafe void ListBoxObjectCollection_IListAdd_NotSortedWithHandle_Success( // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -8363,7 +8363,7 @@ public unsafe void ListBoxObjectCollection_IListAdd_ItemsNotSortedWithHandle_Suc // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -8445,7 +8445,7 @@ public unsafe void ListBoxObjectCollection_IListAdd_SortedWithHandle_Success() // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -8527,7 +8527,7 @@ public unsafe void ListBoxObjectCollection_IListAdd_ItemsSortedWithHandle_Succes // Add one. Assert.Equal(0, collection.Add(2)); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 2 }, collection.Cast()); Assert.Equal(new object[] { 2 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -9023,16 +9023,16 @@ public void ListBoxObjectCollection_IListClear_InvokeEmpty_Success() using ListBox owner = new(); IList collection = new ListBox.ObjectCollection(owner); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -9044,16 +9044,16 @@ public void ListBoxObjectCollection_IListClear_InvokeItemsEmpty_Success() using ListBox owner = new(); IList collection = owner.Items; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -9069,16 +9069,16 @@ public void ListBoxObjectCollection_IListClear_InvokeNotEmpty_Success() }; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -9092,16 +9092,16 @@ public void ListBoxObjectCollection_IListClear_InvokeItemsNotEmpty_Success() collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.False(owner.IsHandleCreated); @@ -9121,8 +9121,8 @@ public void ListBoxObjectCollection_IListClear_InvokeEmptyWithHandle_Success() owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9133,8 +9133,8 @@ public void ListBoxObjectCollection_IListClear_InvokeEmptyWithHandle_Success() // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9158,8 +9158,8 @@ public void ListBoxObjectCollection_IListClear_InvokeItemsEmptyWithHandle_Succes owner.HandleCreated += (sender, e) => createdCallCount++; collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9170,8 +9170,8 @@ public void ListBoxObjectCollection_IListClear_InvokeItemsEmptyWithHandle_Succes // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9196,8 +9196,8 @@ public void ListBoxObjectCollection_IListClear_InvokeNotEmptyWithHandle_Success( collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9208,8 +9208,8 @@ public void ListBoxObjectCollection_IListClear_InvokeNotEmptyWithHandle_Success( // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9234,8 +9234,8 @@ public void ListBoxObjectCollection_IListClear_InvokeItemsNotEmptyWithHandle_Suc collection.Add(1); collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9246,8 +9246,8 @@ public void ListBoxObjectCollection_IListClear_InvokeItemsNotEmptyWithHandle_Suc // Call again. collection.Clear(); - Assert.Equal(0, collection.Count); - Assert.Equal(0, owner.Items.Count); + Assert.Empty(collection); + Assert.Empty(owner.Items); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9448,7 +9448,7 @@ public void ListBoxObjectCollection_IListInsert_NotSorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -9489,7 +9489,7 @@ public void ListBoxObjectCollection_IListInsert_ItemsNotSorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -9533,7 +9533,7 @@ public void ListBoxObjectCollection_IListInsert_Sorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -9577,7 +9577,7 @@ public void ListBoxObjectCollection_IListInsert_ItemsSorted_Success() // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -9624,7 +9624,7 @@ public unsafe void ListBoxObjectCollection_IListInsert_NotSortedWithHandle_Succe // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9703,7 +9703,7 @@ public unsafe void ListBoxObjectCollection_IListInsert_ItemsNotSortedWithHandle_ // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -9785,7 +9785,7 @@ public unsafe void ListBoxObjectCollection_IListInsert_SortedWithHandle_Success( // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -9867,7 +9867,7 @@ public unsafe void ListBoxObjectCollection_IListInsert_ItemsSortedWithHandle_Suc // Insert first. collection.Insert(0, 1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new object[] { 1 }, collection.Cast()); Assert.Equal(new object[] { 1 }, owner.Items.Cast()); Assert.True(owner.IsHandleCreated); @@ -10403,7 +10403,7 @@ public void ListBoxObjectCollection_IListRemove_NotSorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10411,7 +10411,7 @@ public void ListBoxObjectCollection_IListRemove_NotSorted_Success() // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10445,14 +10445,14 @@ public void ListBoxObjectCollection_IListRemove_ItemsNotSorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10493,7 +10493,7 @@ public void ListBoxObjectCollection_IListRemove_Sorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10501,7 +10501,7 @@ public void ListBoxObjectCollection_IListRemove_Sorted_Success() // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10538,14 +10538,14 @@ public void ListBoxObjectCollection_IListRemove_ItemsSorted_Success() // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10601,7 +10601,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_NotSortedWithHandle_Succe // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -10614,7 +10614,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_NotSortedWithHandle_Succe // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -10677,7 +10677,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_ItemsNotSortedWithHandle_ // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10691,7 +10691,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_ItemsNotSortedWithHandle_ // Remove first. collection.Remove(2); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -10753,7 +10753,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_SortedWithHandle_Success( // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -10766,7 +10766,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_SortedWithHandle_Success( // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -10832,7 +10832,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_ItemsSortedWithHandle_Suc // Remove last. collection.Remove(3); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -10846,7 +10846,7 @@ public unsafe void ListBoxObjectCollection_IListRemove_ItemsSortedWithHandle_Suc // Remove first. collection.Remove(1); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -11342,7 +11342,7 @@ public void ListBoxObjectCollection_IListRemoveAt_NotSorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11350,7 +11350,7 @@ public void ListBoxObjectCollection_IListRemoveAt_NotSorted_Success() // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11377,14 +11377,14 @@ public void ListBoxObjectCollection_IListRemoveAt_ItemsNotSorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11417,7 +11417,7 @@ public void ListBoxObjectCollection_IListRemoveAt_Sorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11425,7 +11425,7 @@ public void ListBoxObjectCollection_IListRemoveAt_Sorted_Success() // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11455,14 +11455,14 @@ public void ListBoxObjectCollection_IListRemoveAt_ItemsSorted_Success() // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.False(owner.IsHandleCreated); // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11503,7 +11503,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_NotSortedWithHandle_Suc // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -11516,7 +11516,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_NotSortedWithHandle_Suc // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -11563,7 +11563,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_ItemsNotSortedWithHandl // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 2 }, collection.Cast()); Assert.Equal(new int[] { 2 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11577,7 +11577,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_ItemsNotSortedWithHandl // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -11624,7 +11624,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_SortedWithHandle_Succes // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -11637,7 +11637,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_SortedWithHandle_Succes // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); @@ -11687,7 +11687,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_ItemsSortedWithHandle_S // Remove last. collection.RemoveAt(1); - Assert.Equal(1, collection.Count); + Assert.Single(collection); Assert.Equal(new int[] { 1 }, collection.Cast()); Assert.Equal(new int[] { 1 }, owner.Items.Cast()); Assert.Equal(0, selectedIndexChangedCallCount); @@ -11701,7 +11701,7 @@ public unsafe void ListBoxObjectCollection_IListRemoveAt_ItemsSortedWithHandle_S // Remove first. collection.RemoveAt(0); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.Empty(collection); Assert.Empty(owner.Items); Assert.True(owner.IsHandleCreated); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedIndexCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedIndexCollectionTests.cs index 2f641f67fee..8d79119326d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedIndexCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedIndexCollectionTests.cs @@ -12,7 +12,7 @@ public void ListBoxSelectedIndexCollection_Ctor_ListBox() { using ListBox owner = new(); var collection = new ListBox.SelectedIndexCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.IsReadOnly); } @@ -28,7 +28,7 @@ public void ListBoxSelectedIndexCollection_ICollection_Properties_GetReturnsExpe { using ListBox owner = new(); ICollection collection = new ListBox.SelectedIndexCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); } @@ -38,7 +38,7 @@ public void ListBoxSelectedIndexCollection_IList_Properties_GetReturnsExpected() { using ListBox owner = new(); IList collection = new ListBox.SelectedIndexCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.IsFixedSize); Assert.True(collection.IsReadOnly); Assert.True(collection.IsSynchronized); @@ -78,7 +78,7 @@ public void ListBoxSelectedIndexCollection_IListClear_Invoke_ThrowsNotSupportedE { using ListBox owner = new(); IList collection = new ListBox.SelectedIndexCollection(owner); - Assert.Throws(() => collection.Clear()); + Assert.Throws(collection.Clear); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedObjectCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedObjectCollectionTests.cs index 4e13bafe9f9..858e881caf5 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedObjectCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBox.SelectedObjectCollectionTests.cs @@ -12,7 +12,7 @@ public void ListBoxSelectedObjectCollection_Ctor_ListBox() { using ListBox owner = new(); var collection = new ListBox.SelectedObjectCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.IsReadOnly); } @@ -28,7 +28,7 @@ public void ListBoxSelectedObjectCollection_ICollection_Properties_GetReturnsExp { using ListBox owner = new(); ICollection collection = new ListBox.SelectedObjectCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsSynchronized); Assert.Same(collection, collection.SyncRoot); } @@ -38,7 +38,7 @@ public void ListBoxSelectedObjectCollection_IList_Properties_GetReturnsExpected( { using ListBox owner = new(); IList collection = new ListBox.SelectedObjectCollection(owner); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.True(collection.IsFixedSize); Assert.True(collection.IsReadOnly); Assert.False(collection.IsSynchronized); @@ -78,7 +78,7 @@ public void ListBoxSelectedObjectCollection_IListClear_Invoke_ThrowsNotSupported { using ListBox owner = new(); IList collection = new ListBox.SelectedObjectCollection(owner); - Assert.Throws(() => collection.Clear()); + Assert.Throws(collection.Clear); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBoxTests.cs index f4a12d27970..d239a285249 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListBoxTests.cs @@ -5381,7 +5381,7 @@ public void ListBox_GetItemRectangle_InvokeWithHandle_ReturnsExpected() public static IEnumerable GetItemRectangle_CustomGetItemRect_TestData() { - yield return new object[] { new RECT(), Rectangle.Empty }; + yield return new object[] { default(RECT), Rectangle.Empty }; yield return new object[] { new RECT(1, 2, 3, 4), new Rectangle(1, 2, 2, 2) }; } @@ -6124,24 +6124,24 @@ public void ListBox_Remove_NotSelectedItems_IfOneItemSelected(bool createControl Assert.Equal(3, listBox.Items.Count); Assert.Equal(listBox.Items[0], listBox.SelectedItem); Assert.Equal(0, listBox.SelectedIndex); - Assert.Equal(1, listBox.SelectedIndices.Count); - Assert.Equal(1, listBox.SelectedItems.Count); + Assert.Single(listBox.SelectedIndices); + Assert.Single(listBox.SelectedItems); listBox.Items.Remove(listBox.Items[2]); Assert.Equal(2, listBox.Items.Count); Assert.Equal(listBox.Items[0], listBox.SelectedItem); Assert.Equal(0, listBox.SelectedIndex); - Assert.Equal(1, listBox.SelectedIndices.Count); - Assert.Equal(1, listBox.SelectedItems.Count); + Assert.Single(listBox.SelectedIndices); + Assert.Single(listBox.SelectedItems); listBox.Items.Remove(listBox.Items[1]); - Assert.Equal(1, listBox.Items.Count); + Assert.Single(listBox.Items); Assert.Equal(listBox.Items[0], listBox.SelectedItem); Assert.Equal(0, listBox.SelectedIndex); - Assert.Equal(1, listBox.SelectedIndices.Count); - Assert.Equal(1, listBox.SelectedItems.Count); + Assert.Single(listBox.SelectedIndices); + Assert.Single(listBox.SelectedItems); Assert.Equal(createControl, listBox.IsHandleCreated); } @@ -6207,8 +6207,8 @@ public void ListBox_Remove_SelectedItem(bool createControl) Assert.Equal(listBox.Items[0], listBox.SelectedItem); Assert.Equal(0, listBox.SelectedIndex); - Assert.Equal(1, listBox.SelectedIndices.Count); - Assert.Equal(1, listBox.SelectedItems.Count); + Assert.Single(listBox.SelectedIndices); + Assert.Single(listBox.SelectedItems); listBox.Items.Remove(listBox.Items[0]); count -= 1; @@ -6216,8 +6216,8 @@ public void ListBox_Remove_SelectedItem(bool createControl) Assert.Equal(count, listBox.Items.Count); Assert.Null(listBox.SelectedItem); Assert.Equal(-1, listBox.SelectedIndex); - Assert.Equal(0, listBox.SelectedIndices.Count); - Assert.Equal(0, listBox.SelectedItems.Count); + Assert.Empty(listBox.SelectedIndices); + Assert.Empty(listBox.SelectedItems); } } @@ -6243,8 +6243,8 @@ public void ListBox_Remove_SelectedItems(SelectionMode mode, bool createControl) Assert.Equal(listBox.Items[0], listBox.SelectedItem); Assert.Equal(0, listBox.SelectedIndex); - Assert.Equal(1, listBox.SelectedIndices.Count); - Assert.Equal(1, listBox.SelectedItems.Count); + Assert.Single(listBox.SelectedIndices); + Assert.Single(listBox.SelectedItems); listBox.Items.Remove(listBox.Items[0]); @@ -6253,8 +6253,8 @@ public void ListBox_Remove_SelectedItems(SelectionMode mode, bool createControl) Assert.Equal(count, listBox.Items.Count); Assert.Null(listBox.SelectedItem); Assert.Equal(-1, listBox.SelectedIndex); - Assert.Equal(0, listBox.SelectedIndices.Count); - Assert.Equal(0, listBox.SelectedItems.Count); + Assert.Empty(listBox.SelectedIndices); + Assert.Empty(listBox.SelectedItems); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupCollectionTests.cs index 590b9613f37..d697a2386b2 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupCollectionTests.cs @@ -12,7 +12,7 @@ public void ListViewGroupCollection_IList_GetProperties_ReturnsExpected() { using ListView listView = new(); IList collection = listView.Groups; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsFixedSize); Assert.False(collection.IsReadOnly); Assert.True(collection.IsSynchronized); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupTests.cs index 74a9577075d..211104a2cdf 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupTests.cs @@ -599,6 +599,8 @@ public unsafe void ListViewGroup_Footer_GetGroupInfo_Success() // Run this from another thread as we call Application.EnableVisualStyles. using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() => { + char* buffer = stackalloc char[256]; + foreach (object[] data in Property_TypeString_GetGroupInfo_TestData()) { string value = (string)data[0]; @@ -614,7 +616,6 @@ public unsafe void ListViewGroup_Footer_GetGroupInfo_Success() group.Footer = value; Assert.Equal(1, (int)PInvokeCore.SendMessage(listView, PInvoke.LVM_GETGROUPCOUNT)); - char* buffer = stackalloc char[256]; LVGROUP lvgroup = new() { cbSize = (uint)sizeof(LVGROUP), @@ -859,6 +860,8 @@ public unsafe void ListViewGroup_Header_GetGroupInfo_Success() // Run this from another thread as we call Application.EnableVisualStyles. using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() => { + char* buffer = stackalloc char[256]; + foreach (object[] data in Property_TypeString_GetGroupInfo_TestData()) { string value = (string)data[0]; @@ -874,7 +877,7 @@ public unsafe void ListViewGroup_Header_GetGroupInfo_Success() group.Header = value; Assert.Equal(1, (int)PInvokeCore.SendMessage(listView, PInvoke.LVM_GETGROUPCOUNT)); - char* buffer = stackalloc char[256]; + LVGROUP lvgroup = new() { cbSize = (uint)sizeof(LVGROUP), @@ -1363,7 +1366,7 @@ public void ListViewGroup_ISerializableGetObjectData_InvokeSimple_Success() ListViewGroup group = new(); ISerializable iSerializable = group; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal("ListViewGroup", info.GetString("Header")); @@ -1381,7 +1384,7 @@ public void ListViewGroup_ISerializableGetObjectData_InvokeWithEmptyItems_Succes ISerializable iSerializable = group; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal("ListViewGroup", info.GetString("Header")); @@ -1399,7 +1402,7 @@ public void ListViewGroup_ISerializableGetObjectData_InvokeWithItems_Success() ISerializable iSerializable = group; SerializationInfo info = new(typeof(ListViewGroup), new FormatterConverter()); - StreamingContext context = new(); + StreamingContext context = default; iSerializable.GetObjectData(info, context); Assert.Equal("ListViewGroup", info.GetString("Header")); @@ -1415,7 +1418,7 @@ public void ListViewGroup_ISerializableGetObjectData_NullInfo_ThrowsArgumentNull { ListViewGroup group = new(); ISerializable iSerializable = group; - StreamingContext context = new(); + StreamingContext context = default; Assert.Throws("info", () => iSerializable.GetObjectData(null, context)); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs index f08f37d2471..7071fa662ff 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs @@ -212,7 +212,7 @@ public void ListViewInsertionMark_Bounds_GetWithHandle_ReturnsEqual() public static IEnumerable Bounds_GetCustomInsertMarkRect_TestData() { - yield return new object[] { new RECT(), Rectangle.Empty }; + yield return new object[] { default(RECT), Rectangle.Empty }; yield return new object[] { new RECT(1, 2, 3, 4), new Rectangle(1, 2, 2, 2) }; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItem.IKeyboardToolTipTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItem.IKeyboardToolTipTests.cs index e4a8b3ddabb..9f819601786 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItem.IKeyboardToolTipTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItem.IKeyboardToolTipTests.cs @@ -208,7 +208,7 @@ public void ListViewItemKeyboardToolTip_InvokeGetNeighboringToolsRectangles_With { ListViewItem listViewItem = new(); - Assert.Equal(0, ((IKeyboardToolTip)listViewItem).GetNeighboringToolsRectangles().Count); + Assert.Empty(((IKeyboardToolTip)listViewItem).GetNeighboringToolsRectangles()); } [WinFormsTheory] @@ -219,7 +219,7 @@ public void ListViewItemKeyboardToolTip_InvokeGetNeighboringToolsRectangles_View using var listView = GetListView(virtualMode, view: View.List); ListViewItem listViewItem = AssignItemToListView(listView, new ListViewItem()); - Assert.Equal(0, ((IKeyboardToolTip)listViewItem).GetNeighboringToolsRectangles().Count); + Assert.Empty(((IKeyboardToolTip)listViewItem).GetNeighboringToolsRectangles()); } [WinFormsFact] @@ -228,7 +228,7 @@ public void ListViewItemKeyboardToolTip_InvokeGetNeighboringToolsRectangles_View using var listView = GetListView(virtualMode: false, view: View.Tile); ListViewItem listViewItem = AssignItemToListView(listView, new ListViewItem()); - Assert.Equal(0, ((IKeyboardToolTip)listViewItem).GetNeighboringToolsRectangles().Count); + Assert.Empty(((IKeyboardToolTip)listViewItem).GetNeighboringToolsRectangles()); } // The ListView is configured to display items as follows: diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemStateImageIndexConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemStateImageIndexConverterTests.cs index a55c6176541..3166bf4276e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemStateImageIndexConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemStateImageIndexConverterTests.cs @@ -21,6 +21,6 @@ public void ListViewItemStateImageIndexConverter_GetStandardValues_Null_Context_ StandardValuesCollection result = converter.GetStandardValues(context: null); - Assert.Equal(0, result.Count); + Assert.Empty(result); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemCollectionTests.cs index 4cdfa82f478..6fd19519217 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemCollectionTests.cs @@ -28,7 +28,7 @@ public void ListViewSubItemCollection_IList_GetProperties_ReturnsExpected() { ListViewItem item = new(); IList collection = new ListViewItem.ListViewSubItemCollection(item); - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsFixedSize); Assert.False(collection.IsReadOnly); Assert.True(collection.IsSynchronized); @@ -1112,7 +1112,7 @@ public void ListViewSubItemCollection_RemoveByKey_RemoveOwner() ListViewItem listViewItem = new("Test 1"); ListViewItem.ListViewSubItem oldSubItem = listViewItem.SubItems[0]; oldSubItem.Name = "Test 1"; - ListViewItem.ListViewSubItem subItem = new(listViewItem, "Test 2") { Name = "Test 2" }; + ListViewItem.ListViewSubItem subItem = new(listViewItem, "Test 2") { Name = "Test 2" }; listViewItem.SubItems.Add(subItem); Assert.Same(listViewItem, subItem._owner); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs index 5ba31df97ea..7821ce1b180 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs @@ -4140,7 +4140,7 @@ public void ListView_GetItemRect_InvokeWithHandle_ReturnsExpected() public static IEnumerable GetItemRect_InvokeCustomGetItemRect_TestData() { - yield return new object[] { new RECT(), Rectangle.Empty }; + yield return new object[] { default(RECT), Rectangle.Empty }; yield return new object[] { new RECT(1, 2, 3, 4), new Rectangle(1, 2, 2, 2) }; } @@ -4482,7 +4482,7 @@ public void ListView_WmReflectNotify_LVN_KEYDOWN_WithoutGroups_and_CheckBoxes_Do control.Items.Add(new ListViewItem()); control.CreateControl(); PInvokeCore.SendMessage(control, PInvokeCore.WM_KEYDOWN); - Assert.Equal(0, control.SelectedItems.Count); + Assert.Empty(control.SelectedItems); } [WinFormsTheory] @@ -5531,23 +5531,23 @@ public void ListView_Remove_NotSelectedItems(View view, bool showGroups) Assert.True(listView.Items[0].Selected); Assert.Equal(3, listView.Items.Count); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); listView.Items.Remove(listView.Items[1]); Assert.True(listView.Items[0].Selected); Assert.Equal(2, listView.Items.Count); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); Assert.True(listView.Items[0].Selected); listView.Items.Remove(listView.Items[1]); Assert.True(listView.Items[0].Selected); - Assert.Equal(1, listView.Items.Count); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.Items); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); Assert.True(listView.Items[0].Selected); } @@ -5567,8 +5567,8 @@ public void ListView_Remove_SelectedItems(View view, bool showGroups) Assert.True(item.Selected); Assert.Equal(count, listView.Items.Count); Assert.Equal(listView, item.ListView); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); listView.Items.Remove(item); count -= 1; @@ -5576,8 +5576,8 @@ public void ListView_Remove_SelectedItems(View view, bool showGroups) Assert.True(item.Selected); Assert.Equal(count, listView.Items.Count); Assert.Null(item.ListView); - Assert.Equal(0, listView.SelectedItems.Count); - Assert.Equal(0, listView.SelectedIndices.Count); + Assert.Empty(listView.SelectedItems); + Assert.Empty(listView.SelectedIndices); } } @@ -5593,22 +5593,22 @@ public void ListView_Remove_NotCheckedItems(View view, bool showGroups) Assert.True(listView.Items[0].Checked); Assert.Equal(3, listView.Items.Count); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); listView.Items.Remove(listView.Items[1]); Assert.True(listView.Items[0].Checked); Assert.Equal(2, listView.Items.Count); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); listView.Items.Remove(listView.Items[1]); Assert.True(listView.Items[0].Checked); - Assert.Equal(1, listView.Items.Count); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.Items); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); } [WinFormsTheory] @@ -5627,8 +5627,8 @@ public void ListView_Remove_CheckedItems(View view, bool showGroups) Assert.True(item.Checked); Assert.Equal(count, listView.Items.Count); Assert.Equal(listView, item.ListView); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); listView.Items.Remove(item); count -= 1; @@ -5636,8 +5636,8 @@ public void ListView_Remove_CheckedItems(View view, bool showGroups) Assert.True(item.Checked); Assert.Equal(count, listView.Items.Count); Assert.Null(item.ListView); - Assert.Equal(0, listView.CheckedItems.Count); - Assert.Equal(0, listView.CheckedIndices.Count); + Assert.Empty(listView.CheckedItems); + Assert.Empty(listView.CheckedIndices); } } @@ -5657,25 +5657,25 @@ public void ListView_Remove_Group_WithNotSelectedItems(View view, bool showGroup Assert.True(listView.Items[0].Selected); Assert.Equal(3, listView.Items.Count); Assert.Equal(3, listView.Groups.Count); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); listView.Groups.Remove(listView.Groups[2]); Assert.True(listView.Items[0].Selected); Assert.Equal(3, listView.Items.Count); Assert.Equal(2, listView.Groups.Count); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); Assert.True(listView.Items[0].Selected); listView.Groups.Remove(listView.Groups[1]); Assert.True(listView.Items[0].Selected); Assert.Equal(3, listView.Items.Count); - Assert.Equal(1, listView.Groups.Count); - Assert.Equal(1, listView.SelectedItems.Count); - Assert.Equal(1, listView.SelectedIndices.Count); + Assert.Single(listView.Groups); + Assert.Single(listView.SelectedItems); + Assert.Single(listView.SelectedIndices); Assert.True(listView.Items[0].Selected); } @@ -5732,24 +5732,24 @@ public void ListView_Remove_Group_WithNotCheckedItems(View view, bool showGroups Assert.True(listView.Items[0].Checked); Assert.Equal(3, listView.Items.Count); Assert.Equal(3, listView.Items.Count); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); listView.Groups.Remove(listView.Groups[2]); Assert.True(listView.Items[0].Checked); Assert.Equal(3, listView.Items.Count); Assert.Equal(2, listView.Groups.Count); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); listView.Groups.Remove(listView.Groups[1]); Assert.True(listView.Items[0].Checked); Assert.Equal(3, listView.Items.Count); - Assert.Equal(1, listView.Groups.Count); - Assert.Equal(1, listView.CheckedItems.Count); - Assert.Equal(1, listView.CheckedIndices.Count); + Assert.Single(listView.Groups); + Assert.Single(listView.CheckedItems); + Assert.Single(listView.CheckedIndices); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MdiControlStripTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MdiControlStripTests.cs index deb8b021ff5..732d74e62ff 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MdiControlStripTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MdiControlStripTests.cs @@ -306,7 +306,7 @@ public void MdiControlStrip_MaximizedChildWindow_ControlbBoxButtons_AreNotCloned IntPtr menuHandle = PInvoke.GetMenu((HWND)mdiParent.Handle); int menuItemCount = PInvoke.GetMenuItemCount((HMENU)menuHandle); // Four buttons: System, Minimize, Maximize, Close - Assert.True(menuItemCount == 4); + Assert.Equal(4, menuItemCount); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MenuStripTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MenuStripTests.cs index 6d29c2b5764..bbb2a962a3a 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MenuStripTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MenuStripTests.cs @@ -681,7 +681,7 @@ public void MenuStrip_OnMenuDeactivate_InvokeWithHandle_CallsMenuDeactivate(Even public void MenuStirp_ProcessCmdKey_InvokeWithoutParent_ReturnsFalse(Keys keyData) { using SubMenuStrip control = new(); - Message m = new(); + Message m = default; Assert.False(control.ProcessCmdKey(ref m, keyData)); Assert.False(control.IsHandleCreated); } @@ -699,7 +699,7 @@ public void MenuStirp_ProcessCmdKey_InvokeWithParent_ReturnsFalse(Keys keyData) { Parent = parent }; - Message msg = new(); + Message msg = default; Assert.False(control.ProcessCmdKey(ref msg, keyData)); Assert.False(control.IsHandleCreated); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/CommandViewModel.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/CommandViewModel.cs index c78d7bac679..8919c76818c 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/CommandViewModel.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/CommandViewModel.cs @@ -1,4 +1,7 @@ -#nullable enable +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable namespace System.Windows.Forms.DataBinding.TestUtilities; @@ -22,7 +25,7 @@ public RelayCommand? TestCommand public bool TestCommandExecutionAbility { get => _testCommandExecutionAbility; - + set { if (SetProperty(ref _testCommandExecutionAbility, value)) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/RelayCommand.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/RelayCommand.cs index 7589b706917..c5ea0f9178f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/RelayCommand.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/RelayCommand.cs @@ -1,4 +1,7 @@ -#nullable enable +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable namespace System.Windows.Forms.DataBinding.TestUtilities; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/ViewModelBase.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/ViewModelBase.cs index 8bbb4f64eee..e09b34201bf 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/ViewModelBase.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Mocks/DataBinding/ViewModelBase.cs @@ -1,4 +1,7 @@ -using System.ComponentModel; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; using System.Runtime.CompilerServices; #nullable enable diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MonthCalendar.SelectionRangeConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MonthCalendar.SelectionRangeConverterTests.cs index fb93f5d32e4..55a6e83499d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MonthCalendar.SelectionRangeConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MonthCalendar.SelectionRangeConverterTests.cs @@ -101,7 +101,7 @@ public void ConvertTo_ReturnsExpected(string dateValue, Type targetType, object [WinFormsFact] public void ConvertTo_InstanceDescriptor_ReturnsCorrectInstanceDescriptor() - { + { InstanceDescriptor descriptor = (InstanceDescriptor)_converter.ConvertTo(null, CultureInfo.InvariantCulture, _range, typeof(InstanceDescriptor)); SelectionRange result = (SelectionRange)descriptor.Invoke(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs index d3efb92541d..10d12160b2b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs @@ -119,7 +119,7 @@ public void PaddingConverter_ConvertTo_ValueNotPadding_ThrowsNotSupportedExcepti public void PaddingConverter_ConvertTo_InvalidDestinationType_ThrowsNotSupportedException(Type destinationType) { PaddingConverter converter = new(); - Assert.Throws(() => converter.ConvertTo(new Padding(), destinationType)); + Assert.Throws(() => converter.ConvertTo(default(Padding), destinationType)); } public static IEnumerable CreateInstance_TestData() diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingTests.cs index 503cba54151..ad63903d0c6 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingTests.cs @@ -12,7 +12,7 @@ public class PaddingTests [Fact] public void Padding_Ctor_Default() { - Padding padding = new(); + Padding padding = default; Assert.Equal(-1, padding.All); Assert.Equal(0, padding.Left); Assert.Equal(0, padding.Top); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PictureBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PictureBoxTests.cs index 4c2d2810cf4..0887bf6319c 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PictureBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PictureBoxTests.cs @@ -2117,7 +2117,7 @@ public void PictureBox_Load_InvokeWithoutImageLocation_ThrowsInvalidOperationExc { ImageLocation = imageLocation }; - Assert.Throws(() => pictureBox.Load()); + Assert.Throws(pictureBox.Load); Assert.Throws(() => pictureBox.Load(imageLocation)); } @@ -2129,7 +2129,7 @@ public void PictureBox_LoadAsync_InvokeWithoutImageLocation_ThrowsInvalidOperati { ImageLocation = imageLocation }; - Assert.Throws(() => pictureBox.LoadAsync()); + Assert.Throws(pictureBox.LoadAsync); Assert.Throws(() => pictureBox.LoadAsync(imageLocation)); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Printing/PrintPreviewControl.PrintPreviewControlAccessibilityObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Printing/PrintPreviewControl.PrintPreviewControlAccessibilityObjectTests.cs index 3b917284d53..3f8882a5e2e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Printing/PrintPreviewControl.PrintPreviewControlAccessibilityObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Printing/PrintPreviewControl.PrintPreviewControlAccessibilityObjectTests.cs @@ -1,4 +1,7 @@ -using System.Drawing; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; using Windows.Win32.UI.Accessibility; using static System.Windows.Forms.PrintPreviewControl; using IScrollProvider = Windows.Win32.UI.Accessibility.IScrollProvider; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs index 07ac5ab4a90..cb54c9a2dca 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs @@ -2550,7 +2550,7 @@ public void ProgressBar_PerformStep_Marquee_ThrowsInvalidOperationException(int Style = ProgressBarStyle.Marquee, Step = step }; - Assert.Throws(() => control.PerformStep()); + Assert.Throws(control.PerformStep); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyGridTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyGridTests.cs index 1b9635e8d37..1bbb47f16a9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyGridTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyGridTests.cs @@ -2362,13 +2362,13 @@ public void PropertyGrid_PropertySort_SetWithHandle_GetReturnsExpected(PropertyS public void PropertyGrid_PropertyTabCollection_AddAndRemoveTabType_Success() { using PropertyGrid grid = new(); - Assert.Equal(1, grid.PropertyTabs.Count); + Assert.Single(grid.PropertyTabs); grid.PropertyTabs.AddTabType(typeof(TestPropertyTab)); Assert.Equal(2, grid.PropertyTabs.Count); grid.PropertyTabs.RemoveTabType(typeof(TestPropertyTab)); - Assert.Equal(1, grid.PropertyTabs.Count); + Assert.Single(grid.PropertyTabs); } private class TestPropertyTab : PropertyTab @@ -3916,7 +3916,7 @@ public void PropertyGrid_SetEnableFalse_DoesntBreakEntries_AndFlagsReturnCorrect propertyGrid.Enabled = enable; var entry = (GridEntry)propertyGrid.SelectedGridItem; - Assert.True(entry.EntryFlags != 0); + Assert.NotEqual(0, (int)entry.EntryFlags); Assert.False(propertyGrid.IsHandleCreated); Assert.False(button.IsHandleCreated); } @@ -4052,7 +4052,7 @@ public void PropertyGrid_SelectedObjectsChanged_Invoke_CallsSelectedObjectsChang public void PropertyGrid_ResetSelectedProperty_Invoke_Success() { using PropertyGrid propertyGrid = new(); - var testObject = new TestObject { Property1 = "ChangedValue1"}; + var testObject = new TestObject { Property1 = "ChangedValue1" }; propertyGrid.SelectedObject = testObject; propertyGrid.ResetSelectedProperty(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyManagerTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyManagerTests.cs index bde427aeb18..bbc02406d44 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyManagerTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PropertyManagerTests.cs @@ -44,7 +44,7 @@ public void PropertyManager_GetListName_Invoke_ReturnsEmpty() public void PropertyManager_GetListName_NoDataSource_ThrowsArgumentException() { PropertyManager manager = new(); - Assert.Throws(() => manager.GetListName()); + Assert.Throws(manager.GetListName); } /* @@ -393,7 +393,7 @@ public void PropertyManager_AddNew_Invoke_ThrowsNotSupportedException() BindingContext context = []; BindingSource source = []; PropertyManager manager = Assert.IsType(context[new DataSource()]); - Assert.Throws(() => manager.AddNew()); + Assert.Throws(manager.AddNew); } [Theory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs index 9c21eb48ddb..36a0cf04628 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs @@ -100,7 +100,7 @@ public void RadioButtonRenderer_DrawRadioButton_OverloadWithTextFormat(TextForma } [WinFormsTheory] - [BoolData()] + [BoolData] public void RadioButtonRenderer_DrawRadioButton_OverloadWithHandle(bool focus) { using Form form = new Form(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs index 44321226962..566237c4c90 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs @@ -172,8 +172,8 @@ public void RadioButton_CheckAlign_SetInvalidValue_ThrowsInvalidEnumArgumentExce Assert.Throws("value", () => control.CheckAlign = value); } - public static TheoryData CheckAlignData => new() - { + public static TheoryData CheckAlignData => + [ ContentAlignment.TopLeft, ContentAlignment.TopRight, ContentAlignment.BottomCenter, @@ -183,7 +183,7 @@ public void RadioButton_CheckAlign_SetInvalidValue_ThrowsInvalidEnumArgumentExce ContentAlignment.MiddleRight, ContentAlignment.TopCenter, ContentAlignment.MiddleCenter - }; + ]; [WinFormsTheory] [MemberData(nameof(CheckAlignData))] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ReadOnlyControlCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ReadOnlyControlCollectionTests.cs index 3c4680c9823..fb6db5e434c 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ReadOnlyControlCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ReadOnlyControlCollectionTests.cs @@ -8,7 +8,7 @@ public class ReadOnlyControlCollectionTests [WinFormsFact] public void ReadOnlyControlCollection_Ctor_Control() { - using Control owner = new (); + using Control owner = new(); ReadOnlyControlCollection collection = new(owner, false); Assert.Empty(collection); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs index 493b2ec361c..26ed0df1173 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs @@ -9072,7 +9072,7 @@ public void RichTextBox_OnBackColorChanged_InvokeWithHandle_CallsBackColorChange public static IEnumerable OnContentsResized_TestData() { yield return new object[] { null }; - yield return new object[] { new ContentsResizedEventArgs(new Rectangle()) }; + yield return new object[] { new ContentsResizedEventArgs(default) }; } [WinFormsTheory] @@ -10673,7 +10673,7 @@ public void RichTextBox_SaveFilePath_Invoke_Success() { Rtf = @"{\rtf1\ansi{Sample for {\v HIDDEN }text}}" }; - using RichTextBox richTextBox2 = new(); + using RichTextBox richTextBox2 = new(); string fileName = "SaveRichTextBox.rtf"; string projectDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "..", ".."); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScreenTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScreenTests.cs index bacaa916ce7..3109db5a0ba 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScreenTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScreenTests.cs @@ -213,8 +213,8 @@ public void Screen_ToString_Invoke_ReturnsExpected() private static void VerifyScreen(Screen screen) { Assert.Contains(screen.BitsPerPixel, new int[] { 1, 2, 4, 8, 16, 24, 32, 48, 64 }); - Assert.True(screen.Bounds.Width != 0); - Assert.True(screen.Bounds.Height != 0); + Assert.NotEqual(0, screen.Bounds.Width); + Assert.NotEqual(0, screen.Bounds.Height); Assert.InRange(screen.DeviceName.Length, 1, 32); Assert.Equal(screen.DeviceName, screen.DeviceName.Trim('\0')); Assert.InRange(screen.WorkingArea.Width, 0, screen.Bounds.Width); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollBarTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollBarTests.cs index beaa3d40561..eae574ae30d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollBarTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ScrollBarTests.cs @@ -2594,7 +2594,7 @@ public void ScrollBar_ScaleScrollBarForDpi_InvokeWithSize_Nop(bool scaleScrollBa control.TestAccessor().Dynamic._scrollOrientation = orientation; - SizeF factor = new (((float)deviceDpiNew) / deviceDpiOld, ((float)deviceDpiNew) / deviceDpiOld); + SizeF factor = new(((float)deviceDpiNew) / deviceDpiOld, ((float)deviceDpiNew) / deviceDpiOld); control.ScaleControl(factor, factor); Assert.Equal(expected, control.Size); @@ -3162,7 +3162,7 @@ private class SubScrollBar : ScrollBar public new bool CanRaiseEvents => base.CanRaiseEvents; public new CreateParams CreateParams => base.CreateParams; - + public new Cursor DefaultCursor => base.DefaultCursor; public new ImeMode DefaultImeMode => base.DefaultImeMode; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SpecialFolderEnumConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SpecialFolderEnumConverterTests.cs index 789d25ed7b3..b3bdde42a32 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SpecialFolderEnumConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SpecialFolderEnumConverterTests.cs @@ -97,7 +97,9 @@ private TypeConverter GetNewSpecialFolderEnumConverter() return (TypeConverter)Activator.CreateInstance(descriptor.Converter.GetType(), new Type[] { typeof(Environment.SpecialFolder) }); } +#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable private class CustomReflectionType +#pragma warning restore CA1052 { #pragma warning disable CS0649 #pragma warning disable IDE1006 // Naming Styles diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SplitContainer.SplitContainerTypedControlCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SplitContainer.SplitContainerTypedControlCollectionTests.cs index 37a7b4fa061..70ba8a552c5 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SplitContainer.SplitContainerTypedControlCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SplitContainer.SplitContainerTypedControlCollectionTests.cs @@ -8,7 +8,7 @@ public class SplitContainer_SplitContainerTypedControlCollectionTests [WinFormsFact] public void SplitContainerTypedControlCollection_Ctor_Control() { - using SplitContainer owner = new (); + using SplitContainer owner = new(); SplitContainer.SplitContainerTypedControlCollection collection = new(owner, typeof(SplitterPanel), false); Assert.Empty(collection); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/StatusStripTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/StatusStripTests.cs index 3d117493a78..a8b9cb74ce6 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/StatusStripTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/StatusStripTests.cs @@ -393,7 +393,7 @@ public void StatusStrip_LayoutStyle_Set_GetReturnsExpected(DockStyle dock, ToolS public static IEnumerable Padding_Set_TestData() { - yield return new object[] { new Padding(), new Padding(), 1, 1 }; + yield return new object[] { default(Padding), default(Padding), 1, 1 }; yield return new object[] { new Padding(1, 0, 14, 0), new Padding(1, 0, 14, 0), 0, 0 }; yield return new object[] { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 1 }; yield return new object[] { new Padding(1), new Padding(1), 1, 1 }; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SystemInformationTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SystemInformationTests.cs index dbe81a11ac8..d30bbe0945f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SystemInformationTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SystemInformationTests.cs @@ -789,8 +789,8 @@ public void SystemInformation_VerticalScrollBarWidth_Get_ReturnsExpected() public void SystemInformation_VirtualScreen_Get_ReturnsExpected() { Rectangle screen = SystemInformation.VirtualScreen; - Assert.True(screen.Width != 0); - Assert.True(screen.Height != 0); + Assert.NotEqual(0, screen.Width); + Assert.NotEqual(0, screen.Height); Assert.Equal(screen, SystemInformation.VirtualScreen); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControl.TabPageCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControl.TabPageCollectionTests.cs index f3a28bb57ed..8bc1ab4ca14 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControl.TabPageCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControl.TabPageCollectionTests.cs @@ -1840,7 +1840,7 @@ public void TabPageCollection_GetEnumerator_InvokeInvalidGetItems_ReturnsExpecte { using InvalidGetItemsTabControl owner = new(); var collection = new TabControl.TabPageCollection(owner); - Assert.Throws(() => collection.GetEnumerator()); + Assert.Throws(collection.GetEnumerator); } [WinFormsFact] @@ -5025,7 +5025,7 @@ public void TabPageCollection_Insert_By_Index() [WinFormsFact] public void TabPageCollection_Insert_First_item() { - using TabControl TabControl = new (); + using TabControl TabControl = new(); using TabPage page1 = new(); using TabPage page2 = new(); @@ -5033,7 +5033,7 @@ public void TabPageCollection_Insert_First_item() page1.Text = "First works"; TabControl.TabPages.Insert(0, page1); - Assert.Equal(1, TabControl.TabPages.Count); + Assert.Single(TabControl.TabPages); Assert.Equal(page1, TabControl.TabPages[0]); Assert.Equal(page1, TabControl.Controls[0]); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControlTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControlTests.cs index a98bb95ddba..8e0ac90df96 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControlTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabControlTests.cs @@ -3709,7 +3709,7 @@ public void TabControl_GetTabRect_InvokeWithHandle_ReturnsExpected() public static IEnumerable GetTabRect_InvokeCustomGetItemRect_TestData() { - yield return new object[] { new RECT(), Rectangle.Empty }; + yield return new object[] { default(RECT), Rectangle.Empty }; yield return new object[] { new RECT(1, 2, 3, 4), new Rectangle(1, 2, 2, 2) }; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs index e1aee1c382e..769d973b3e6 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs @@ -13,7 +13,7 @@ public class TableLayoutPanelCellPositionTests [Fact] public void TableLayoutPanelCellPosition_Ctor_Default() { - TableLayoutPanelCellPosition style = new(); + TableLayoutPanelCellPosition style = default; Assert.Equal(0, style.Column); Assert.Equal(0, style.Row); } @@ -198,7 +198,7 @@ public void TableLayoutPanelCellPosition_ConverterConvertTo_ValueNotTableLayoutP public void TableLayoutPanelCellPosition_ConverterConvertTo_InvalidDestinationType_ThrowsNotSupportedException(Type destinationType) { TypeConverter converter = TypeDescriptor.GetConverter(typeof(TableLayoutPanelCellPosition)); - Assert.Throws(() => converter.ConvertTo(new TableLayoutPanelCellPosition(), destinationType)); + Assert.Throws(() => converter.ConvertTo(default(TableLayoutPanelCellPosition), destinationType)); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs index fa08cf840af..bdced2bd072 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelTests.cs @@ -1652,7 +1652,7 @@ public void TableLayoutPanel_SetCellPosition_InvokeMultipleTimes_GetReturnsExpec public void TableLayoutPanel_SetCellPosition_NullControl_ThrowsArgumentNullException() { using TableLayoutPanel control = new(); - Assert.Throws("control", () => control.SetCellPosition(null, new TableLayoutPanelCellPosition())); + Assert.Throws("control", () => control.SetCellPosition(null, default)); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutStyleCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutStyleCollectionTests.cs index ef945b01740..92e103d1ddc 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutStyleCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutStyleCollectionTests.cs @@ -13,7 +13,7 @@ public void TableLayoutStyleCollection_Properties_GetDefault_ReturnsExpected() using ToolStrip toolStrip = new() { LayoutStyle = ToolStripLayoutStyle.Table }; TableLayoutSettings settings = Assert.IsType(toolStrip.LayoutSettings); IList collection = settings.RowStyles; - Assert.Equal(0, collection.Count); + Assert.Empty(collection); Assert.False(collection.IsFixedSize); Assert.False(collection.IsReadOnly); Assert.False(collection.IsSynchronized); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxBase.TextBoxBaseUiaTextProviderTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxBase.TextBoxBaseUiaTextProviderTests.cs index 0aeab00c166..54ced077648 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxBase.TextBoxBaseUiaTextProviderTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxBase.TextBoxBaseUiaTextProviderTests.cs @@ -590,9 +590,9 @@ public void TextBoxBaseUiaTextProvider_EditStyle_ReturnsCorrectValue() textBoxBase.CreateControl(); TextBoxBaseUiaTextProvider provider = new(textBoxBase); WINDOW_STYLE actual = provider.WindowStyle; - Assert.False(((int)actual & PInvoke.ES_RIGHT) != 0); - Assert.True(((int)actual & PInvoke.ES_AUTOVSCROLL) != 0); - Assert.True(((int)actual & PInvoke.ES_AUTOHSCROLL) != 0); + Assert.Equal(0, ((int)actual & PInvoke.ES_RIGHT)); + Assert.NotEqual(0, ((int)actual & PInvoke.ES_AUTOVSCROLL)); + Assert.NotEqual(0, ((int)actual & PInvoke.ES_AUTOHSCROLL)); Assert.True(textBoxBase.IsHandleCreated); } @@ -935,7 +935,7 @@ public void TextBoxBaseUiaTextProvider_GetLogfont_ReturnEmpty_WithoutHandle() TextBoxBaseUiaTextProvider provider = new(textBoxBase); Assert.False(textBoxBase.IsHandleCreated); - Assert.Equal(new LOGFONTW(), provider.Logfont); + Assert.Equal(default, provider.Logfont); } private class SubTextBoxBase : TextBoxBase diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxRendererTests.cs index c2b77de6f8e..0e23bbfb5ba 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextBoxRendererTests.cs @@ -9,13 +9,13 @@ namespace System.Windows.Forms.Tests; public class TextBoxRendererTests { - public static TheoryData DrawTextBox_State_TheoryData() => new() - { + public static TheoryData DrawTextBox_State_TheoryData() => + [ TextBoxState.Normal, TextBoxState.Hot, TextBoxState.Selected, TextBoxState.Disabled - }; + ]; [WinFormsTheory] [MemberData(nameof(DrawTextBox_State_TheoryData))] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextRendererTests.cs index d5e54d5ea16..4a4a39a04e3 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TextRendererTests.cs @@ -313,11 +313,11 @@ public void TextRenderer_DrawText_Mocked_Success() Mock mockDeviceContext = new(MockBehavior.Strict); mockDeviceContext .Setup(c => c.GetHdc()) - .Returns(() => graphics.GetHdc()) + .Returns(graphics.GetHdc) .Verifiable(); mockDeviceContext .Setup(c => c.ReleaseHdc()) - .Callback(() => graphics.ReleaseHdc()) + .Callback(graphics.ReleaseHdc) .Verifiable(); TextRenderer.DrawText(mockDeviceContext.Object, "text", SystemFonts.MenuFont, Point.Empty, Color.Red); @@ -538,11 +538,11 @@ public void TextRenderer_MeasureText_Mocked_Success() Mock mockDeviceContext = new(MockBehavior.Strict); mockDeviceContext .Setup(c => c.GetHdc()) - .Returns(() => graphics.GetHdc()) + .Returns(graphics.GetHdc) .Verifiable(); mockDeviceContext .Setup(c => c.ReleaseHdc()) - .Callback(() => graphics.ReleaseHdc()) + .Callback(graphics.ReleaseHdc) .Verifiable(); TextRenderer.MeasureText(mockDeviceContext.Object, "text", SystemFonts.MenuFont); @@ -585,8 +585,8 @@ public unsafe void TextRenderer_DrawText_DefaultBackground_RendersTransparent(Fu } public static TheoryData> TextRenderer_DrawText_DefaultBackground_RendersTransparent_TestData - => new() - { + => + [ (IDeviceContext context) => () => TextRenderer.DrawText(context, "Acrylic", SystemFonts.DefaultFont, pt: default, Color.Blue), @@ -599,7 +599,7 @@ public static TheoryData> TextRenderer_DrawText_Def (IDeviceContext context) => () => TextRenderer.DrawText(context, "Acrylic", SystemFonts.DefaultFont, bounds: new Rectangle(0, 0, int.MaxValue, int.MaxValue), Color.Blue, flags: default), - }; + ]; [Theory] [MemberData(nameof(TextRenderer_Span_ModifyString_ThrowsArgumentOutOfRange_TestData))] @@ -610,20 +610,20 @@ public void TextRenderer_Span_ModifyString_ThrowsArgumentOutOfRange(Action actio #pragma warning disable CS0618 // Type or member is obsolete public static TheoryData TextRenderer_Span_ModifyString_ThrowsArgumentOutOfRange_TestData() - => new() - { + => + [ () => TextRenderer.DrawText( MockDC.Instance, string.Empty.AsSpan(), null, - new Point(), + default(Point), Color.Empty, TextFormatFlags.ModifyString), () => TextRenderer.DrawText( MockDC.Instance, string.Empty.AsSpan(), null, - new Point(), + default(Point), Color.Empty, Color.Empty, TextFormatFlags.ModifyString), @@ -631,14 +631,14 @@ public static TheoryData TextRenderer_Span_ModifyString_ThrowsArgumentOu MockDC.Instance, string.Empty.AsSpan(), null, - new Rectangle(), + default(Rectangle), Color.Empty, TextFormatFlags.ModifyString), () => TextRenderer.DrawText( MockDC.Instance, string.Empty.AsSpan(), null, - new Rectangle(), + default(Rectangle), Color.Empty, Color.Empty, TextFormatFlags.ModifyString), @@ -646,14 +646,14 @@ public static TheoryData TextRenderer_Span_ModifyString_ThrowsArgumentOu MockDC.Instance, string.Empty.AsSpan(), null, - new Size(), + default, TextFormatFlags.ModifyString), () => TextRenderer.MeasureText( string.Empty.AsSpan(), null, - new Size(), + default, TextFormatFlags.ModifyString), - }; + ]; #pragma warning restore CS0618 private class MockDC : IDeviceContext diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripComboBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripComboBoxTests.cs index b600abcc4e4..47f4bf34ce4 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripComboBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripComboBoxTests.cs @@ -104,7 +104,7 @@ public void ToolStripComboBox_ConstructorWithControl_ThrowsNotSupportedException [WinFormsFact] public void ToolStripComboBox_AutoCompleteCustomSource_SetAndGet() { - AutoCompleteStringCollection source = new(){ "Item1", "Item2" }; + AutoCompleteStringCollection source = ["Item1", "Item2"]; _toolStripComboBox.AutoCompleteCustomSource = source; _toolStripComboBox.AutoCompleteCustomSource.Should().BeEquivalentTo(source); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripControlHostTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripControlHostTests.cs index 699cc098990..16f820fe458 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripControlHostTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripControlHostTests.cs @@ -2702,7 +2702,7 @@ public void ToolStripControlHost_Focus_InvokeDisposed_ThrowsObjectDisposedExcept using ToolStripControlHost item = new(c); item.Dispose(); - Assert.Throws(() => item.Focus()); + Assert.Throws(item.Focus); } public static IEnumerable GetPreferredSize_TestData() @@ -4198,7 +4198,7 @@ public void ToolStripControlHost_ProcessCmdKey_Invoke_ReturnsFalse(Keys keyData) { using Control c = new(); using SubToolStripControlHost item = new(c); - Message m = new(); + Message m = default; Assert.False(item.ProcessCmdKey(ref m, keyData)); Assert.False(c.IsHandleCreated); } @@ -4241,7 +4241,7 @@ public void ToolStripControlHost_ProcessCmdKey_InvokeDisposed_ReturnsFalse(Keys using SubToolStripControlHost item = new(c); item.Dispose(); - Message m = new(); + Message m = default; Assert.False(item.ProcessCmdKey(ref m, keyData)); } @@ -4412,7 +4412,7 @@ public void ToolStripControlHost_ResetBackColor_InvokeDisposed_ThrowsObjectDispo using SubToolStripControlHost item = new(c); item.Dispose(); - Assert.Throws(() => item.ResetBackColor()); + Assert.Throws(item.ResetBackColor); } [WinFormsFact] @@ -4445,7 +4445,7 @@ public void ToolStripControlHost_ResetForeColor_InvokeDisposed_ThrowsObjectDispo using SubToolStripControlHost item = new(c); item.Dispose(); - Assert.Throws(() => item.ResetForeColor()); + Assert.Throws(item.ResetForeColor); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripDropDownTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripDropDownTests.cs index 8630316a634..867f62e30bf 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripDropDownTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripDropDownTests.cs @@ -4992,7 +4992,7 @@ public void ToolStripDropDown_Show_ControlPointDirection(int x, int y, ToolStrip toolStripDropDown.Show(control, new Point(x, y), direction); toolStripDropDown.Location.Should().Be(new Point(x + 6, y + 27)); - } + } [WinFormsTheory] [InlineData(10, 20, ToolStripDropDownDirection.AboveLeft)] @@ -5003,7 +5003,7 @@ public void ToolStripDropDown_Show_PositionDirection(int x, int y, ToolStripDrop toolStripDropDown.Show(new Point(x, y), direction); Point expectedLocation = new(x, y); var nonClientSize = SystemInformation.BorderSize; - expectedLocation.Offset(nonClientSize.Width-3, nonClientSize.Height -1); + expectedLocation.Offset(nonClientSize.Width - 3, nonClientSize.Height - 1); if (direction is ToolStripDropDownDirection.AboveLeft or ToolStripDropDownDirection.AboveRight) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemCollectionTests.cs index d42cc30396a..ad73851a15b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemCollectionTests.cs @@ -110,7 +110,7 @@ public void ToolStripItemCollection_AddRange_ToolStripItemCollection_Success() // Add 0 items. contextMenuStrip.Items.AddRange(toolStripDropDownButton.DropDownItems); - Assert.Equal(0, contextMenuStrip.Items.Count); + Assert.Empty(contextMenuStrip.Items); // Add 3 items. toolStripDropDownButton.DropDownItems.Add("a"); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemTests.cs index ee840a48e71..8d9fd409138 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripItemTests.cs @@ -6732,7 +6732,7 @@ public void ToolStripItem_Padding_Set_GetReturnsExpected(Padding value, Padding public static IEnumerable Padding_SetWithOwner_TestData() { - yield return new object[] { new Padding(), new Padding(), 0, 0 }; + yield return new object[] { default(Padding), default(Padding), 0, 0 }; yield return new object[] { new Padding(1, 2, 3, 4), new Padding(1, 2, 3, 4), 1, 1 }; yield return new object[] { new Padding(1), new Padding(1), 1, 1 }; yield return new object[] { new Padding(-1, -2, -3, -4), Padding.Empty, 1, 2 }; @@ -13969,7 +13969,7 @@ public void ToolStripItem_PerformClick_InvokeWithParentWithHandle_Success() public void ToolStripItem_ProcessCmdKey_Invoke_ReturnsFalse(Keys keyData) { using SubToolStripItem item = new(); - Message message = new(); + Message message = default; Assert.False(item.ProcessCmdKey(ref message, keyData)); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripPanelRow.ToolStripPanelRowControlCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripPanelRow.ToolStripPanelRowControlCollectionTests.cs index ed0b74b7de1..4fc6a523f7b 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripPanelRow.ToolStripPanelRowControlCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripPanelRow.ToolStripPanelRowControlCollectionTests.cs @@ -33,9 +33,8 @@ public void GetControl_ShouldNotThrowIndexOutOfRangeException() toolStripContainer.PerformLayout(); form.ResumeLayout(false); - var exception = Record.Exception(() => form.Show()); + var exception = Record.Exception(form.Show); Assert.Null(exception); } } - diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripSplitButtonTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripSplitButtonTests.cs index df1b54e8d89..125ea583d30 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripSplitButtonTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripSplitButtonTests.cs @@ -18,11 +18,11 @@ public ToolStripSplitButtonTests() public void Dispose() => _toolStripSplitButton.Dispose(); - public static TheoryData ToolStripItem_Set_TestData() => new() - { + public static TheoryData ToolStripItem_Set_TestData() => + [ null, new SubToolStripItem() - }; + ]; [WinFormsTheory] [MemberData(nameof(ToolStripItem_Set_TestData))] @@ -294,7 +294,7 @@ public void ToolStripSplitButton_ButtonDoubleClick_EventHandlerRemoved() [WinFormsFact] public void ToolStripSplitButton_DropDownButtonArea_ReturnsExpected() { - _toolStripSplitButton.DropDownButtonArea.Should().Be( _toolStripSplitButton.DropDownButtonBounds); + _toolStripSplitButton.DropDownButtonArea.Should().Be(_toolStripSplitButton.DropDownButtonBounds); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTests.cs index 2c9b2d068ca..c66a5c5ea3f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTests.cs @@ -6903,7 +6903,7 @@ public void ToolStrip_OnVisibleChanged_InvokeDisposed_CallsVisibleChanged(EventA public void ToolStrip_ProcessCmdKey_InvokeWithoutParent_ReturnsFalse(Keys keyData) { using SubToolStrip control = new(); - Message m = new(); + Message m = default; Assert.False(control.ProcessCmdKey(ref m, keyData)); Assert.False(control.IsHandleCreated); } @@ -6921,7 +6921,7 @@ public void ToolStrip_ProcessCmdKey_InvokeWithParent_ReturnsFalse(Keys keyData) { Parent = parent }; - Message msg = new(); + Message msg = default; Assert.False(control.ProcessCmdKey(ref msg, keyData)); Assert.False(control.IsHandleCreated); } @@ -7365,7 +7365,7 @@ public void ToolStrip_displayedItems_Clear() toolStripMenuItem.ShowDropDown(); Assert.Equal(4, listToolStripMenuItem.DropDown.DisplayedItems.Count); toolStripMenuItem.HideDropDown(); - Assert.Equal(0, listToolStripMenuItem.DropDown.DisplayedItems.Count); + Assert.Empty(listToolStripMenuItem.DropDown.DisplayedItems); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTextBoxTests.cs index b60aa166ad0..b83971dd284 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTextBoxTests.cs @@ -191,7 +191,7 @@ public void ToolStripTextBox_ShouldSerializeFont_ReturnsExpected() } [WinFormsTheory] - [BoolData] + [BoolData] public void ToolStripTextBox_AcceptsReturn_GetSet_ReturnsExpected(bool acceptsReturn) { _toolStripTextBox.AcceptsReturn = acceptsReturn; @@ -201,11 +201,11 @@ public void ToolStripTextBox_AcceptsReturn_GetSet_ReturnsExpected(bool acceptsRe [WinFormsFact] public void ToolStripTextBox_AutoCompleteCustomSource_GetSet_ReturnsExpected() { - AutoCompleteStringCollection collection = new(); + AutoCompleteStringCollection collection = []; _toolStripTextBox.AutoCompleteCustomSource = collection; _toolStripTextBox.AutoCompleteCustomSource.Should().BeEquivalentTo(collection); - AutoCompleteStringCollection newCollection = new(); + AutoCompleteStringCollection newCollection = []; _toolStripTextBox.AutoCompleteCustomSource = newCollection; _toolStripTextBox.AutoCompleteCustomSource.Should().BeEquivalentTo(newCollection); } @@ -745,7 +745,7 @@ public void ToolStripTextBox_GetFirstCharIndexFromLine_ReturnsExpected() _toolStripTextBox.Text = "Hello\r\nWorld\r\nTest"; _toolStripTextBox.GetFirstCharIndexFromLine(0).Should().Be(0); - _toolStripTextBox.GetFirstCharIndexFromLine(1).Should().Be(7); + _toolStripTextBox.GetFirstCharIndexFromLine(1).Should().Be(7); _toolStripTextBox.GetFirstCharIndexFromLine(2).Should().Be(14); } @@ -754,7 +754,7 @@ public void ToolStripTextBox_GetFirstCharIndexOfCurrentLine_Success() { _toolStripTextBox.Multiline = true; _toolStripTextBox.Text = "Hello\r\nWorld\r\nTest"; - _toolStripTextBox.SelectionStart = 7; + _toolStripTextBox.SelectionStart = 7; _toolStripTextBox.GetFirstCharIndexOfCurrentLine().Should().Be(7); } @@ -765,7 +765,7 @@ public void ToolStripTextBox_GetLineFromCharIndex_ReturnsExpected() _toolStripTextBox.Multiline = true; _toolStripTextBox.Text = "Hello\r\nWorld\r\nTest"; - _toolStripTextBox.GetLineFromCharIndex(0).Should().Be(0); + _toolStripTextBox.GetLineFromCharIndex(0).Should().Be(0); _toolStripTextBox.GetLineFromCharIndex(7).Should().Be(1); _toolStripTextBox.GetLineFromCharIndex(14).Should().Be(2); } @@ -776,8 +776,8 @@ public void ToolStripTextBox_GetPositionFromCharIndex_ReturnsExpected() _toolStripTextBox.Text = "Hello World"; _toolStripTextBox.GetPositionFromCharIndex(0).Should().Be(new Point(1, 0)); - _toolStripTextBox.GetPositionFromCharIndex(5).Should().Be(new Point(29, 0)); - _toolStripTextBox.GetPositionFromCharIndex(10).Should().Be(new Point(57, 0)); + _toolStripTextBox.GetPositionFromCharIndex(5).Should().Be(new Point(29, 0)); + _toolStripTextBox.GetPositionFromCharIndex(10).Should().Be(new Point(57, 0)); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipBufferTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipBufferTests.cs index e53ddd04a97..e398d3fd20f 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipBufferTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipBufferTests.cs @@ -10,14 +10,14 @@ public partial class ToolTipBufferTests [WinFormsFact] public void ToolTipBuffer_Buffer_GetEmpty_ReturnsZero() { - ToolTipBuffer buffer = new(); + ToolTipBuffer buffer = default; Assert.Equal(IntPtr.Zero, buffer.Buffer); } [WinFormsFact] public void ToolTipBuffer_SetText_NoBuffer_Success() { - ToolTipBuffer buffer = new(); + ToolTipBuffer buffer = default; IntPtr memory1 = buffer.Buffer; Assert.Null(Marshal.PtrToStringUni(memory1)); @@ -32,7 +32,7 @@ public void ToolTipBuffer_SetText_NoBuffer_Success() [InlineData("")] public void ToolTipBuffer_SetText_EmptyNoBuffer_Success(string empty) { - ToolTipBuffer buffer = new(); + ToolTipBuffer buffer = default; IntPtr memory1 = buffer.Buffer; Assert.Null(Marshal.PtrToStringUni(memory1)); @@ -47,7 +47,7 @@ public void ToolTipBuffer_SetText_EmptyNoBuffer_Success(string empty) [InlineData("abcdef")] public void ToolTipBuffer_SetTextLonger_Success(string longer) { - ToolTipBuffer buffer = new(); + ToolTipBuffer buffer = default; buffer.SetText("text"); IntPtr memory1 = buffer.Buffer; Assert.Equal("text", Marshal.PtrToStringUni(buffer.Buffer)); @@ -67,7 +67,7 @@ public void ToolTipBuffer_SetTextLonger_Success(string longer) [InlineData("abc", "abc")] public void ToolTipBuffer_SetTextShorter_Success(string shorter, string expected) { - ToolTipBuffer buffer = new(); + ToolTipBuffer buffer = default; buffer.SetText("text"); IntPtr memory1 = buffer.Buffer; Assert.Equal("text", Marshal.PtrToStringUni(buffer.Buffer)); @@ -84,7 +84,7 @@ public void ToolTipBuffer_SetTextShorter_Success(string shorter, string expected [InlineData("abcd")] public void ToolTipBuffer_SetTextSameLength_Success(string sameLength) { - ToolTipBuffer buffer = new(); + ToolTipBuffer buffer = default; buffer.SetText("text"); IntPtr memory1 = buffer.Buffer; Assert.Equal("text", Marshal.PtrToStringUni(buffer.Buffer)); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs index bbfd4f46ae7..30eb5e18e92 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs @@ -896,9 +896,9 @@ public void ToolTip_SetToolTip_TabControl_DoesNotAddToolForTabControlItself() [WinFormsFact] public unsafe void ToolTip_TTTOOLINFOW_Struct_Size_IsExpected() { - TTTOOLINFOW toolInfo = new(); + TTTOOLINFOW toolInfo = default; int size = (int)&toolInfo.lParam - (int)&toolInfo + sizeof(LPARAM); - int expected = (int)new ToolInfoWrapper().TestAccessor().Dynamic.TTTOOLINFO_V2_Size; + int expected = (int)default(ToolInfoWrapper).TestAccessor().Dynamic.TTTOOLINFO_V2_Size; size.Should().Be(expected); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNode.IKeyboardToolTipTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNode.IKeyboardToolTipTests.cs index d578a6200db..3b16ceb2fa7 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNode.IKeyboardToolTipTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNode.IKeyboardToolTipTests.cs @@ -123,7 +123,7 @@ public void TreeNodeIKeyboardToolTip_InvokeGetNeighboringToolsRectangles_FirstTr IList neighboringRectangles = ((IKeyboardToolTip)firstTreeNode).GetNeighboringToolsRectangles(); - Assert.Equal(1, neighboringRectangles.Count); + Assert.Single(neighboringRectangles); Assert.Contains(GetRectangle(treeView, treeView.Nodes[1]), neighboringRectangles); } @@ -156,7 +156,7 @@ public void TreeNodeIKeyboardToolTip_InvokeGetNeighboringToolsRectangles_LastTre IList neighboringRectangles = ((IKeyboardToolTip)lastTreeNode).GetNeighboringToolsRectangles(); - Assert.Equal(1, neighboringRectangles.Count); + Assert.Single(neighboringRectangles); Assert.Contains(GetRectangle(treeView, treeView.Nodes[1]), neighboringRectangles); } @@ -303,9 +303,9 @@ public void TreeNodeIKeyboardToolTip_InvokeGetNeighboringToolsRectangles_Without { List treeNodesList = GetHierarchyNodes(); - Assert.Equal(0, ((IKeyboardToolTip)treeNodesList[0]).GetNeighboringToolsRectangles().Count); - Assert.Equal(0, ((IKeyboardToolTip)treeNodesList[1]).GetNeighboringToolsRectangles().Count); - Assert.Equal(0, ((IKeyboardToolTip)treeNodesList[2]).GetNeighboringToolsRectangles().Count); + Assert.Empty(((IKeyboardToolTip)treeNodesList[0]).GetNeighboringToolsRectangles()); + Assert.Empty(((IKeyboardToolTip)treeNodesList[1]).GetNeighboringToolsRectangles()); + Assert.Empty(((IKeyboardToolTip)treeNodesList[2]).GetNeighboringToolsRectangles()); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeCollectionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeCollectionTests.cs index 5495be2e1a7..f3ea2263dbb 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeCollectionTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeCollectionTests.cs @@ -94,7 +94,7 @@ public void TreeNodeCollection_Item_SetTreeNodeAlreadyAdded_Noop() TreeNode node = new("Node 0"); collection.Add(node); collection[0] = node; - Assert.Equal(1, collection.Count); + Assert.Single(collection); } [WinFormsFact] @@ -129,8 +129,8 @@ public void TreeNodeCollection_Item_SetTreeNodeReplacesExistingOne() TreeNodeCollection collection = treeView.Nodes; collection.Add("Node 1"); collection[0] = new TreeNode("New node 1"); - Assert.Equal(1, treeView._nodesByHandle.Count); - Assert.Equal(1, collection.Count); + Assert.Single(treeView._nodesByHandle); + Assert.Single(collection); } [WinFormsTheory] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeTests.cs index 1743004c23d..55e89eba4f7 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeNodeTests.cs @@ -488,7 +488,7 @@ public void TreeNode_Bounds_GetWithTreeViewWithHandle_Success() public static IEnumerable Bounds_Get_CustomGetItemRect_TestData() { - yield return new object[] { new RECT(), Rectangle.Empty }; + yield return new object[] { default(RECT), Rectangle.Empty }; yield return new object[] { new RECT(1, 2, 3, 4), new Rectangle(1, 2, 2, 2) }; yield return new object[] { new RECT(0, 1, 3, 4), new Rectangle(0, 1, 3, 3) }; @@ -1932,7 +1932,7 @@ public void TreeNode_IsVisible_GetWithTreeViewWithHandle_ReturnsExpected() public static IEnumerable IsVisible_Get_CustomGetItemRect_TestData() { - yield return new object[] { new RECT(), false }; + yield return new object[] { default(RECT), false }; yield return new object[] { new RECT(1, 2, 3, 4), true }; yield return new object[] { new RECT(0, 1, 3, 4), true }; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeViewTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeViewTests.cs index 3926f8984c7..5f341dd5ace 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeViewTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TreeViewTests.cs @@ -6847,7 +6847,7 @@ public void TreeView_Remove_NotSelectedNode() treeView.Nodes.Remove(treeView.Nodes[1]); Assert.True(treeView.Nodes[0].IsSelected); - Assert.Equal(1, treeView.Nodes.Count); + Assert.Single(treeView.Nodes); Assert.Equal(treeView.Nodes[0], treeView.SelectedNode); } @@ -6910,7 +6910,7 @@ public void TreeView_Remove_NotSelectedSubNode() treeNode.Nodes.Remove(treeNode.Nodes[1]); Assert.True(treeNode.Nodes[0].IsSelected); - Assert.Equal(1, treeNode.Nodes.Count); + Assert.Single(treeNode.Nodes); Assert.Equal(treeNode.Nodes[0], treeView.SelectedNode); } @@ -6965,14 +6965,14 @@ public void TreeView_Remove_ParentSelectedNode() Assert.True(treeNode.Nodes[0].IsSelected); Assert.Equal(treeNode.Nodes[0], treeView.SelectedNode); - Assert.Equal(1, treeNode.Nodes.Count); - Assert.Equal(1, treeView.Nodes.Count); + Assert.Single(treeNode.Nodes); + Assert.Single(treeView.Nodes); treeView.Nodes.Remove(treeNode); Assert.False(treeNode.Nodes[0].IsSelected); Assert.Null(treeView.SelectedNode); - Assert.Equal(0, treeView.Nodes.Count); + Assert.Empty(treeView.Nodes); } [WinFormsTheory] @@ -6997,7 +6997,7 @@ public void TreeView_Remove_NotCheckedNode(bool checkBoxes) treeView.Nodes.Remove(treeView.Nodes[1]); Assert.True(treeView.Nodes[0].Checked); - Assert.Equal(1, treeView.Nodes.Count); + Assert.Single(treeView.Nodes); } [WinFormsTheory] @@ -7050,7 +7050,7 @@ public void TreeView_Remove_NotCheckedSubNode(bool checkBoxes) treeNode.Nodes.Remove(treeNode.Nodes[1]); Assert.True(treeNode.Nodes[0].Checked); - Assert.Equal(1, treeNode.Nodes.Count); + Assert.Single(treeNode.Nodes); } [WinFormsTheory] @@ -7098,15 +7098,15 @@ public void TreeView_Remove_ParentCheckedNode(bool checkBoxes) Assert.True(treeNode.Checked); Assert.True(treeNode.Nodes[0].Checked); - Assert.Equal(1, treeNode.Nodes.Count); - Assert.Equal(1, treeView.Nodes.Count); + Assert.Single(treeNode.Nodes); + Assert.Single(treeView.Nodes); treeView.Nodes.Remove(treeNode); Assert.True(treeNode.Checked); Assert.True(treeNode.Nodes[0].Checked); - Assert.Equal(1, treeNode.Nodes.Count); - Assert.Equal(0, treeView.Nodes.Count); + Assert.Single(treeNode.Nodes); + Assert.Empty(treeView.Nodes); } [WinFormsFact] @@ -7152,7 +7152,7 @@ public void Clear_AfterSort_ShouldNotGetStuck(string firstNodeText, string secon treeView.Sort(); - Action action = () => parent.Nodes.Clear(); + Action action = parent.Nodes.Clear; action.ExecutionTime().Should().BeLessThanOrEqualTo(TimeSpan.FromMilliseconds(500)); action.Should().NotThrow(); @@ -7201,10 +7201,10 @@ public void Remove_MultipleLevelsNodes_AfterSort() treeView.Sort(); - Assert.Equal(1, treeNode5.Nodes.Count); + Assert.Single(treeNode5.Nodes); parent.Nodes.Remove(treeNode4); - Assert.Equal(0, treeNode5.Nodes.Count); + Assert.Empty(treeNode5.Nodes); Action action = () => { @@ -7241,7 +7241,7 @@ public void Clear_MultipleLevelsNodes_AfterSort() // Make sure all nodes have been added as expected. Assert.Equal(3, fifthSubNode1.Nodes.Count); Assert.Equal(2, parent.Nodes[0].Nodes.Count); - Assert.Equal(1, parent.Nodes.Count); + Assert.Single(parent.Nodes); Assert.Equal(fourthSubNode2, thirdSubNode1.Nodes[0]); Assert.Equal(lastSubNode3, fifthSubNode1.Nodes[1]); @@ -7253,16 +7253,16 @@ public void Clear_MultipleLevelsNodes_AfterSort() // Clear the last non-leaf nodes. fifthSubNode1.Nodes.Clear(); - Assert.Equal(0, fifthSubNode1.Nodes.Count); + Assert.Empty(fifthSubNode1.Nodes); // Clear the first-level child nodes. firstSubNode.Nodes.Clear(); - Assert.Equal(0, firstSubNode.Nodes.Count); + Assert.Empty(firstSubNode.Nodes); // Clear top-level nodes. Action action = parent.Nodes.Clear; action.Should().NotThrow(); - Assert.Equal(0, parent.Nodes.Count); + Assert.Empty(parent.Nodes); } [WinFormsFact] @@ -7301,7 +7301,7 @@ public void Verify_NodeValue_AfterSortAndRemove() // Remove the last child node. parent.Nodes.Remove(parent.Nodes[1]); - Assert.Equal(1, parent.Nodes.Count); + Assert.Single(parent.Nodes); Assert.Equal(treeNode2, parent.Nodes[0]); } @@ -7563,8 +7563,8 @@ public void TreeView_VisibleCount_MultipleNodes_ReturnsExpected(int nodeCount) } treeView.CreateControl(); - treeView.Height = 100; - treeView.VisibleCount.Should().Be(5); + treeView.Height = 100; + treeView.VisibleCount.Should().Be(5); } private class SubTreeView : TreeView diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs index c4c77d8f12e..7b4042e9aa9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs @@ -9,7 +9,7 @@ public class TextMetricsTests [Fact] public void TextMetrics_Ctor_Default() { - TextMetrics metric = new(); + TextMetrics metric = default; Assert.Equal(0, metric.Ascent); Assert.Equal(0, metric.AverageCharWidth); Assert.Equal('\0', metric.BreakChar); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/WebBrowserTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/WebBrowserTests.cs index 183a18f8030..cb101068b20 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/WebBrowserTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/WebBrowserTests.cs @@ -3120,7 +3120,7 @@ public void WebBrowser_GoHome_InvokeDisposed_ThrowsObjectDisposedException() Parent = parent }; control.Dispose(); - Assert.Throws(() => control.GoHome()); + Assert.Throws(control.GoHome); } [WinFormsFact] @@ -3132,7 +3132,7 @@ public void WebBrowser_GoHome_InvokeDetached_ThrowsInvalidOperationException() Parent = parent }; control.DetachInterfaces(); - Assert.Throws(() => control.GoHome()); + Assert.Throws(control.GoHome); } [WinFormsFact] @@ -3169,7 +3169,7 @@ public void WebBrowser_GoSearch_InvokeDisposed_ThrowsObjectDisposedException() Parent = parent }; control.Dispose(); - Assert.Throws(() => control.GoSearch()); + Assert.Throws(control.GoSearch); } [WinFormsFact] @@ -3181,7 +3181,7 @@ public void WebBrowser_GoSearch_InvokeDetached_ThrowsInvalidOperationException() Parent = parent }; control.DetachInterfaces(); - Assert.Throws(() => control.GoSearch()); + Assert.Throws(control.GoSearch); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs index d1cbd8b6022..ee3ab9f9759 100644 --- a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs @@ -778,7 +778,7 @@ public void TextBoxBase_RecreateControl_DoesntClearTextProvider() provider = control.AccessibilityObject.TestAccessor().Dynamic._textProvider; // The control's accessible object and its providers shouldn't be cleaned when recreating of the control - // because this object and all its providers will continue to be used. + // because this object and all its providers will continue to be used. Assert.IsType(provider); } @@ -5849,7 +5849,7 @@ public void TextBoxBase_ProcessCmdKey_Invoke_ReturnsExpected(bool shortcutsEnabl ShortcutsEnabled = shortcutsEnabled, ReadOnly = readOnly }; - Message m = new(); + Message m = default; Assert.Equal(expected, control.ProcessCmdKey(ref m, keyData)); Assert.False(control.IsHandleCreated); } @@ -5865,7 +5865,7 @@ public void TextBoxBase_ProcessCmdKey_InvokeWithParent_ReturnsFalse(bool shortcu ShortcutsEnabled = shortcutsEnabled, ReadOnly = readOnly }; - Message msg = new(); + Message msg = default; Assert.Equal(expected, control.ProcessCmdKey(ref msg, keyData)); Assert.False(control.IsHandleCreated); } @@ -5875,7 +5875,7 @@ public void TextBoxBase_ProcessCmdKey_InvokeWithParent_ReturnsFalse(bool shortcu public void TextBoxBase_ProcessCmdKey_InvokeWithoutParent_ReturnsFalse(Keys keyData) { using SubTextBox control = new(); - Message m = new(); + Message m = default; Assert.False(control.ProcessCmdKey(ref m, keyData)); Assert.False(control.IsHandleCreated); } @@ -5938,7 +5938,7 @@ public void TextBoxBase_ProcessCmdKey_CtrlBackspaceTextEmpty_RemainsEmpty() { using SubTextBox control = new(); - Message message = new(); + Message message = default; Assert.True(control.ProcessCmdKey(ref message, Keys.Control | Keys.Back)); Assert.Empty(control.Text); } @@ -5952,7 +5952,7 @@ public void TextBoxBase_ProcessCmdKey_CtrlBackspaceReadOnly_Nop() ReadOnly = true }; - Message message = new(); + Message message = default; Assert.False(control.ProcessCmdKey(ref message, Keys.Control | Keys.Back)); Assert.Equal("text", control.Text); } @@ -5967,7 +5967,7 @@ public void TextBoxBase_ProcessCmdKey_CtrlBackspace_ClearsSelection(string text, SelectionStart = text.Length + cursorRelativeToEnd }; - Message message = new(); + Message message = default; Assert.True(control.ProcessCmdKey(ref message, Keys.Control | Keys.Back)); Assert.Equal(expected, control.Text); } @@ -5985,7 +5985,7 @@ public void TextBoxBase_ProcessCmdKey_CtrlBackspaceRepeated_ClearsSelection(stri for (int i = 0; i < repeats; i++) { - Message message = new(); + Message message = default; Assert.True(control.ProcessCmdKey(ref message, Keys.Control | Keys.Back)); } @@ -6002,7 +6002,7 @@ public void TextBoxBase_ProcessCmdKey_CtrlBackspaceWithSelection_ClearsSelection SelectionLength = 5 }; - Message message = new(); + Message message = default; Assert.True(control.ProcessCmdKey(ref message, Keys.Control | Keys.Back)); Assert.Equal("12-9", control.Text); } diff --git a/src/System.Windows.Forms/tests/UnitTests/ThreadContextTests.cs b/src/System.Windows.Forms/tests/UnitTests/ThreadContextTests.cs index 678bd6af880..13060b25067 100644 --- a/src/System.Windows.Forms/tests/UnitTests/ThreadContextTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/ThreadContextTests.cs @@ -19,7 +19,7 @@ public void ThreadContext_EmptyProcessFiltersWorks() { // Test that no filters at all does not throw, and that returns false from translation Application.ThreadContext threadContext = new Application.LightThreadContext(); - MSG msg = new(); + MSG msg = default; Assert.False(threadContext.PreTranslateMessage(ref msg)); } diff --git a/src/System.Windows.Forms/tests/UnitTests/ToolStripContainerTests.cs b/src/System.Windows.Forms/tests/UnitTests/ToolStripContainerTests.cs index 20b16780df6..335fe65a038 100644 --- a/src/System.Windows.Forms/tests/UnitTests/ToolStripContainerTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/ToolStripContainerTests.cs @@ -104,7 +104,7 @@ public void ToolStripContainer_BackgroundImageLayoutChanged_AddRemoveEvent_Maint _toolStripContainer.BackgroundImageLayoutChanged -= handler; _toolStripContainer.BackgroundImageLayout = ImageLayout.Stretch; - callCount.Should().BeGreaterThan(1); + callCount.Should().BeGreaterThan(1); } [WinFormsTheory]