public void StatusLogic_AnalyseApiResults_CorrectResultsReturned() { // Arrange ApiScanResult results = ApiLogic.ApiScanResult(JSON_RESULT); StatusLogic statusLogic = new StatusLogic(); // Act Dictionary <string, AsafaResult> analysedResults = statusLogic.AnalyseResults(results); // Assert Assert.That(analysedResults.Count, Is.EqualTo(5)); }
static void Main(string[] args) { StatusLogic logic = LoadParams(args); ApiLogic api = new ApiLogic(_name, _key, _url); if (_validParams) { Console.Write("Selected failures: "); if (logic.FailOnFailure) { Console.Write("Failures "); } if (logic.FailOnWarning) { Console.Write("Warnings "); } if (logic.FailOnNotTested) { Console.Write("Not Tested"); } if (!logic.FailOnNotTested && !logic.FailOnWarning && !logic.FailOnFailure) { Console.Write("None, this will always pass"); } Console.WriteLine(); if (logic.IgnoredTests.Count > 0) { Console.WriteLine("Ignored Tests: {0}", logic.IgnoredTests.Aggregate((i, j) => i + ", " + j)); } Console.WriteLine("Scanning {0}", _url); var results = logic.AnalyseResults(api.Scan()); if (results.Count > 0) { StringBuilder sb = new StringBuilder(); sb.AppendLine("ERROR DETECTED:"); foreach (var asafaResult in results) { sb.AppendLine(string.Format("The {0} test has failed with the status {1}", asafaResult.Key, asafaResult.Value)); } sb.AppendLine(); sb.AppendLine(string.Format("For more information visit https://asafaweb.com/Scan?Url={0}", HttpUtility.UrlEncode(_url))); Console.WriteLine(sb.ToString()); if (_throwExceptionOnFail) { throw new Exception(sb.ToString()); } } Console.WriteLine("No errors found"); } }
public void StatusLogic_AnalyseResults_DontFailOnFailure_SomeFailed_NotIncluded() { // Arrange Dictionary <string, AsafaResult> results = new Dictionary <string, AsafaResult> { { "Key1", AsafaResult.Fail } }; StatusLogic logic = new StatusLogic { FailOnFailure = false }; // Act Dictionary <string, AsafaResult> updatedResults = logic.AnalyseResults(results); // Assert Assert.That(updatedResults.Count, Is.EqualTo(0)); }
public void StatusLogic_AnalyseResults_FailOnNotTested_SomeNotTested_IncludedInFails() { // Arrange Dictionary <string, AsafaResult> results = new Dictionary <string, AsafaResult> { { "Key1", AsafaResult.NotTested } }; StatusLogic logic = new StatusLogic { FailOnNotTested = true }; // Act Dictionary <string, AsafaResult> updatedResults = logic.AnalyseResults(results); // Assert Assert.That(updatedResults.Count, Is.EqualTo(1)); }
public void StatusLogic_AnalyseResults_AllPass_NoneFailed() { // Arrange Dictionary <string, AsafaResult> results = new Dictionary <string, AsafaResult> { { "Key1", AsafaResult.Pass }, { "Key2", AsafaResult.Pass }, { "Key3", AsafaResult.Pass }, { "Key4", AsafaResult.Pass }, { "Key5", AsafaResult.Pass }, }; StatusLogic logic = new StatusLogic(); // Act Dictionary <string, AsafaResult> updatedResults = logic.AnalyseResults(results); // Assert Assert.That(updatedResults.Count, Is.EqualTo(0)); }