<commit_before>// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.UnitTests;
using Xunit;

namespace System.Runtime.Analyzers.UnitTests
{
    public class InstantiateArgumentExceptionsCorrectlyTests : DiagnosticAnalyzerTestBase
    {
        private static readonly string s_ruleId = InstantiateArgumentExceptionsCorrectlyAnalyzer.RuleId;
        private static readonly string s_noArguments = SystemRuntimeAnalyzersResources.InstantiateArgumentExceptionsCorrectlyMessageNoArguments;
        private static readonly string s_incorrectMessage = SystemRuntimeAnalyzersResources.InstantiateArgumentExceptionsCorrectlyMessageIncorrectMessage;
        private static readonly string s_incorrectParameterName = SystemRuntimeAnalyzersResources.InstantiateArgumentExceptionsCorrectlyMessageIncorrectParameterName;

        protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
        {
            return new InstantiateArgumentExceptionsCorrectlyAnalyzer();
        }

        protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
        {
            return new InstantiateArgumentExceptionsCorrectlyAnalyzer();
        }

        [Fact]

        public void ArgumentException_NoArguments_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentException();
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_noArguments, "System.ArgumentException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Throw New System.ArgumentException()
                    End Sub
                End Class",
              GetBasicExpectedResult(4, 31, s_noArguments, "System.ArgumentException"));
        }

        [Fact]
        public void ArgumentException_EmptyParameterNameArgument_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentNullException("""");
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_incorrectParameterName, "Class.Test(string)", "", "paramName", "System.ArgumentNullException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Throw New System.ArgumentNullException("""")
                    End Sub
                End Class",
                GetBasicExpectedResult(4, 31, s_incorrectParameterName, "Public Sub Test(first As String)", "", "paramName", "System.ArgumentNullException"));
        }

        [Fact]
        public void ArgumentNullException_SpaceParameterArgument_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentNullException("" "");
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_incorrectParameterName, "Class.Test(string)", " ", "paramName", "System.ArgumentNullException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Throw New System.ArgumentNullException("" "")
                    End Sub
                End Class",
                GetBasicExpectedResult(4, 31, s_incorrectParameterName, "Public Sub Test(first As String)", " ", "paramName", "System.ArgumentNullException"));
        }

        public void ArgumentNullException_NameofNonParameter_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        var foo = new object();
                        throw new System.ArgumentNullException(nameof(foo));
                    }
                }",
                GetCSharpExpectedResult(6, 31, s_incorrectParameterName, "Class.Test(string)", " ", "paramName", "System.ArgumentNullException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Dim foo As New Object()
                        Throw New System.ArgumentNullException(NameOf(foo))
                    End Sub
                End Class",
                GetBasicExpectedResult(4, 31, s_incorrectParameterName, "Public Sub Test(first As String)", " ", "paramName", "System.ArgumentNullException"));
        }

        [Fact]
        public void ArgumentException_ParameterNameAsMessage_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentException(""first"");
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_incorrectMessage, "Class.Test(string)", "first", "message", "System.ArgumentException"));
<commit_msg>Add missing FactAttribute and fix issues with the test<commit_after>// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.UnitTests;
using Xunit;

namespace System.Runtime.Analyzers.UnitTests
{
    public class InstantiateArgumentExceptionsCorrectlyTests : DiagnosticAnalyzerTestBase
    {
        private static readonly string s_ruleId = InstantiateArgumentExceptionsCorrectlyAnalyzer.RuleId;
        private static readonly string s_noArguments = SystemRuntimeAnalyzersResources.InstantiateArgumentExceptionsCorrectlyMessageNoArguments;
        private static readonly string s_incorrectMessage = SystemRuntimeAnalyzersResources.InstantiateArgumentExceptionsCorrectlyMessageIncorrectMessage;
        private static readonly string s_incorrectParameterName = SystemRuntimeAnalyzersResources.InstantiateArgumentExceptionsCorrectlyMessageIncorrectParameterName;

        protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
        {
            return new InstantiateArgumentExceptionsCorrectlyAnalyzer();
        }

        protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
        {
            return new InstantiateArgumentExceptionsCorrectlyAnalyzer();
        }

        [Fact]
        public void ArgumentException_NoArguments_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentException();
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_noArguments, "System.ArgumentException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Throw New System.ArgumentException()
                    End Sub
                End Class",
              GetBasicExpectedResult(4, 31, s_noArguments, "System.ArgumentException"));
        }

        [Fact]
        public void ArgumentException_EmptyParameterNameArgument_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentNullException("""");
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_incorrectParameterName, "Class.Test(string)", "", "paramName", "System.ArgumentNullException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Throw New System.ArgumentNullException("""")
                    End Sub
                End Class",
                GetBasicExpectedResult(4, 31, s_incorrectParameterName, "Public Sub Test(first As String)", "", "paramName", "System.ArgumentNullException"));
        }

        [Fact]
        public void ArgumentNullException_SpaceParameterArgument_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentNullException("" "");
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_incorrectParameterName, "Class.Test(string)", " ", "paramName", "System.ArgumentNullException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Throw New System.ArgumentNullException("" "")
                    End Sub
                End Class",
                GetBasicExpectedResult(4, 31, s_incorrectParameterName, "Public Sub Test(first As String)", " ", "paramName", "System.ArgumentNullException"));
        }

        [Fact]
        public void ArgumentNullException_NameofNonParameter_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        var foo = new object();
                        throw new System.ArgumentNullException(nameof(foo));
                    }
                }",
                GetCSharpExpectedResult(7, 31, s_incorrectParameterName, "Class.Test(string)", "foo", "paramName", "System.ArgumentNullException"));

            VerifyBasic(@"
                Public Class MyClass
                    Public Sub Test(Dim first As String)
                        Dim foo As New Object()
                        Throw New System.ArgumentNullException(NameOf(foo))
                    End Sub
                End Class",
                GetBasicExpectedResult(5, 31, s_incorrectParameterName, "Public Sub Test(first As String)", "foo", "paramName", "System.ArgumentNullException"));
        }

        [Fact]
        public void ArgumentException_ParameterNameAsMessage_Warns()
        {
            VerifyCSharp(@"
                public class Class
                {
                    public void Test(string first)
                    {
                        throw new System.ArgumentException(""first"");
                    }
                }", 
                GetCSharpExpectedResult(6, 31, s_incorrectMessage, "Class.Test(string)", "first", "message", "System.ArgumentException"));

{'fraction_non_alphanumeric': 0.07186170694180469, 'fraction_numerical': 0.005249343832020997, 'mean_word_length': 1.7521793275217932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6545147', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2342, 'n_words': 585}