コード例 #1
0
        public void ActivatePlugins_ThrowErrors_ShouldCatch_ShouldReport()
        {
            // arrange
            var path            = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"UnitTests/PluginHandler/tsqllint-plugin-throws-exception.dll"));
            var assemblyWrapper = new AssemblyWrapper();

            var pluginPaths = new Dictionary <string, string>
            {
                {
                    "my-plugin", path
                }
            };

            var reporter       = Substitute.For <IReporter>();
            var versionWrapper = Substitute.For <IFileversionWrapper>();
            var context        = Substitute.For <IPluginContext>();

            versionWrapper.GetVersion(Arg.Any <Assembly>()).Returns("1.2.3");

            // act
            var pluginHandler = new Infrastructure.Plugins.PluginHandler(reporter, new FileSystem(), assemblyWrapper, versionWrapper);

            pluginHandler.ProcessPaths(pluginPaths);
            pluginHandler.ActivatePlugins(context);

            // assert
            Assert.AreEqual(1, pluginHandler.Plugins.Count);
            reporter.Received().Report(@"There was a problem with plugin: tsqllint_plugin_throws_exception.PluginThatThrows - something bad happened");
        }
コード例 #2
0
        public void ActivatePlugins_PluginRuleViolations_ShouldCallReporter()
        {
            // arrange
            var filePath1  = TestHelper.GetTestFilePath(@"c:\pluginDirectory\plugin_one.dll");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                {
                    filePath1, new MockFileData(string.Empty)
                }
            });

            var assemblyWrapper = new TestAssemblyWrapper();

            var pluginPaths = new Dictionary <string, string>
            {
                {
                    "my-plugin", filePath1
                }
            };

            var reporter   = Substitute.For <IReporter>();
            var textReader = ParsingUtility.CreateTextReaderFromString("\tSELECT * FROM FOO");

            var scriptPath = TestHelper.GetTestFilePath(@"c:\scripts\foo.sql");
            var context    = new PluginContext(scriptPath, new List <IRuleException>(), textReader);

            var versionWrapper = Substitute.For <IFileversionWrapper>();

            versionWrapper.GetVersion(Arg.Any <Assembly>()).Returns("1.2.3");

            // act
            var pluginHandler = new Infrastructure.Plugins.PluginHandler(reporter, fileSystem, assemblyWrapper, versionWrapper);

            pluginHandler.ProcessPaths(pluginPaths);

            // assert
            Assert.AreEqual(1, pluginHandler.Plugins.Count);
            Assert.DoesNotThrow(() => pluginHandler.ActivatePlugins(context));

            reporter.Received().ReportViolation(Arg.Is <IRuleViolation>(x =>
                                                                        x.FileName == context.FilePath &&
                                                                        x.RuleName == "prefer-tabs" &&
                                                                        x.Text == "Should use spaces rather than tabs" &&
                                                                        x.Line == 1 &&
                                                                        x.Column == 0 &&
                                                                        x.Severity == RuleViolationSeverity.Warning));
        }