public SarifFileWithContentsTests()
        {
            var testLog = new SarifLog
            {
                Runs = new List <Run>
                {
                    new Run
                    {
                        Tool = new Tool
                        {
                            Name            = "Test",
                            SemanticVersion = "1.0"
                        },
                        Files = new Dictionary <string, FileData>
                        {
                            {
                                "file:///item.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = "VGhpcyBpcyBhIHRlc3QgZmlsZS4=",
                                    Hashes   = new List <Hash>
                                    {
                                        new Hash
                                        {
                                            Algorithm = AlgorithmKind.Sha256,
                                            Value     = "HashValue"
                                        }
                                    }
                                }
                            }
                        },
                        Results = new List <Result>
                        {
                            new Result
                            {
                                RuleId    = "C0001",
                                Message   = "Error 1",
                                Locations = new List <Location>
                                {
                                    new Location
                                    {
                                        AnalysisTarget = new PhysicalLocation
                                        {
                                            Uri = new Uri("file:///item.cpp")
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestUtilities.InitializeTestEnvironment(testLog);
        }
        public async Task ErrorList_IsSarifLogOpened()
        {
            TestUtilities.InitializeTestEnvironment();

            string logFileName1   = @"C:\git\repo\sarif-sdk\test_data\testresult1.sarif";
            string logFileName2   = @"C:\git\repo\sarif-sdk\test_data\testtool2.sarif";
            bool   sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);

            sarifLogOpened.Should().BeFalse();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeFalse();

            // load sarif log 1
            await TestUtilities.InitializeTestEnvironmentAsync(this.testLog, logFileName1);

            bool hasFirstError  = SarifTableDataSource.Instance.HasErrors("/item1.cpp");
            bool hasSecondError = SarifTableDataSource.Instance.HasErrors("/item2.cpp");
            bool hasThirdError  = SarifTableDataSource.Instance.HasErrors("/item3.cpp");

            bool hasBothErrors = hasFirstError && hasSecondError && hasThirdError;

            hasBothErrors.Should().BeTrue();

            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);
            sarifLogOpened.Should().BeTrue();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeFalse();

            // load sarif log 2
            await TestUtilities.InitializeTestEnvironmentAsync(this.testLog, logFileName2, cleanErrors : false);

            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);
            sarifLogOpened.Should().BeTrue();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeTrue();

            // close sairf log 1
            await ErrorListService.CloseSarifLogItemsAsync(new string[] { logFileName1 });

            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);
            sarifLogOpened.Should().BeFalse();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeTrue();
        }
Exemplo n.º 3
0
        public SarifFileWithContentsTests()
        {
            var testLog = new SarifLog
            {
                Runs = new List <Run>
                {
                    new Run
                    {
                        Tool = new Tool
                        {
                            Name            = "Test",
                            SemanticVersion = "1.0"
                        },
                        Files = new Dictionary <string, FileData>
                        {
                            {
                                "file:///item.cpp#fragment",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Binary = "VGhpcyBpcyBhIHRlc3QgZmlsZS4="
                                    },
                                    Hashes = new List <Hash>
                                    {
                                        new Hash
                                        {
                                            Algorithm = "sha-256",
                                            Value     = ExpectedHashValue1
                                        }
                                    }
                                }
                            },
                            {
                                "file:///binary.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Binary = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4="
                                    },
                                    Hashes = new List <Hash>
                                    {
                                        new Hash
                                        {
                                            Algorithm = "sha-256",
                                            Value     = ExpectedHashValue2
                                        }
                                    }
                                }
                            },
                            {
                                "file:///text.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Text = ExpectedContents1
                                    }
                                }
                            },
                            {
                                "file:///both.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Binary = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4=",
                                        Text   = ExpectedContents2
                                    },
                                    Hashes = new List <Hash>
                                    {
                                        new Hash
                                        {
                                            Algorithm = "sha-256",
                                            Value     = ExpectedHashValue2
                                        }
                                    }
                                }
                            },
                            {
                                "file:///emptybinary.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Binary = ""
                                    }
                                }
                            },
                            {
                                "file:///emptytext.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Text = ""
                                    }
                                }
                            },
                            {
                                "file:///existinghash.cpp",
                                new FileData
                                {
                                    MimeType = "text/x-c",
                                    Contents = new FileContent()
                                    {
                                        Text = ExpectedContents2
                                    },
                                    Hashes = new List <Hash>
                                    {
                                        new Hash
                                        {
                                            Algorithm = "sha-256",
                                            Value     = ExpectedHashValue1
                                        }
                                    }
                                }
                            }
                        },
                        Results = new List <Result>
                        {
                            new Result
                            {
                                AnalysisTarget = new
                                                 FileLocation
                                {
                                    Uri = new Uri(@"file:///item.cpp")
                                },
                                RuleId  = "C0001",
                                Message = new Message {
                                    Text = "Error 1"
                                },
                                Locations = new List <Location>
                                {
                                    new Location()
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestUtilities.InitializeTestEnvironment(testLog);
        }
 public SarifErrorListItemTests()
 {
     TestUtilities.InitializeTestEnvironment();
 }
Exemplo n.º 5
0
 public SarifLocationErrorTagTests()
 {
     TestUtilities.InitializeTestEnvironment();
 }
Exemplo n.º 6
0
        public MultipleRunsPerSarifTests()
        {
            var testLog = new SarifLog
            {
                Runs = new List <Run>
                {
                    new Run
                    {
                        Tool = new Tool
                        {
                            Driver = new ToolComponent
                            {
                                Name            = "Test",
                                SemanticVersion = "1.0"
                            }
                        },
                        Results = new List <Result>
                        {
                            new Result
                            {
                                RuleId  = "C0001",
                                Message = new Message {
                                    Text = "Error 1"
                                },
                                Locations = new List <Location>
                                {
                                    new Location
                                    {
                                        PhysicalLocation = new PhysicalLocation
                                        {
                                            ArtifactLocation = new ArtifactLocation
                                            {
                                                Uri = new Uri("file:///item1.cpp")
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new Run
                    {
                        Tool = new Tool
                        {
                            Driver = new ToolComponent
                            {
                                Name            = "Test",
                                SemanticVersion = "1.0"
                            }
                        },
                        Results = new List <Result>
                        {
                            new Result
                            {
                                RuleId  = "C0002",
                                Message = new Message {
                                    Text = "Error 2"
                                },
                                Locations = new List <Location>
                                {
                                    new Location
                                    {
                                        PhysicalLocation = new PhysicalLocation
                                        {
                                            ArtifactLocation = new ArtifactLocation
                                            {
                                                Uri = new Uri("file:///item2.cpp")
                                            }
                                        }
                                    }
                                }
                            },
                            new Result
                            {
                                RuleId  = "C0003",
                                Message = new Message {
                                    Text = "Error 3"
                                },
                                Locations = new List <Location>
                                {
                                    new Location
                                    {
                                        PhysicalLocation = new PhysicalLocation
                                        {
                                            ArtifactLocation = new ArtifactLocation
                                            {
                                                Uri = new Uri("file:///item3.cpp")
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestUtilities.InitializeTestEnvironment(testLog);
        }
Exemplo n.º 7
0
        public MultipleRunsPerSarifTests()
        {
            var testLog = new SarifLog
            {
                Runs = new List <Run>
                {
                    new Run
                    {
                        Tool = new Tool
                        {
                            Name            = "Test",
                            SemanticVersion = "1.0"
                        },
                        Results = new List <Result>
                        {
                            new Result
                            {
                                RuleId    = "C0001",
                                Message   = "Error 1",
                                Locations = new List <Location>
                                {
                                    new Location
                                    {
                                        AnalysisTarget = new PhysicalLocation
                                        {
                                            Uri = new Uri("file:///item1.cpp")
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new Run
                    {
                        Tool = new Tool
                        {
                            Name            = "Test",
                            SemanticVersion = "1.0"
                        },
                        Results = new List <Result>
                        {
                            new Result
                            {
                                RuleId    = "C0002",
                                Message   = "Error 2",
                                Locations = new List <Location>
                                {
                                    new Location
                                    {
                                        AnalysisTarget = new PhysicalLocation
                                        {
                                            Uri = new Uri("file:///item2.cpp")
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestUtilities.InitializeTestEnvironment(testLog);
        }