Esempio n. 1
0
        private IServiceProvider CreateServiceProvider(TestProgrammingPlatform generator, bool scriptOnly)
        {
            var sourceCodeFolder = Path.Combine(_testDirPath, "src");

            Directory.CreateDirectory(sourceCodeFolder);
            var outputFolder = Path.Combine(_testDirPath, "output");

            Directory.CreateDirectory(outputFolder);
            var servicesBuilder = new ServiceProviderBuilder()
                                  .ConfigureServices(services =>
            {
                // Add 'test' script generator here as we can control what the script output is rather
                // than depending on in-built script generators whose script could change overtime causing
                // this test to be difficult to manage.
                services.RemoveAll <ILanguageDetector>();
                services.TryAddEnumerable(
                    ServiceDescriptor.Singleton <ILanguageDetector>(
                        new TestLanguageDetectorUsingLangName(
                            detectedLanguageName: "test",
                            detectedLanguageVersion: "1.0.0")));
                services.RemoveAll <IProgrammingPlatform>();
                services.TryAddEnumerable(
                    ServiceDescriptor.Singleton <IProgrammingPlatform>(generator));
                services.AddSingleton <ITempDirectoryProvider>(
                    new TestTempDirectoryProvider(Path.Combine(_testDirPath, "temp")));
            })
                                  .ConfigureScriptGenerationOptions(o =>
            {
                o.SourceDir      = sourceCodeFolder;
                o.DestinationDir = outputFolder;
                o.ScriptOnly     = scriptOnly;
            });

            return(servicesBuilder.Build());
        }
        public void TryParseReturnsResolvedVersions_WhenInputIsFromFile()
        {
            // Arrange
            var newLine = Environment.NewLine;
            var versionsToBeInstalledFile = Path.Combine(_tempDirRootPath, "input.txt");

            File.WriteAllText(versionsToBeInstalledFile, $"p1=2.1.3{newLine}p2=3.1.3{newLine}");
            var p1 = new TestProgrammingPlatform(
                name: "p1",
                detectedVersion: "1.0.0",
                resolvedVersion: "2.1.3");
            var p2 = new TestProgrammingPlatform(
                name: "p2",
                detectedVersion: "1.0.0",
                resolvedVersion: "3.1.3");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1, p2 },
                suppliedPlatformsAndVersions: null,
                suppliedPlatformsAndVersionsFile: versionsToBeInstalledFile,
                new TestConsole(),
                out var results);

            // Assert
            Assert.True(actual);
            Assert.NotNull(results);
            Assert.Equal(2, results.Count);
            Assert.Equal("p1", results[0].Platform);
            Assert.Equal("2.1.3", results[0].PlatformVersion);
            Assert.Equal("p2", results[1].Platform);
            Assert.Equal("3.1.3", results[1].PlatformVersion);
        }
        public void TryParseReturns_DoesCaseInsensitiveComparisonOfPlatformName()
        {
            // Arrange
            var suppliedPlatformsAndVersions = "PlatForm1=3.2.2, PLATFORM2=3.1.2";
            var p1 = new TestProgrammingPlatform(
                name: "platform1",
                resolvedVersion: "3.2.2");
            var p2 = new TestProgrammingPlatform(
                name: "platform2",
                resolvedVersion: "3.1.2");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1, p2 },
                suppliedPlatformsAndVersions,
                suppliedPlatformsAndVersionsFile: null,
                new TestConsole(),
                out var results);

            // Assert
            Assert.True(actual);
            Assert.NotNull(results);
            Assert.Equal(2, results.Count);
            Assert.Equal("platform1", results[0].Platform);
            Assert.Equal("3.2.2", results[0].PlatformVersion);
            Assert.Equal("platform2", results[1].Platform);
            Assert.Equal("3.1.2", results[1].PlatformVersion);
        }
        public void TryParseReturnsDefaultVersions_WhenNoVersionSetForMultiplePlatforms()
        {
            // Arrange
            var suppliedPlatformsAndVersions = "p1, p2";
            var p1 = new TestProgrammingPlatform(
                name: "p1",
                resolvedVersion: "2.1.3");
            var p2 = new TestProgrammingPlatform(
                name: "p2",
                resolvedVersion: "3.1.3");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1, p2 },
                suppliedPlatformsAndVersions,
                suppliedPlatformsAndVersionsFile: null,
                new TestConsole(),
                out var results);

            // Assert
            Assert.True(actual);
            Assert.NotNull(results);
            Assert.Equal(2, results.Count);
            Assert.Equal("p1", results[0].Platform);
            Assert.Equal("2.1.3", results[0].PlatformVersion);
            Assert.Equal("p2", results[1].Platform);
            Assert.Equal("3.1.3", results[1].PlatformVersion);
        }
Esempio n. 5
0
        public void TryParseReturns_ReturnsFalseWhenPlatformNameIsNotValidAndInputIsFromFile()
        {
            // Arrange
            var newLine = Environment.NewLine;
            var versionsToBeInstalledFile = Path.Combine(_tempDirRootPath, "input.txt");

            File.WriteAllText(
                versionsToBeInstalledFile,
                $"foo=3.2.2{newLine}p1=3.1.2");
            var p1 = new TestProgrammingPlatform(
                name: "p1",
                resolvedVersion: "2.1.3");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1 },
                suppliedPlatformsAndVersions: null,
                suppliedPlatformsAndVersionsFile: versionsToBeInstalledFile,
                new TestConsole(),
                GetContext(),
                out var results);

            // Assert
            Assert.False(actual);
        }
        public void TryParseReturnsFalse_IfSuppliedFileDoesNotExist()
        {
            // Arrange
            var versionsToBeInstalledFile = Path.Combine(_tempDirRootPath, "doestNotExist.txt");
            var p1 = new TestProgrammingPlatform(
                name: "p1",
                resolvedVersion: "2.1.3");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1 },
                suppliedPlatformsAndVersions: null,
                suppliedPlatformsAndVersionsFile: versionsToBeInstalledFile,
                new TestConsole(),
                out var results);

            // Assert
            Assert.False(actual);
        }
        public void TryParseReturns_ReturnsFalseWhenPlatformNameIsNotValid()
        {
            // Arrange
            var suppliedPlatformsAndVersions = "foo=3.2.2, p1=3.1.2";
            var p1 = new TestProgrammingPlatform(
                name: "p1",
                resolvedVersion: "2.1.3");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1 },
                suppliedPlatformsAndVersions,
                suppliedPlatformsAndVersionsFile: null,
                new TestConsole(),
                out var results);

            // Assert
            Assert.False(actual);
        }
        public void TryParseReturnsFalseWhenNoInputsAreProvided()
        {
            // Arrange
            var p1 = new TestProgrammingPlatform(
                name: "p1",
                detectedVersion: "1.0.0",
                resolvedVersion: "2.1.3");
            var p2 = new TestProgrammingPlatform(
                name: "p2",
                detectedVersion: "1.0.0",
                resolvedVersion: "3.1.3");

            // Act
            var actual = PrepareEnvironmentCommand.TryValidateSuppliedPlatformsAndVersions(
                new[] { p1, p2 },
                suppliedPlatformsAndVersions: null,
                suppliedPlatformsAndVersionsFile: null,
                new TestConsole(),
                out var results);

            // Assert
            Assert.False(actual);
        }