public void AnalyzeCommandBase_GetFileNameFromUriWorks() { var sb = new StringBuilder(); var testCases = new Tuple <string, string>[] { new Tuple <string, string>(null, null), new Tuple <string, string>("file.txt", "file.txt"), new Tuple <string, string>(@".\file.txt", "file.txt"), new Tuple <string, string>(@"c:\directory\file.txt", "file.txt"), new Tuple <string, string>(@"\\computer\computer\file.txt", "file.txt"), new Tuple <string, string>("file://directory/file.txt", "file.txt"), new Tuple <string, string>("/file.txt", "file.txt"), new Tuple <string, string>("directory/file.txt", "file.txt"), }; foreach (Tuple <string, string> testCase in testCases) { Uri uri = testCase.Item1 != null ? new Uri(testCase.Item1, UriKind.RelativeOrAbsolute) : null; string expectedFileName = testCase.Item2; string actualFileName = AnalyzeCommandBase <TestAnalysisContext, AnalyzeOptionsBase> .GetFileNameFromUri(uri); if (!object.Equals(actualFileName, expectedFileName)) { sb.AppendFormat("Incorrect file name returned for uri '{0}'. Expected '{1}' but saw '{2}'.", uri, expectedFileName, actualFileName).AppendLine(); } } sb.Length.Should().Be(0, because: "all URI to file name conversions should succeed but the following cases failed." + Environment.NewLine + sb.ToString()); }
public void AnalyzeCommandBase_UpdateLocationsAndMessageWithCurrentUri() { Uri uri = new Uri(@"c:\directory\test.txt", UriKind.RelativeOrAbsolute); Notification actualNotification = BuildTestNotification(uri); Uri updatedUri = new Uri(@"c:\updated\directory\newFileName.txt", UriKind.RelativeOrAbsolute); Notification expectedNotification = BuildTestNotification(updatedUri); AnalyzeCommandBase <TestAnalysisContext, AnalyzeOptionsBase> .UpdateLocationsAndMessageWithCurrentUri(actualNotification.Locations, actualNotification.Message, updatedUri); actualNotification.Should().BeEquivalentTo(expectedNotification); }
public void ConvertAnalyzeOptionsToLoggingOptions() { LoggingOptions loggingOptions; var analyzeOptions = new TestAnalyzeOptions() { ComputeFileHashes = true }; loggingOptions = AnalyzeCommandBase <TestAnalysisContext, TestAnalyzeOptions> .ConvertAnalyzeOptionsToLoggingOption(analyzeOptions); loggingOptions.Should().Be(LoggingOptions.ComputeFileHashes); analyzeOptions = new TestAnalyzeOptions() { LogEnvironment = true }; loggingOptions = AnalyzeCommandBase <TestAnalysisContext, TestAnalyzeOptions> .ConvertAnalyzeOptionsToLoggingOption(analyzeOptions); loggingOptions.Should().Be(LoggingOptions.PersistEnvironment); analyzeOptions = new TestAnalyzeOptions() { PersistFileContents = true }; loggingOptions = AnalyzeCommandBase <TestAnalysisContext, TestAnalyzeOptions> .ConvertAnalyzeOptionsToLoggingOption(analyzeOptions); loggingOptions.Should().Be(LoggingOptions.PersistFileContents); analyzeOptions = new TestAnalyzeOptions() { Verbose = true }; loggingOptions = AnalyzeCommandBase <TestAnalysisContext, TestAnalyzeOptions> .ConvertAnalyzeOptionsToLoggingOption(analyzeOptions); loggingOptions.Should().Be(LoggingOptions.Verbose); }