public void ValidWhenIgnoreCaseUsedForStringEqualToArgument() { var testCode = TestUtility.WrapInTestMethod(@" Assert.That(""A"", Is.EqualTo(""a"").IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidForNonStringMethods() { var testCode = TestUtility.WrapInTestMethod( @"Assert.That(new List<string> { ""a"",""ab""}.Contains(""ab""));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenOtherTypesUsed() { var testCode = TestUtility.WrapInTestMethod(@" Assert.That(""1, 2, 3"".Contains(""1""));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenActualAndExpectedTypesAreSame_WithLambdaActualValue() { var testCode = TestUtility.WrapInTestMethod(@" var expected = """"; Assert.That(() => """", Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenConditionalPrefixPresent() { var testCode = TestUtility.WrapInTestMethod(@" bool shouldBePresent = true; Assert.That(new[] { 1, 2, 3 }, (shouldBePresent ? Has.Some : Has.None).EqualTo(2));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidOtherMethodUsed() { var testCode = TestUtility.WrapInTestMethod(@" var actual = ""abc""; Assert.That(actual.Contains(""bc""));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenObjectComparedToInt() { var testCode = TestUtility.WrapInTestMethod(@" object actual = 3; Assert.That(actual, Is.EqualTo(3));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidWhenDifferentExpressionsProvided() { var testCode = TestUtility.WrapInTestMethod($@" var str = ""test""; Assert.That(str.Trim(), Is.EqualTo(↓str.TrimEnd()));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidForValueTupleWithStringMember() { var testCode = TestUtility.WrapInTestMethod(@" var actual = (""a"", 2, false); Assert.That(actual, Is.EqualTo((""A"", 2, false)).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenListOtherMethodsUsed() { var testCode = TestUtility.WrapInTestMethod(@" Assert.That(new List<int> { 1, 2, 3 }.Remove(1));", additionalUsings: "using System.Collections.Generic;"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenUsedWithPropertyConstraint() { var testCode = TestUtility.WrapInTestMethod(@" var actual = ""abc""; Assert.That(actual, Has.Property(""Length"").EqualTo(3));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidWhenIsNotEqualToConstraintUsed() { var testCode = TestUtility.WrapInTestMethod(@" var actual = ""abc""; Assert.That(actual, Is.Not.EqualTo(""bcd""));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidWhenNonGenericIEnumerableProvided() { var testCode = TestUtility.WrapInTestMethod(@" var actual = new[] {""a"",""b"",""c""}; System.Collections.IEnumerable expected = new[] {""A"",""C"",""B""}; Assert.That(actual, Is.EqualTo(expected).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidWhenIgnoreCaseUsedForStringCollection(string constraintMethod) { var testCode = TestUtility.WrapInTestMethod($@" var actual = new[] {{""a"",""b"",""c""}}; var expected = new[] {{""A"",""C"",""B""}}; Assert.That(actual, Is.{constraintMethod}(expected).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenActualAndExpectedTypesAreSame_WithNegatedAssert() { var testCode = TestUtility.WrapInTestMethod(@" var actual = """"; var expected = """"; Assert.That(actual, Is.Not.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenExpectedIsErrorTypeArray() { var testCode = TestUtility.WrapInTestMethod(@" var actual = new[] { 3 }; var expected = HaveNoIdea(); Assert.That(actual, Is.EqualTo(new[] { expected }));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticForKeyValuePairsOfNumerics() { var testCode = TestUtility.WrapInTestMethod(@" var actual = new KeyValuePair<string, int>(""a"", 1); var expected = new KeyValuePair<string, double>(""a"", 1.0); Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidForDictionaryEntry() { var testCode = TestUtility.WrapInTestMethod(@" var expected = new System.Collections.DictionaryEntry(1, ""a""); var actual = new System.Collections.DictionaryEntry(1, ""A""); Assert.That(actual, Is.EqualTo(expected).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenVariableIsPartOfConstraint() { var testCode = TestUtility.WrapInTestMethod(@" bool shouldBePresent = true; var constraintModifier = (shouldBePresent ? Has.Some : Has.None); Assert.That(new[] { 1, 2, 3 }, constraintModifier.EqualTo(2));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenActualIsNumericNullableType() { var testCode = TestUtility.WrapInTestMethod(@" int? actual = 5; double expected = 5.0; Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenExpectedIsMatchingNullableType() { var testCode = TestUtility.WrapInTestMethod(@" int actual = 5; int? expected = 5; Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenExpectedIsDynamic() { var testCode = TestUtility.WrapInTestMethod(@" var actual = """"; dynamic expected = 2; Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticForValueTuplesWithCompatibleElementTypes() { var testCode = TestUtility.WrapInTestMethod(@" var actual = (""1"", 2.0); var expected = (""1"", 2); Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidForTupleWithStringMember() { var testCode = TestUtility.WrapInTestMethod(@" var actual = System.Tuple.Create(1, ""a""); var expected = System.Tuple.Create(1, ""A""); Assert.That(actual, Is.EqualTo(expected).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidForKeyValuePairWithStringValue() { var testCode = TestUtility.WrapInTestMethod(@" var expected = new System.Collections.Generic.KeyValuePair<int, string>(1, ""a""); var actual = new System.Collections.Generic.KeyValuePair<int, string>(1, ""A""); Assert.That(actual, Is.EqualTo(expected).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticForCharAndInt() { var testCode = TestUtility.WrapInTestMethod(@" var actual = 'a'; var expected = (int)actual; Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void ValidForDeepNesting() { var testCode = TestUtility.WrapInTestMethod(@" var actual = (1, new[] { new[] { ""a"" } }); var expected = (1, new[] { new[] { ""A"" } }); Assert.That(actual, Is.EqualTo(expected).IgnoreCase);"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticForStreams() { var testCode = TestUtility.WrapInTestMethod(@" var actual = new System.IO.FileStream("""", System.IO.FileMode.Open);; var expected = new System.IO.MemoryStream(); Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenActualIsErrorType() { var testCode = TestUtility.WrapInTestMethod(@" var actual = HaveNoIdea(); var expected = 3; Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }
public void NoDiagnosticWhenActualAndExpectedTypesAreSame_WithTaskActualValue() { var testCode = TestUtility.WrapInTestMethod(@" var actual = Task.FromResult(""""); var expected = """"; Assert.That(actual, Is.EqualTo(expected));"); AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode); }