public void Should_Not_Throw_When_Passed_NonExistant_Path() { const string filePath1 = @"c:\dbscripts\db1\file2.sql"; const string filePath2 = @"c:\dbscripts\db1\file3.sql"; const string invalidFilePath = @"c:\invalid\invalid.sql"; var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IBaseReporter>(); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { filePath1, new MockFileData("File1SQL") }, { filePath2, new MockFileData("File2SQL") }, }); var processor = new SqlFileProcessor(ruleVisitor, reporter, fileSystem); processor.ProcessList(new List <string> { invalidFilePath, @"c:\dbscripts\db1\" }); ruleVisitor.DidNotReceive().VisitRules(invalidFilePath, Arg.Any <TextReader>()); ruleVisitor.Received().VisitRules(filePath1, Arg.Any <TextReader>()); ruleVisitor.Received().VisitRules(filePath2, Arg.Any <TextReader>()); reporter.Received().Report(@"Directory doest not exit: c:\invalid"); Assert.AreEqual(2, processor.GetFileCount()); }
public void ProcessList_InvalidPaths_ShouldProcessValidPaths() { // arrange const string filePath1 = @"c:\dbscripts\db1\file2.sql"; const string filePath2 = @"c:\dbscripts\db1\file3.sql"; const string invalidFilePath = @"c:\invalid\invalid.sql"; var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IReporter>(); var pluginHandler = Substitute.For <IPluginHandler>(); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { filePath1, new MockFileData("File1SQL") }, { filePath2, new MockFileData("File2SQL") } }); var processor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, fileSystem); // act processor.ProcessList(new List <string> { invalidFilePath, @"c:\dbscripts\db1\" }); // assert ruleVisitor.DidNotReceive().VisitRules(invalidFilePath, Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath1, Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath2, Arg.Any <Stream>()); reporter.Received().Report($@"{invalidFilePath} is not a valid file path."); Assert.AreEqual(2, processor.FileCount); }
public void ProcessList_Processes_List_Of_Items() { const string filePath1 = @"c:\dbscripts\file1.SQL"; const string filePath2 = @"c:\dbscripts\db1\file2.sql"; const string filePath3 = @"c:\dbscripts\db2\file3.sql"; const string filePath4 = @"c:\dbscripts\db2\sproc\file4.Sql"; var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IBaseReporter>(); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { filePath1, new MockFileData("File1SQL") }, { filePath2, new MockFileData("File2SQL") }, { filePath3, new MockFileData("File3SQL") }, { filePath4, new MockFileData("File4SQL") } }); var processor = new SqlFileProcessor(ruleVisitor, reporter, fileSystem); // handles quotes, extra spaces, commas, multiple items in the list processor.ProcessList(new List <string> { "\" c:\\dbscripts\\db2\\sproc , c:\\dbscripts\\db2\\file3.sql \"", @"c:\dbscripts\db1\" }); ruleVisitor.DidNotReceive().VisitRules(filePath1, Arg.Any <TextReader>()); ruleVisitor.Received().VisitRules(filePath2, Arg.Any <TextReader>()); ruleVisitor.Received().VisitRules(filePath3, Arg.Any <TextReader>()); ruleVisitor.Received().VisitRules(filePath4, Arg.Any <TextReader>()); reporter.DidNotReceive().Report(Arg.Any <string>()); Assert.AreEqual(3, processor.GetFileCount()); }
public void ProcessList_Does_Not_Process_Any_Files_For_Empty_List() { var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IBaseReporter>(); var fileSystem = Substitute.For <IFileSystem>(); var processor = new SqlFileProcessor(ruleVisitor, reporter, fileSystem); processor.ProcessList(new List <string>()); ruleVisitor.DidNotReceive().VisitRules(Arg.Any <string>(), Arg.Any <TextReader>()); reporter.DidNotReceive().Report(Arg.Any <string>()); Assert.AreEqual(0, processor.GetFileCount()); }
public void ProcessList_ListOfPaths_ShouldOnlyProcessFilesInList() { // arrange var filePath1 = TestHelper.GetTestFilePath(@"c:\dbscripts\file1.SQL"); var filePath2 = TestHelper.GetTestFilePath(@"c:\dbscripts\db1\file2.sql"); var filePath3 = TestHelper.GetTestFilePath(@"c:\dbscripts\db2\file3.sql"); var filePath4 = TestHelper.GetTestFilePath(@"c:\dbscripts\db2\sproc\file4.Sql"); var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IReporter>(); var pluginHandler = Substitute.For <IPluginHandler>(); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { filePath1, new MockFileData("File1SQL") }, { filePath2, new MockFileData("File2SQL") }, { filePath3, new MockFileData("File3SQL") }, { filePath4, new MockFileData("File4SQL") } }); var processor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, fileSystem); var f1 = TestHelper.GetTestFilePath(@"c:\dbscripts\db2\sproc"); var f2 = TestHelper.GetTestFilePath(@"c:\dbscripts\db2\file3.sql"); var multiPathString = $@" {f1}, {f2}"; // act // tests quotes, extra spaces, commas, multiple items in the list processor.ProcessList(new List <string> { multiPathString, TestHelper.GetTestFilePath(@"c:\dbscripts\db1\") }); // assert ruleVisitor.DidNotReceive().VisitRules(filePath1, Arg.Any <IEnumerable <IExtendedRuleException> >(), Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath2, Arg.Any <IEnumerable <IExtendedRuleException> >(), Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath3, Arg.Any <IEnumerable <IExtendedRuleException> >(), Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath4, Arg.Any <IEnumerable <IExtendedRuleException> >(), Arg.Any <Stream>()); Assert.AreEqual(3, processor.FileCount); }
public void ProcessList_EmptyList_ShouldNotProcess() { // arrange var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IReporter>(); var fileSystem = Substitute.For <IFileSystem>(); var pluginHandler = Substitute.For <IPluginHandler>(); var processor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, fileSystem); // act processor.ProcessList(new List <string>()); // assert ruleVisitor.DidNotReceive().VisitRules(Arg.Any <string>(), Arg.Any <Stream>()); Assert.AreEqual(0, processor.FileCount); }
public void ProcessList_ListOfPaths_ShouldOnlyProcessFilesInList() { // arrange const string filePath1 = @"c:\dbscripts\file1.SQL"; const string filePath2 = @"c:\dbscripts\db1\file2.sql"; const string filePath3 = @"c:\dbscripts\db2\file3.sql"; const string filePath4 = @"c:\dbscripts\db2\sproc\file4.Sql"; var ruleVisitor = Substitute.For <IRuleVisitor>(); var reporter = Substitute.For <IReporter>(); var pluginHandler = Substitute.For <IPluginHandler>(); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { filePath1, new MockFileData("File1SQL") }, { filePath2, new MockFileData("File2SQL") }, { filePath3, new MockFileData("File3SQL") }, { filePath4, new MockFileData("File4SQL") } }); var processor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, fileSystem); // act processor.ProcessList(new List <string> { "\" c:\\dbscripts\\db2\\sproc , c:\\dbscripts\\db2\\file3.sql \"", @"c:\dbscripts\db1\" }); // tests quotes, extra spaces, commas, multiple items in the list // assert ruleVisitor.DidNotReceive().VisitRules(filePath1, Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath2, Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath3, Arg.Any <Stream>()); ruleVisitor.Received().VisitRules(filePath4, Arg.Any <Stream>()); Assert.AreEqual(3, processor.FileCount); }
public void Lint() { Parser.ProcessList(CommandLineOptions.LintPath); RuleViolations = RuleVisitor.Violations; LintedFileCount = Parser.GetFileCount(); }