-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from lgolding/master
Add unit test for RuleDictionaryConverter
- Loading branch information
Showing
11 changed files
with
219 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Sarif.UnitTests/Readers/RuleDictionaryConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Readers | ||
{ | ||
[TestClass] | ||
public class RuleDictionaryConverterTests : JsonTests | ||
{ | ||
[TestMethod] | ||
public void RuleDictionaryConverter_WritesRule() | ||
{ | ||
string expected = | ||
@"{ | ||
""$schema"": ""http://json.schemastore.org/sarif-1.0.0-beta.5"", | ||
""version"": ""1.0.0-beta.5"", | ||
""runs"": [ | ||
{ | ||
""tool"": { | ||
""name"": null | ||
}, | ||
""rules"": { | ||
""CA1000.1"": { | ||
""id"": ""CA1000"" | ||
} | ||
} | ||
} | ||
] | ||
}"; | ||
string actual = GetJson(uut => | ||
{ | ||
var run = new Run(); | ||
uut.Initialize(id: null, correlationId: null); | ||
uut.WriteTool(DefaultTool); | ||
uut.WriteRules(new Dictionary<string, IRule> | ||
{ | ||
["CA1000.1"] = new Rule { Id = "CA1000" } | ||
}); | ||
}); | ||
|
||
Assert.AreEqual(expected, actual); | ||
|
||
var sarifLog = JsonConvert.DeserializeObject<SarifLog>(actual); | ||
Assert.AreEqual("CA1000", sarifLog.Runs[0].Rules["CA1000.1"].Id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.