public void CircuitBreakerAnalyzer_WhileWithDoubleNestedNoBreak_ProposeFix()
        {
            var test = @"
namespace ConsoleApplication1
{
	class TypeName
	{   
		static void Main(string[] args)
		{
			int i = 0;
			while(i > 1)
			{
				i++
                if(i > 100)
                {
                    if(i > 120)
                    {
                        
                    }
                }
			}
		}
	}
}";

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0001", "Add circuit breaker to loop", 9, 4);

            VerifyCSharpDiagnostic(test, expected);
        }
示例#2
0
        public void TimeSpanFormatAnalyzer_MM_ProposeFix()
        {
            var nameSpace = @"using System;
using System.Globalization;";
            var method    = @"var time = new TimeSpan(20, 10, 5, 2).ToString(@""MM"", CultureInfo.InvariantCulture);";

            var test     = CodeTestHelper.GetCodeInMainMethod(nameSpace, method);
            var expected = CodeTestHelper.CreateDiagnosticResult("AN0009", "Month not valid in TimeSpan formatting. Did you mean 'm' (minutes)?", 10, 15);

            VerifyCSharpDiagnostic(test, expected);
        }
示例#3
0
        public void DateFormatAnalyzer_DateTimeyymmdd_ProposeFix()
        {
            var nameSpace = @"using System;";
            var method    = @"var date = DateTime.UtcNow.ToString(""yy/mm/dd"");";

            var test = CodeTestHelper.GetCodeInMainMethod(nameSpace, method);

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0008", 9, 15);

            VerifyCSharpDiagnostic(test, expected);
        }
示例#4
0
        public void TimeSpanFormatAnalyzer_F_ProposeFix()
        {
            var nameSpace = @"using System;
using System.Globalization;";
            var method    = @"var time = new TimeSpan(20, 10, 5, 2).ToString(@""F"", CultureInfo.InvariantCulture);";

            var test     = CodeTestHelper.GetCodeInMainMethod(nameSpace, method);
            var expected = CodeTestHelper.CreateDiagnosticResult("AN0009", "'F' alone doesn't work in TimeSpan, use %f or in a pattern @\"F\\:ff\"", 10, 15);

            VerifyCSharpDiagnostic(test, expected);
        }
示例#5
0
        public void DateAndTimeStringAnalyzer_TimeSpanToStringWithoutInvariantCulture_ProposeFix()
        {
            var nameSpace = @"using System;";
            var method    = @"var timeSpan = new TimeSpan(0).ToString(""mm/dd/yyyy hh:mm:ss"");";

            var test = CodeTestHelper.GetCodeInMainMethod(nameSpace, method);

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0007", "Use InvariantCulture for printing date/time", 9, 19);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void DateTimeAnalyzer_InitializeDateTimeTicks_ProposeFix()
        {
            var nameSpace = @"using System;";
            var method    = @"DateTime dateTime = new DateTime(0);";

            var test = CodeTestHelper.GetCodeInMainMethod(nameSpace, method);

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0002", "DateTime kind should be UTC", 9, 24);

            VerifyCSharpDiagnostic(test, expected);
        }
示例#7
0
        public void DoubleFloatParseAnalyzer_TryParseFloatWithoutInvarientCulture_ProposeFix()
        {
            var nameSpace = @"using System;
using System.Globalization;";
            var method    = @"bool didParse = float.TryParse(""1.1"", out float parsedFloat);";

            var test = CodeTestHelper.GetCodeInMainMethod(nameSpace, method);

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0003", "Use InvariantCulture for double/float parsing", 10, 20);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void CollectionContainsAnalyzer_ListAnyCouldBeContainsLeft_ProposeFix()
        {
            var namespaces = @"
using System.Collections.Generic;
using System.Linq;
    ";

            var methodBody = @"
            var collection = new List<string>();
            var result = collection.Any(e => e == ""test"");
            ";

            var code = CodeTestHelper.GetCodeInMainMethod(namespaces, methodBody);

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0010", 14, 41);

            VerifyCSharpDiagnostic(code, expected);
        }
        public void CollectionContainsAnalyzer_HashSetAnyIntCouldBeContainsRight_ProposeFix()
        {
            var namespaces = @"
using System.Collections.Generic;
using System.Linq;
    ";

            var methodBody = @"
            var collection = new HashSet<int>();
            var result = collection.Any(e => 5 == e);
            ";

            var code = CodeTestHelper.GetCodeInMainMethod(namespaces, methodBody);

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0010", 14, 41);

            VerifyCSharpDiagnostic(code, expected);
        }
        public void CircuitBreakerAnalyzer_ForWithoutConditionNoBreak_ProposeFix()
        {
            var test = @"
namespace ConsoleApplication1
{
	class TypeName
	{   
		static void Main(string[] args)
		{
			for(;;)
			{
				int o = 1;
			}
		}
	}
}";

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0001", "Add circuit breaker to loop", 8, 4);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void CircuitBreakerAnalyzer_ConditionGreaterOrEqualsThanIncrementingBreakerLeft_ProposeFix()
        {
            var test = @"
namespace ConsoleApplication1
{
	class TypeName
	{   
		static void Main(string[] args)
		{
			int i = 10;
			while(1 <= i)
			{
				i++;
			}
		}
	}
}";

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0001", 9, 4);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void CircuitBreakerAnalyzer_ConditionLessThanDecrementingAndOperator_ProposeFix()
        {
            var test = @"
namespace ConsoleApplication1
{
	class TypeName
	{   
		static void Main(string[] args)
		{
            bool run = true;
			int i = 1;
			while(i < 10 && run)
			{
				i--;
			}
		}
	}
}";

            var expected = CodeTestHelper.CreateDiagnosticResult("AN0001", 10, 4);

            VerifyCSharpDiagnostic(test, expected);
        }