public void RulesPluginBuilder_RulesFileValidation()
        {
            // Arrange
            MockJdkWrapper     mockJdkWrapper = new MockJdkWrapper();
            RulesPluginBuilder builder        = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger());

            SetValidCoreProperties(builder);
            builder.SetLanguage("aLanguage");

            // 1. Rules file not specified -> error
            AssertException.Expect <InvalidOperationException>(() => builder.Build());

            // 2. Non-existent rules file specified -> error
            string testDir   = TestUtils.EnsureTestDirectoryExists(this.TestContext);
            string rulesFile = Path.Combine(testDir, "missingFile.txt");

            mockJdkWrapper.AssertCodeNotCompiled();

            builder.SetRulesFilePath(rulesFile);
            FileNotFoundException ex = AssertException.Expect <FileNotFoundException>(() => builder.Build());

            Assert.AreEqual(ex.FileName, rulesFile);
            mockJdkWrapper.AssertCodeNotCompiled();

            // 3. Rules file exists -> succeeds
            AddValidDummyRulesFiles(builder);
            builder.Build(); // should succeed
            mockJdkWrapper.AssertJarBuilt();
        }
        public void RulesPluginBuilder_SqaleFileValidation()
        {
            // Arrange
            string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext);

            MockJdkWrapper     mockJdkWrapper = new MockJdkWrapper();
            RulesPluginBuilder builder        = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger());

            SetValidCoreProperties(builder);
            builder.SetLanguage("aLanguage");
            AddValidDummyRulesFiles(builder);

            // 1. Sqale file not specified -> ok
            builder.Build();

            // 2. Non-existent Sqale file specified -> error
            mockJdkWrapper.ClearCalledMethodList();

            string sqaleFile = Path.Combine(testDir, "missingFile.txt");

            builder.SetSqaleFilePath(sqaleFile);
            FileNotFoundException ex = AssertException.Expect <FileNotFoundException>(() => builder.Build());

            Assert.AreEqual(ex.FileName, sqaleFile);
            mockJdkWrapper.AssertCodeNotCompiled();

            // 3. Sqale file exists -> succeeds
            sqaleFile = TestUtils.CreateTextFile("sqale.txt", testDir, "dummy sqale file");
            builder.SetSqaleFilePath(sqaleFile);
            builder.Build(); // should succeed
            mockJdkWrapper.AssertJarBuilt();
        }
        private void BuildAndCheckCompileFails(PluginBuilder builder, TestLogger logger)
        {
            AssertException.Expect <JavaCompilerException>(() => builder.Build());

            Assert.IsNotNull(builder.JarFilePath, "Expecting the jar file path to be set");
            TestUtils.AssertFileDoesNotExist(builder.JarFilePath);
            logger.AssertErrorsLogged();
        }
        public void RulesPluginBuilder_SqaleFileSetToNull_Fails()
        {
            // Arrange
            RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger());

            // Act and assert
            AssertException.Expect <ArgumentNullException>(() => builder.SetSqaleFilePath(null));
            AssertException.Expect <ArgumentNullException>(() => builder.SetSqaleFilePath(""));
        }
        public void PluginBuilder_PluginNameIsRequired()
        {
            // Arrange
            TestLogger    logger  = new TestLogger();
            PluginBuilder builder = CreateValidBuilder(logger);

            builder.SetProperty(WellKnownPluginProperties.PluginName, null);

            // Act and assert
            AssertException.Expect <System.InvalidOperationException>(() => builder.Build());
        }
        public void RulesPluginBuilder_LanguageIsRequired()
        {
            // Arrange
            RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger());

            SetValidCoreProperties(builder);
            AddValidDummyRulesFiles(builder);

            // Act and assert
            AssertException.Expect <InvalidOperationException>(() => builder.Build());
        }
        public void AssemblyResolver_Creation()
        {
            // 1. Null logger
            AssertException.Expect <ArgumentNullException>(() => new AssemblyResolver(null, new string[] { this.TestContext.TestDeploymentDir }));

            // 2. Null paths
            AssertException.Expect <ArgumentException>(() => new AssemblyResolver(new TestLogger(), null));

            // 3. Empty paths
            AssertException.Expect <ArgumentException>(() => new AssemblyResolver(new TestLogger(), new string[] { }));
        }
        public void ThrowIfNotSupported_Unrecognised_Throws()
        {
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported(""));
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("123"));
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("Visual Basic"));
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("CSharp"));

            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("Cs"));
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("CS"));
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("vB"));
            AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.ThrowIfNotSupported("VB"));
        }
Пример #9
0
        public void Manifest_NameTooLong_Throws()
        {
            // Arrange
            JarManifestBuilder builder = new JarManifestBuilder();

            string validName1  = "".PadLeft(69, 'A');
            string validName2  = "".PadLeft(70, 'A');
            string invalidName = "".PadLeft(71, 'A');

            // Act
            builder.SetProperty(validName1, "69 chars");
            builder.SetProperty(validName2, "70 chars");

            AssertException.Expect <ArgumentException>(() => builder.SetProperty(invalidName, "valid.property"));
        }
Пример #10
0
        public void Manifest_InvalidCharsInName_Throws()
        {
            // Arrange
            JarManifestBuilder builder = new JarManifestBuilder();

            string[] invalidNames =
            {
                "", // empty
                null,
                "%",
                "1234!",
                "a b",   // whitespace
                "1\r\n2" // more whitespace
            };

            // Act and assert
            foreach (string name in invalidNames)
            {
                AssertException.Expect <ArgumentException>(() => builder.SetProperty(name, "valid.property"));
            }
        }
        public void PluginBuilder_Extensions_Required()
        {
            string inputDir  = TestUtils.CreateTestDirectory(this.TestContext, "input");
            string outputDir = TestUtils.CreateTestDirectory(this.TestContext, "output");

            string pluginFilePath = Path.Combine(outputDir, "plugin1.jar");
            string source1        = TestUtils.CreateTextFile("Program.java", inputDir,
                                                             @"package myorg.app1;
public final class Program {}
");
            TestLogger    logger  = new TestLogger();
            PluginBuilder builder = new PluginBuilder(logger);

            builder
            .AddSourceFile(source1)
            .SetJarFilePath(pluginFilePath)
            .SetPluginKey("dummy.key")
            .SetPluginName("dummy name");

            //Act and assert
            AssertException.Expect <System.InvalidOperationException>(() => builder.Build());
        }
Пример #12
0
 private static void CheckGetValidKeyThrows(string input)
 {
     // Should throw on input that cannot be corrected
     AssertException.Expect <ArgumentException>(() => RepositoryKeyUtilities.GetValidKey(input));
 }
Пример #13
0
 private static void CheckThrowIfInvalidThrows(string input)
 {
     AssertException.Expect <ArgumentException>(() => RepositoryKeyUtilities.ThrowIfInvalid(input));
 }
 public void GetRoslynName_Unrecognised_Throws()
 {
     AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.GetRoslynLanguageName("foo"));
     AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.GetRoslynLanguageName("CS")); // case-sensitive
     AssertException.Expect <ArgumentOutOfRangeException>(() => SupportedLanguages.GetRoslynLanguageName("VB")); // case-sensitive
 }
 private static void AssertAssemblyLoadFails(string asmRef)
 {
     AssertException.Expect <FileNotFoundException>(() => Assembly.Load(asmRef));
 }