Beispiel #1
0
        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);
        }
Beispiel #3
0
        public void NoDiagnosticWhenOtherTypesUsed()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                Assert.That(""1, 2, 3"".Contains(""1""));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #4
0
        public void NoDiagnosticWhenActualAndExpectedTypesAreSame_WithLambdaActualValue()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var expected = """";
                Assert.That(() => """", Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public void ValidOtherMethodUsed()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = ""abc"";
                Assert.That(actual.Contains(""bc""));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #7
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        public void NoDiagnosticWhenUsedWithPropertyConstraint()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
            var actual = ""abc"";
            Assert.That(actual, Has.Property(""Length"").EqualTo(3));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #12
0
        public void ValidWhenIsNotEqualToConstraintUsed()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = ""abc"";
                Assert.That(actual, Is.Not.EqualTo(""bcd""));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        public void NoDiagnosticWhenActualAndExpectedTypesAreSame_WithNegatedAssert()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = """";
                var expected = """";
                Assert.That(actual, Is.Not.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public void NoDiagnosticWhenActualIsNumericNullableType()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
            int? actual = 5;
            double expected = 5.0;
            Assert.That(actual, Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #21
0
        public void NoDiagnosticWhenExpectedIsMatchingNullableType()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
            int actual = 5;
            int? expected = 5;
            Assert.That(actual, Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #22
0
        public void NoDiagnosticWhenExpectedIsDynamic()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = """";
                dynamic expected = 2;
                Assert.That(actual, Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        public void NoDiagnosticForCharAndInt()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = 'a';
                var expected = (int)actual;
                Assert.That(actual, Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
        public void NoDiagnosticWhenActualIsErrorType()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = HaveNoIdea();
                var expected = 3;
                Assert.That(actual, Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }
Beispiel #30
0
        public void NoDiagnosticWhenActualAndExpectedTypesAreSame_WithTaskActualValue()
        {
            var testCode = TestUtility.WrapInTestMethod(@"
                var actual = Task.FromResult("""");
                var expected = """";
                Assert.That(actual, Is.EqualTo(expected));");

            AnalyzerAssert.NoAnalyzerDiagnostics(analyzer, testCode);
        }