當前位置: 首頁>>代碼示例>>C#>>正文


C# TestHelper.DiagnosticResult類代碼示例

本文整理匯總了C#中TestHelper.DiagnosticResult的典型用法代碼示例。如果您正苦於以下問題:C# DiagnosticResult類的具體用法?C# DiagnosticResult怎麽用?C# DiagnosticResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DiagnosticResult類屬於TestHelper命名空間,在下文中一共展示了DiagnosticResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DoNotUseValuesWhenMultipleIsFalse

		public void DoNotUseValuesWhenMultipleIsFalse()
		{
			var testContent = @"
				using Bridge.React;

				namespace TestCase
				{
					public class Example
					{
						public void Go()
						{
							new SelectAttributes { Multiple = false, Values = new[] { ""1"" } };
						}
					}
				}";

			var expected = new DiagnosticResult
			{
				Id = SelectAttributesAnalyzer.DiagnosticId,
				Message = SelectAttributesAnalyzer.DoNotUseValuesWhenMultipleIsFalseRule.MessageFormat.ToString(),
				Severity = DiagnosticSeverity.Warning,
				Locations = new[]
				{
					new DiagnosticResultLocation("Test0.cs", 10, 29)
				}
			};

			VerifyCSharpDiagnostic(testContent, expected);
		}
開發者ID:ProductiveRage,項目名稱:Bridge.React,代碼行數:29,代碼來源:SelectAttributesTests.cs

示例2: AccessWithoutChecking

        public void AccessWithoutChecking()
        {
            var code = @"
                        using System;
                        using System.Linq;

                        namespace ConsoleApp1
                        {
                            public class Test0
                            {
                                public void Tested()
                                {
                                    var obj = new Object();
                                    
                                    var s = obj as String;

                                    var toString = s.ToString();
                                }
                            }
                        }
                        ";

            var expected = new DiagnosticResult
            {
                Id = "AV1570",
                Message = "Always check the result of an as operation",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 15, 52)
                        }
            };

            VerifyCSharpDiagnostic(code, expected);
        }
開發者ID:mytinyfast,項目名稱:CSharpCodingGuidelines,代碼行數:35,代碼來源:AV1570Tests.cs

示例3: Test1

        public void Test1()
        {
            var test = @"
class C
{
    public void M1()
    {
    }

    public virtual void M2()
    {
    }

    public int M3()
    {
    }
}";
            var expected = new DiagnosticResult
            {
                Id = DiagnosticIds.CodeBlockAnalyzerRuleId,
                Message = string.Format(Resources.CodeBlockAnalyzerMessageFormat, "M1"),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[]
                    {
                        new DiagnosticResultLocation("Test0.cs", 4, 17)
                    }
            };

            VerifyCSharpDiagnostic(test, expected);
        }
開發者ID:CAPCHIK,項目名稱:roslyn,代碼行數:31,代碼來源:CodeBlockAnalyzerUnitTests.cs

示例4: UnHandle

        public void UnHandle()
        {
            var source = @"
using System;
   
class Test
{
    IObservable<int> GetObservable() => null;

    void Hoge()
    {
        GetObservable();
    }
}";
            var expected = new DiagnosticResult
            {
                Id = UniRxAnalyzer.HandleObservableAnalyzer.DiagnosticId,
                Message = "This call does not handle IObservable<T>.",
                Severity = DiagnosticSeverity.Warning,
                Locations = new[]
                {
                    new DiagnosticResultLocation("Test0.cs", 10, 9)
                }
            };

            this.VerifyCSharpDiagnostic(source, expected);
        }
開發者ID:createdbyx,項目名稱:UniRx,代碼行數:27,代碼來源:HandleObservableAnalyzerTest.cs

示例5: TestCSharpAtrributesPresentButEmpty

        public void TestCSharpAtrributesPresentButEmpty()
        {
            var expected = new DiagnosticResult[4];
            expected[0] = CompanyAttributeResult;
            expected[1] = CopyrightAttributeResult;
            expected[2] = DescriptionAttributeResult;
            expected[3] = TitleAttributeResult;

            VerifyCSharpDiagnostic(@"
using System;
using System.Reflection;

[assembly: AssemblyTitle("""")]
[assembly: AssemblyDescription("""")]
[assembly: AssemblyCompany("""")]
[assembly: AssemblyCopyright("""")]

namespace SomeTests
{
    public class BasicClass
    {
        public void SomeWork(String message)
        {
            Console.WriteLine(message);
        }
    }
}
", expected);
        }
開發者ID:vuder,項目名稱:Wintellect.Analyzers,代碼行數:29,代碼來源:AssemblyAttributesUnitTests.cs

示例6: ForeachSimpleStatementAssignment

        public void ForeachSimpleStatementAssignment()
        {
            var code = @"
                        using System;
                        using System.Linq;

                        namespace ConsoleApp1
                        {
                            public class Test0
                            {
                                public void Tested()
                                {
                                    var list = new List<int>();
                                    foreach(var item in list)
                                        item = null;
                                }
                            }
                        }
                        ";

            var expected = new DiagnosticResult
            {
                Id = "AV1530",
                Message = "Don’t change a loop variable inside a for or foreach loop",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 13, 41)
                        }
            };

            VerifyCSharpDiagnostic(code, expected);
        }
開發者ID:mytinyfast,項目名稱:CSharpCodingGuidelines,代碼行數:33,代碼來源:AV1530Tests.cs

示例7: TestMethod2

        public void TestMethod2()
        {
            var test = @"using System;
using FluentArithmetic;

class Program
{
    static void Main(string[] args)
    {
        var x = 1.Add(2).Mul(3).Sub(1).Div(0);
        Console.WriteLine(x);
    }
}
";
            var expected = new DiagnosticResult
            {
                Id = DivByZeroAnalyzer.DiagnosticId,
                Message = DivByZeroAnalyzer.MessageFormat.ToString(),
                Severity = DiagnosticSeverity.Error,
                Locations = new[]
                {
                    new DiagnosticResultLocation("Test0.cs", 8, 44)
                }
            };

            VerifyCSharpDiagnostic(test, expected);
        }
開發者ID:ufcpp,項目名稱:UfcppSample,代碼行數:27,代碼來源:DivByZeroUnitTest.cs

示例8: ValidateDiagnosticFires

        public void ValidateDiagnosticFires()
        {
            var test = @"
            using System;
            using System.Collections.Generic;

            namespace ConsoleApplication1
            {
            class TypeName
            {
               var a = new System.Collections.ArrayList();
            }
            }";
            var expected = new DiagnosticResult
            {
                Id = DontUseArrayList.DiagnosticId,
                Message = "The type ArrayList should not be used",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 9, 20)
                        }
            };

            VerifyCSharpDiagnostic(test, expected);
        }
開發者ID:johnkoerner,項目名稱:AnalyzerSamples,代碼行數:26,代碼來源:DontUseArrayListTests.cs

示例9: MethodNamesTest

        public void MethodNamesTest()
        {
            string test = System.IO.File.ReadAllText(@"TestCodes\AsyncTestCode_1.cs");
            var expected1 = new DiagnosticResult
            {
                Id = AsyncAnalyzerAnalyzer.DiagnosticId,
                Message = String.Format("Async method name '{0}' does not end with Async", "Test"),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[]
                    {
                        new DiagnosticResultLocation("Test0.cs", 12, 27),
                    }
            };

            var expected2 = new DiagnosticResult
            {
                Id = AsyncAnalyzerAnalyzer.DiagnosticId,
                Message = String.Format("Async method name '{0}' does not end with Async", "Something"),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[]
                    {
                        new DiagnosticResultLocation("Test0.cs", 28, 33),
                    }
            };

            VerifyCSharpDiagnostic(test, expected1, expected2);

            string fixtest = System.IO.File.ReadAllText(@"TestCodes\AsyncTestCode_1_fix.cs");
            VerifyCSharpFix(test, fixtest);
        }
開發者ID:jernejk,項目名稱:Roslyn-simple-demos,代碼行數:32,代碼來源:JkAsyncTests.cs

示例10: TestBasicEmptyComment

        public void TestBasicEmptyComment()
        {
            var testCode = @"
            class Foo
            {
            public void Bar()
            {
            //
            }
            }";

            var expected = new DiagnosticResult
            {
                Id = EmptyCommentAnalyzer.DiagnosticId,
                Message = EmptyCommentAnalyzer.MessageFormat.ToString(),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 6, 9)
                        }
            };
            this.VerifyCSharpDiagnostic(testCode, expected);

            var expectedFixedCode = @"
            class Foo
            {
            public void Bar()
            {
            }
            }";
            this.VerifyCSharpFix(testCode, expectedFixedCode);
        }
開發者ID:johnkoerner,項目名稱:AnalyzerSamples,代碼行數:32,代碼來源:EmptyCommentCodeFix.cs

示例11: AssertEquals_IfActualValueIsAStringLiteral_ThenItTriggersTheDiagnostic

        public void AssertEquals_IfActualValueIsAStringLiteral_ThenItTriggersTheDiagnostic()
        {
            var test = @"
    using System;
    using System.Linq;
    using Xunit;

    namespace WongaTests
    {
        class WongaTest
        {
            [Fact]
            public void MyTest()
            {
                var result = Testee.GetSomeData();
                Assert.Equal(result.Id, ""someId"");
            }
        }
    }";
            var expected = new DiagnosticResult
            {
                Id = "AssertExpectedActualAnalyser",
                Message = "Possible incorrect argument order in 'Assert.Equal': '\"someId\"' is likely to be the expected value",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 14, 17)
                        }
            };

            VerifyCSharpDiagnostic(test, expected);
        }
開發者ID:itowlson,項目名稱:unexpected,代碼行數:32,代碼來源:UnitTests.cs

示例12: TestMethod2

        public void TestMethod2()
        {
            const String test = @"
            using System;

            namespace ConsoleApplication1
            {
            class TypeName
            {
            }
            }";
            var expected = new DiagnosticResult
            {
                Id = "CSharpCodeFixes",
                Message = $"Type name '{"TypeName"}' contains lowercase letters",
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 6, 15)
                        }
            };

            VerifyCSharpDiagnostic(test, expected);

            const String fixtest = @"
            using System;

            namespace ConsoleApplication1
            {
            class TYPENAME
            {
            }
            }";
            VerifyCSharpFix(test, fixtest);
        }
開發者ID:damieng,項目名稱:CSharpCodeFixes,代碼行數:35,代碼來源:UnitTests.cs

示例13: CorrectDiagnosticWhenAnonymousTypeInProjection

        public void CorrectDiagnosticWhenAnonymousTypeInProjection()
        {
            // Fixture setup
            var test = @"
            using System;
            using System.Linq;

            namespace N
            {
            class C
            {
            void M()
            {
            var q = Enumerable.Range(0, 5)
                .Select(i => new { Qux = i });
            }
            }
            }";
            var expected = new DiagnosticResult
            {
                Id = "ExtractAnonymousType",
                Message = "Anonymous type used",
                Severity = DiagnosticSeverity.Info,
                Locations =
                    new[] {
                            new DiagnosticResultLocation("Test0.cs", 12, 30)
                        }
            };
            // Exercise system & Verify outcome
            VerifyCSharpDiagnostic(test, expected);
            // Teardown
        }
開發者ID:Pvlerick,項目名稱:ExtractAnonymousType,代碼行數:32,代碼來源:ExtractAnonymousTypeAnalyzerTests.cs

示例14: Test1

        public void Test1()
        {
            var test = @"
class C
{
    public void M()
    {
        var implicitTypedLocal = 0;
        int explicitTypedLocal = 1;
    }
}";
            var expected = new DiagnosticResult
            {
                Id = DiagnosticIds.SyntaxNodeAnalyzerRuleId,
                Message = string.Format(Resources.SyntaxNodeAnalyzerMessageFormat, "implicitTypedLocal"),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[]
                    {
                        new DiagnosticResultLocation("Test0.cs", 6, 13)
                    }
            };

            VerifyCSharpDiagnostic(test, expected);
        }
開發者ID:CAPCHIK,項目名稱:roslyn,代碼行數:25,代碼來源:SyntaxNodeAnalyzerUnitTests.cs

示例15: Test1

        public void Test1()
        {
            var test = @"
namespace MyInterfaces
{
    public interface Interface {}

    class MyInterfaceImpl : Interface
    {
    }

    class MyInterfaceImpl2 : Interface
    {
    }
}";
            var expected = new DiagnosticResult
            {
                Id = DiagnosticIds.CompilationStartedAnalyzerRuleId,
                Message = string.Format(Resources.CompilationStartedAnalyzerMessageFormat, "MyInterfaceImpl2", CompilationStartedAnalyzer.DontInheritInterfaceTypeName),
                Severity = DiagnosticSeverity.Warning,
                Locations =
                    new[]
                    {
                        new DiagnosticResultLocation("Test0.cs", 10, 11)
                    }
            };

            VerifyCSharpDiagnostic(test, expected);
        }
開發者ID:Rickinio,項目名稱:roslyn,代碼行數:29,代碼來源:CompilationStartedAnalyzerUnitTests.cs


注:本文中的TestHelper.DiagnosticResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。