コード例 #1
0
        public void ExcelMemberMayReturnNothing_ReturnsResult_FindWithMemberAccess()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    foo = ws.UsedRange.Find(""foo"").Row
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
コード例 #2
0
        public void ExcelMemberMayReturnNothing_ReturnsNoResult_ResultIsNothingInAssignment()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    Dim foo As Boolean
    foo = ws.UsedRange.Find(""foo"") Is Nothing
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.IsFalse(inspectionResults.Any());
            }
        }
コード例 #3
0
        public void ExcelMemberMayReturnNothing_Ignored_DoesNotReturnResult()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    '@Ignore ExcelMemberMayReturnNothing
    foo = ws.UsedRange.Find(""foo"").Row
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.IsFalse(inspectionResults.Any());
            }
        }
コード例 #4
0
        public void ExcelMemberMayReturnNothing_ReturnsNoResult_TransientAccessIsNothing()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    If ws.UsedRange.Find(""foo"") Is Nothing Then
        Debug.Print ""Not found""
    End If
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.IsFalse(inspectionResults.Any());
            }
        }
コード例 #5
0
        public void ExcelMemberMayReturnNothing_ReturnsResult_DefaultAccessExpression()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    If ws.Range(""B:B"").Find(""bar"") = 1 Then 
        Debug.Print ""bar""
    End If
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
コード例 #6
0
        public void ExcelMemberMayReturnNothing_ReturnsResult_AssignedAndNotTested()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    Dim result As Range
    Set result = ws.UsedRange.Find(""foo"")
    result.Value = ""bar""
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }
コード例 #7
0
        public void ExcelMemberMayReturnNothing_ReturnsResult_ResultIsSomethingElse()
        {
            const string inputCode =
                @"Sub UnderTest()
    Dim ws As Worksheet
    Set ws = Sheet1
    Dim result As Range
    Set result = ws.Range(""A1"")
    If ws.UsedRange.Find(""foo"") Is result Then
        Debug.Print ""Found it the dumb way""
    End If
End Sub
";

            using (var state = ArrangeParserAndParse(inputCode))
            {
                var inspection        = new ExcelMemberMayReturnNothingInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }