public async void DoesNotFindError_FromAnyMatchingType_WithTypeConstraint(string value) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(" + value + ")] public void TestMethod<T>(T a) where T: System.IConvertible, System.IFormattable { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_FromAnyValues_UsingParams(string value) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(" + value + ")] public void TestMethod(params object[] a) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_FromAnyReferenceType_WithClassConstraint(string value) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(" + value + ")] public void TestMethod<T>(T a) where T: class { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_FromEnum_ToNullable() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(System.StringComparison.Ordinal)] public void TestMethod(System.StringComparison? a) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_FromTypesImplementingInterface(string value) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(" + value + ")] public void TestMethod(System.IFormattable a) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_FromCharType_ToNullable(string value) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(" + value + ")] public void TestMethod(char? a) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_ForCharArgument(string type) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData('a')] public void TestMethod(" + type + " a) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_FromAnyOtherNumericType(string value, string type) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(" + value + ")] public void TestMethod(" + type + " a) { } }"); Assert.Empty(diagnostics); }
public async void FindsWarningForSymbolDeclaringTypeHasZeroArity_ImplementsICollectionOfT() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @" using System.Collections; using System.Collections.Generic; using Xunit; class IntCollection : ICollection<int> { public int Count { get { throw null; } } public bool IsReadOnly { get { throw null; } } public void Add(int item) { throw null; } public void Clear() { throw null; } public bool Contains(int item) { throw null; } public void CopyTo(int[] array, int arrayIndex) { throw null; } public IEnumerator<int> GetEnumerator() { throw null; } public bool Remove(int item) { throw null; } IEnumerator IEnumerable.GetEnumerator() { throw null; } } class TestClass { void TestMethod() { Assert.Equal(1, new IntCollection().Count); } }"); CheckDiagnostics(diagnostics, "Equal"); }
public async void DoesNotFindErrorForMethodWithSingleAttribute(string attribute) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit." + attribute + "] public void TestMethod() { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindErrorForOverridenMethod(string attribute) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, CompilationReporting.IgnoreErrors, "public class TestClass { [" + attribute + "] public void TestMethod() { } public override void Method() {} }"); Assert.Empty(diagnostics); }
public async void DoesNotFindErrorForTheoryMethodWithParameters() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory] public void TestMethod(string s) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_WhenNoDataAttributes() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Fact] public void TestMethod() { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindWarning_ForReferenceParameterType(string type) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit.InlineData(1, null)] public void TestMethod(int a, " + type + " b) { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindErrorForTheoryMethodWithDataAttributes(string dataAttribute) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Theory, Xunit." + dataAttribute + "] public void TestMethod() { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_WithAttribute() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class TestClass { [Xunit.Fact, Xunit.InlineData] public void TestMethod(string a) { } }"); Assert.Empty(diagnostics); }
public async void InterfaceWithProperBaseClass_NoDiagnostics(string @interface, string baseClass) { var code = string.Format(Template, $"{baseClass}, {@interface}"); var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, CompilationReporting.IgnoreErrors, code); Assert.Empty(diagnostics); }
public async void PublicParameterlessConstructor_NoDiagnostics(string @interface) { var code = string.Format(Template, @interface, "public Foo() { }"); var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, code); Assert.Empty(diagnostics); }
public async void ImplicitConstructors_NoDiagnostics(string @interface) { var code = string.Format(Template, @interface, ""); var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, code); Assert.Empty(diagnostics); }
public async void DoesNotFindErrorForDerviedFactMethodWithDataAttributes(string dataAttribute) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, "public class DerivedFactAttribute: Xunit.FactAttribute {}", "public class TestClass { [DerivedFactAttribute, Xunit." + dataAttribute + "] public void TestMethod() { } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindError_ForNameofOnOtherClass() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, sharedCode, "public partial class TestClass { [Xunit.MemberData(nameof(OtherClass.OtherData), MemberType = typeof(OtherClass))] public void TestMethod() { } }"); Assert.Empty(diagnostics); }
public async void ForPublicClass_DoesNotFindError() { var source = "public class TestClass { [Xunit.Fact] public void TestMethod() { } }"; var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, source); Assert.Empty(diagnostics); }
public async void DoesNotFindWarningForCollectionCheckWithAction(string collection) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert.Collection(" + collection + @", i => Xunit.Assert.True(true)); } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindWarning_ForBooleanFalseStartsWithCheck_WithStringComparison() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert.False(""abc"".StartsWith(""a"", System.StringComparison.CurrentCulture)); } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindWarning_ForBooleanStartsWithCheck_WithUserMessage(string method) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert." + method + @"(""abc"".StartsWith(""a""), ""message""); } }"); Assert.Empty(diagnostics); }
public async void DoesNotFindWarning_ForBooleanFalseStartsWithCheck() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert.False(""abc"".StartsWith(""a"")); } }"); Assert.Empty(diagnostics); }
public async void FindsWarning_ForBooleanTrueStartsWithCheck_WithStringComparison() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert.True(""abc"".StartsWith(""a"", System.StringComparison.CurrentCulture)); } }"); AssertHasDiagnostic(diagnostics, "True"); }
public async void FindsWarning_ForBooleanTrueStartsWithCheck() { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert.True(""abc"".StartsWith(""a"")); } }"); AssertHasDiagnostic(diagnostics, "True"); }
public async void FindsWarning_ForBooleanContainsCheck(string method) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert." + method + @"(""abc"".Contains(""a"")); } }"); AssertHasDiagnostic(diagnostics, method); }
public async void DoesNotFindWarning_ForBooleanEndsWithCheck_WithBoolAndCulture_AndUserMessage(string method) { var diagnostics = await CodeAnalyzerHelper.GetDiagnosticsAsync(analyzer, @"class TestClass { void TestMethod() { Xunit.Assert." + method + @"(""abc"".EndsWith(""a"", true, System.Globalization.CultureInfo.CurrentCulture), ""message""); } }"); Assert.Empty(diagnostics); }