Example #1
0
        internal async Task Create_TemplateWithBinaryFile_Package()
        {
            Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string packageLocation = _packageManager.PackTestTemplatesNuGetPackage();
            await bootstrapper.InstallTemplateAsync(packageLocation).ConfigureAwait(false);

            string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithBinaryFile");

            string output = TestUtils.CreateTemporaryFolder();

            var foundTemplates = await bootstrapper.GetTemplatesAsync(new[] { WellKnownSearchFilters.NameFilter("TestAssets.TemplateWithBinaryFile") }).ConfigureAwait(false);

            var result = await bootstrapper.CreateAsync(foundTemplates[0].Info, "my-test-folder", output, new Dictionary <string, string>()).ConfigureAwait(false);

            string sourceImage = Path.Combine(templateLocation, "image.png");
            string targetImage = Path.Combine(output, "image.png");

            Assert.True(File.Exists(targetImage));

            Assert.Equal(
                new FileInfo(sourceImage).Length,
                new FileInfo(targetImage).Length);
            Assert.True(TestUtils.CompareFiles(sourceImage, targetImage), $"The content of {sourceImage} and {targetImage} is not same.");
        }
Example #2
0
        internal async Task GetCreationEffects_BasicTest_Package()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string packageLocation = await _packageManager.GetNuGetPackage("Microsoft.DotNet.Common.ProjectTemplates.5.0").ConfigureAwait(false);

            await bootstrapper.InstallTemplateAsync(packageLocation).ConfigureAwait(false);

            string output = TestUtils.CreateTemporaryFolder();

            var foundTemplates = await bootstrapper.GetTemplatesAsync(new[] { WellKnownSearchFilters.NameFilter("console") }).ConfigureAwait(false);

            var result = await bootstrapper.GetCreationEffectsAsync(foundTemplates[0].Info, "test", output, new Dictionary <string, string>(), "").ConfigureAwait(false);

            Assert.Equal(2, result.CreationResult.PrimaryOutputs.Count);
            Assert.Equal(2, result.CreationResult.PostActions.Count);
            Assert.Equal(2, result.FileChanges.Count);

            var expectedFileChanges = new FileChange[]
            {
                new FileChange("Company.ConsoleApplication1.csproj", "test.csproj", ChangeKind.Create),
                new FileChange("Program.cs", "Program.cs", ChangeKind.Create),
            };
            IFileChangeComparer comparer = new IFileChangeComparer();

            Assert.Equal(
                expectedFileChanges.OrderBy(s => s, comparer),
                result.FileChanges.OrderBy(s => s, comparer),
                comparer);
        }
Example #3
0
        internal async Task GetCreationEffects_BasicTest_Package()
        {
            var    bootstrapper    = BootstrapperFactory.GetBootstrapper();
            string packageLocation = _packageManager.PackProjectTemplatesNuGetPackage("microsoft.dotnet.common.projecttemplates.5.0");

            bootstrapper.InstallTemplate(packageLocation);

            string output   = TestHelper.CreateTemporaryFolder();
            var    template = bootstrapper.ListTemplates(true, WellKnownSearchFilters.NameFilter("console"));
            var    result   = await bootstrapper.GetCreationEffectsAsync(template.First().Info, "test", output, new Dictionary <string, string>(), "").ConfigureAwait(false);

            Assert.Equal(2, result.CreationResult.PrimaryOutputs.Count);
            Assert.Equal(2, result.CreationResult.PostActions.Count);
            Assert.Equal(2, result.FileChanges.Count);

            var expectedFileChanges = new FileChange[]
            {
                new FileChange("Company.ConsoleApplication1.csproj", "test.csproj", ChangeKind.Create),
                new FileChange("Program.cs", "Program.cs", ChangeKind.Create),
            };
            IFileChangeComparer comparer = new IFileChangeComparer();

            Assert.Equal(
                expectedFileChanges.OrderBy(s => s, comparer),
                result.FileChanges.OrderBy(s => s, comparer),
                comparer);
        }
Example #4
0
        internal async Task CanReInstallFolder_WhenForceIsSpecified()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithSourceName");

            InstallRequest installRequest = new InstallRequest(Path.GetFullPath(templateLocation));

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            result[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(installRequest, result[0].InstallRequest);

            InstallRequest repeatedInstallRequest = new InstallRequest(Path.GetFullPath(templateLocation), force: true);

            result = await bootstrapper.InstallTemplatePackagesAsync(new[] { repeatedInstallRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            result[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(repeatedInstallRequest, result[0].InstallRequest);

            InstallRequest repeatedInstallRequestWithoutForce = new InstallRequest(Path.GetFullPath(templateLocation));

            result = await bootstrapper.InstallTemplatePackagesAsync(new[] { repeatedInstallRequestWithoutForce }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.False(result[0].Success);
            Assert.Equal(InstallerErrorCode.AlreadyInstalled, result[0].Error);
        }
Example #5
0
        internal async Task CanReInstallRemotePackage_WhenForceIsSpecified()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            InstallRequest installRequest = new InstallRequest("Microsoft.DotNet.Common.ProjectTemplates.5.0", version: "5.0.0");

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            Assert.True(string.IsNullOrEmpty(result[0].ErrorMessage));
            Assert.Equal(installRequest, result[0].InstallRequest);

            InstallRequest repeatedInstallRequest = new InstallRequest("Microsoft.DotNet.Common.ProjectTemplates.5.0", version: "5.0.0", force: true);

            result = await bootstrapper.InstallTemplatePackagesAsync(new[] { repeatedInstallRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            result[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(repeatedInstallRequest, result[0].InstallRequest);

            InstallRequest repeatedInstallRequestWithoutForce = new InstallRequest("Microsoft.DotNet.Common.ProjectTemplates.5.0", version: "5.0.0");

            result = await bootstrapper.InstallTemplatePackagesAsync(new[] { repeatedInstallRequestWithoutForce }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.False(result[0].Success);
            Assert.Equal(InstallerErrorCode.AlreadyInstalled, result[0].Error);
        }
        internal async Task GetCreationEffectsTest_Package(string templateName, string parameters, MockCreationEffects expectedResult)
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string packageLocation = _packageManager.PackTestTemplatesNuGetPackage();
            await bootstrapper.InstallTemplateAsync(packageLocation).ConfigureAwait(false);

            string name   = BasicParametersParser.GetNameFromParameterString(parameters);
            string output = BasicParametersParser.GetOutputFromParameterString(parameters);
            Dictionary <string, string> parametersDict = BasicParametersParser.ParseParameterString(parameters);

            var foundTemplates = await bootstrapper.GetTemplatesAsync(new[] { WellKnownSearchFilters.NameFilter(templateName) }).ConfigureAwait(false);

            ITemplateInfo    template = foundTemplates.Single(template => template.Info.ShortNameList.Contains($"TestAssets.{templateName}")).Info;
            ICreationEffects result   = await bootstrapper.GetCreationEffectsAsync(template, name, output, parametersDict, "").ConfigureAwait(false);

            Assert.Equal(expectedResult.CreationResult.PrimaryOutputs.Count, result.CreationResult.PrimaryOutputs.Count);
            Assert.Equal(
                expectedResult.CreationResult.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                result.CreationResult.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                StringComparer.OrdinalIgnoreCase);

            IFileChangeComparer comparer = new IFileChangeComparer();

            Assert.Equal(expectedResult.FileChanges.Count, result.FileChanges.Count);
            Assert.Equal(
                expectedResult.FileChanges.OrderBy(s => s, comparer),
                result.FileChanges.OrderBy(s => s, comparer),
                comparer);
        }
        internal async Task CanInstall_LocalNuGetPackage()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string packageLocation = await _packageManager.GetNuGetPackage("Microsoft.DotNet.Common.ProjectTemplates.5.0").ConfigureAwait(false);

            InstallRequest installRequest = new InstallRequest(Path.GetFullPath(packageLocation));

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            result[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(installRequest, result[0].InstallRequest);

            IManagedTemplatePackage source = result[0].TemplatePackage;

            Assert.Equal("Microsoft.DotNet.Common.ProjectTemplates.5.0", source.Identifier);
            Assert.Equal("Global Settings", source.Provider.Factory.DisplayName);
            Assert.Equal("NuGet", source.Installer.Factory.Name);
            Assert.Equal("Microsoft", source.GetDetails()["Author"]);
            source.Version.Should().NotBeNullOrEmpty();

            IReadOnlyList <IManagedTemplatePackage> managedTemplatesPackages = await bootstrapper.GetManagedTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, managedTemplatesPackages.Count);
            managedTemplatesPackages[0].Should().BeEquivalentTo(source);

            IReadOnlyList <ITemplatePackage> templatePackages = await bootstrapper.GetTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, templatePackages.Count);
            Assert.IsAssignableFrom <IManagedTemplatePackage>(templatePackages[0]);
            templatePackages[0].Should().BeEquivalentTo((ITemplatePackage)source);
        }
        internal async Task CanUninstall_Folder()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithSourceName");

            InstallRequest installRequest = new InstallRequest(Path.GetFullPath(templateLocation));

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            IManagedTemplatePackage source = result[0].TemplatePackage;

            Assert.Equal(templateLocation, source.MountPointUri);

            IReadOnlyList <IManagedTemplatePackage> managedTemplatesPackages = await bootstrapper.GetManagedTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, managedTemplatesPackages.Count);
            managedTemplatesPackages[0].Should().BeEquivalentTo(source);

            IReadOnlyList <UninstallResult> uninstallResults = await bootstrapper.UninstallTemplatePackagesAsync(new[] { source }, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, uninstallResults.Count);
            Assert.True(uninstallResults[0].Success);
            Assert.Equal(InstallerErrorCode.Success, uninstallResults[0].Error);
            uninstallResults[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(source, uninstallResults[0].TemplatePackage);

            IReadOnlyList <ITemplatePackage> templatePackages = await bootstrapper.GetTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(0, templatePackages.Count);

            Directory.Exists(templateLocation);
        }
Example #9
0
        internal async Task GetCreationEffects_BasicTest_Folder()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            await bootstrapper.InstallTestTemplateAsync("TemplateWithSourceName").ConfigureAwait(false);

            string output         = TestUtils.CreateTemporaryFolder();
            var    foundTemplates = await bootstrapper.GetTemplatesAsync(
                new[] { WellKnownSearchFilters.NameFilter("TestAssets.TemplateWithSourceName") }).ConfigureAwait(false);

            var result = await bootstrapper.GetCreationEffectsAsync(foundTemplates[0].Info, "test", output, new Dictionary <string, string>(), "").ConfigureAwait(false);

            Assert.Equal(2, result.CreationResult.PrimaryOutputs.Count);
            Assert.Equal(0, result.CreationResult.PostActions.Count);
            Assert.Equal(2, result.FileChanges.Count);

            var expectedFileChanges = new FileChange[]
            {
                new FileChange("bar.cs", "test.cs", ChangeKind.Create),
                new FileChange("bar/bar.cs", "test/test.cs", ChangeKind.Create),
            };
            IFileChangeComparer comparer = new IFileChangeComparer();

            Assert.Equal(
                expectedFileChanges.OrderBy(s => s, comparer),
                result.FileChanges.OrderBy(s => s, comparer),
                comparer);
        }
        internal async Task CanUninstall_NuGetPackage()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            InstallRequest installRequest = new InstallRequest("Microsoft.DotNet.Common.ProjectTemplates.5.0", "5.0.0");

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            IManagedTemplatePackage source = result[0].TemplatePackage;

            IReadOnlyList <IManagedTemplatePackage> managedTemplatesPackages = await bootstrapper.GetManagedTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, managedTemplatesPackages.Count);
            managedTemplatesPackages[0].Should().BeEquivalentTo(source);

            IReadOnlyList <UninstallResult> uninstallResults = await bootstrapper.UninstallTemplatePackagesAsync(new[] { source }, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, uninstallResults.Count);
            Assert.True(uninstallResults[0].Success);
            Assert.Equal(InstallerErrorCode.Success, uninstallResults[0].Error);
            uninstallResults[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(source, uninstallResults[0].TemplatePackage);

            IReadOnlyList <ITemplatePackage> templatePackages = await bootstrapper.GetTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(0, templatePackages.Count);
        }
Example #11
0
        public override bool Execute()
        {
            try
            {
                var bootstrapFileType = ParseFileType(FileType);

                Log.LogMessage(MessageImportance.Normal, $"{LogPrefix}Reading content of {bootstrapFileType} file '{FilePath}'");
                var fileLines    = File.ReadAllLines(FilePath).ToList();
                var bootstrapper = BootstrapperFactory.GetBootstrapper(bootstrapFileType);

                if (bootstrapper.Bootstrap(fileLines))
                {
                    File.WriteAllLines(FilePath, fileLines);
                    Log.LogMessage(MessageImportance.Normal, $"{LogPrefix}Bootstrapping completed for {bootstrapFileType} file '{FilePath}'");
                }
                else
                {
                    Log.LogMessage(MessageImportance.Normal, $"{LogPrefix}Bootstrapping skipped for {bootstrapFileType} file '{FilePath}'");
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.LogError($"{LogPrefix}An unexpected error occured when bootstrapping file '{FilePath}'");
                Log.LogErrorFromException(ex);
                return(false);
            }
        }
Example #12
0
        internal async Task GetCreationEffectsTest(string templateName, string parameters, MockCreationEffects expectedResult)
        {
            Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();

            bootstrapper.InstallTestTemplate(templateName);

            string name   = BasicParametersParser.GetNameFromParameterString(parameters);
            string output = BasicParametersParser.GetOutputFromParameterString(parameters);
            Dictionary <string, string> parametersDict = BasicParametersParser.ParseParameterString(parameters);


            ITemplateInfo    template = bootstrapper.ListTemplates(true, WellKnownSearchFilters.NameFilter(templateName)).First().Info;
            ICreationEffects result   = await bootstrapper.GetCreationEffectsAsync(template, name, output, parametersDict, "").ConfigureAwait(false);

            Assert.Equal(expectedResult.CreationResult.PrimaryOutputs.Count, result.CreationResult.PrimaryOutputs.Count);
            Assert.Equal(
                expectedResult.CreationResult.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                result.CreationResult.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                StringComparer.OrdinalIgnoreCase);


            IFileChangeComparer comparer = new IFileChangeComparer();

            Assert.Equal(expectedResult.FileChanges.Count, result.FileChanges.Count);
            Assert.Equal(
                expectedResult.FileChanges.OrderBy(s => s, comparer),
                result.FileChanges.OrderBy(s => s, comparer),
                comparer);
        }
        internal async Task CanInstall_Folder()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithSourceName");

            InstallRequest installRequest = new InstallRequest(Path.GetFullPath(templateLocation));

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            result[0].ErrorMessage.Should().BeNullOrEmpty();
            Assert.Equal(installRequest, result[0].InstallRequest);

            IManagedTemplatePackage source = result[0].TemplatePackage;

            Assert.Equal(Path.GetFullPath(templateLocation), source.Identifier);
            Assert.Equal("Global Settings", source.Provider.Factory.DisplayName);
            Assert.Equal("Folder", source.Installer.Factory.Name);
            source.Version.Should().BeNullOrEmpty();

            IReadOnlyList <IManagedTemplatePackage> managedTemplatesPackages = await bootstrapper.GetManagedTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, managedTemplatesPackages.Count);
            managedTemplatesPackages[0].Should().BeEquivalentTo(source);

            IReadOnlyList <ITemplatePackage> templatePackages = await bootstrapper.GetTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, templatePackages.Count);
            Assert.IsAssignableFrom <IManagedTemplatePackage>(templatePackages[0]);
            templatePackages[0].Should().BeEquivalentTo((ITemplatePackage)source);
        }
Example #14
0
        internal async Task CreateBasicTest()
        {
            var bootstrapper = BootstrapperFactory.GetBootstrapper(additionalVirtualLocations: new string[] { "test" });

            bootstrapper.InstallTestTemplate("TemplateWithSourceName");
            var template = bootstrapper.ListTemplates(true, WellKnownSearchFilters.NameFilter("TestAssets.TemplateWithSourceName"));

            var result = await bootstrapper.CreateAsync(template.First().Info, "test", "test", new Dictionary <string, string>(), false, "").ConfigureAwait(false);

            Assert.Equal(2, result.PrimaryOutputs.Count);
            Assert.Equal(0, result.PostActions.Count);
        }
Example #15
0
        internal async Task Create_BasicTest_Folder()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper(additionalVirtualLocations: new string[] { "test" });
            await bootstrapper.InstallTestTemplateAsync("TemplateWithSourceName").ConfigureAwait(false);

            string output         = TestUtils.CreateTemporaryFolder();
            var    foundTemplates = await bootstrapper.GetTemplatesAsync(
                new[] { WellKnownSearchFilters.NameFilter("TestAssets.TemplateWithSourceName") }).ConfigureAwait(false);

            var result = await bootstrapper.CreateAsync(foundTemplates[0].Info, "test", output, new Dictionary <string, string>(), false, "").ConfigureAwait(false);

            Assert.Equal(2, result.PrimaryOutputs.Count);
            Assert.Equal(0, result.PostActions.Count);
            Assert.True(File.Exists(Path.Combine(output, "test.cs")));
            Assert.True(File.Exists(Path.Combine(output, "test/test.cs")));
        }
Example #16
0
        internal async Task GetCreationEffectsBasicTest()
        {
            var bootstrapper = BootstrapperFactory.GetBootstrapper();

            bootstrapper.InstallTestTemplate("TemplateWithSourceName");

            var template = bootstrapper.ListTemplates(true, WellKnownSearchFilters.NameFilter("TestAssets.TemplateWithSourceName"));
            var result   = await bootstrapper.GetCreationEffectsAsync(template.First().Info, "test", "test", new Dictionary <string, string>(), "").ConfigureAwait(false);

            Assert.Equal(2, result.CreationResult.PrimaryOutputs.Count);
            Assert.Equal(0, result.CreationResult.PostActions.Count);
            Assert.Equal(2, result.FileChanges.Count);

            Assert.Single(result.FileChanges.Where(change => change.ChangeKind == ChangeKind.Create && ((IFileChange2)change).SourceRelativePath == "bar.cs" && change.TargetRelativePath == "test.cs"));
            Assert.Single(result.FileChanges.Where(change => change.ChangeKind == ChangeKind.Create && ((IFileChange2)change).SourceRelativePath == "bar/bar.cs" && change.TargetRelativePath == "test/test.cs"));
        }
Example #17
0
        internal async Task Create_BasicTest_Package()
        {
            var    bootstrapper    = BootstrapperFactory.GetBootstrapper();
            string packageLocation = _packageManager.PackProjectTemplatesNuGetPackage("microsoft.dotnet.common.projecttemplates.5.0");

            bootstrapper.InstallTemplate(packageLocation);

            string output   = TestHelper.CreateTemporaryFolder();
            var    template = bootstrapper.ListTemplates(true, WellKnownSearchFilters.NameFilter("console"));
            var    result   = await bootstrapper.CreateAsync(template.First().Info, "test", output, new Dictionary <string, string>(), false, "").ConfigureAwait(false);

            Assert.Equal(2, result.PrimaryOutputs.Count);
            Assert.Equal(2, result.PostActions.Count);

            Assert.True(File.Exists(Path.Combine(output, "Program.cs")));
            Assert.True(File.Exists(Path.Combine(output, "test.csproj")));
        }
Example #18
0
        internal async Task Create_BasicTest_Package()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string packageLocation = await _packageManager.GetNuGetPackage("Microsoft.DotNet.Common.ProjectTemplates.5.0").ConfigureAwait(false);

            await bootstrapper.InstallTemplateAsync(packageLocation).ConfigureAwait(false);

            string output         = TestUtils.CreateTemporaryFolder();
            var    foundTemplates = await bootstrapper.GetTemplatesAsync(new[] { WellKnownSearchFilters.NameFilter("console") }).ConfigureAwait(false);

            var result = await bootstrapper.CreateAsync(foundTemplates[0].Info, "test", output, new Dictionary <string, string>(), false, "").ConfigureAwait(false);

            Assert.Equal(2, result.PrimaryOutputs.Count);
            Assert.Equal(2, result.PostActions.Count);

            Assert.True(File.Exists(Path.Combine(output, "Program.cs")));
            Assert.True(File.Exists(Path.Combine(output, "test.csproj")));
        }
        internal async Task CreateTest_Package(string templateName, string parameters, MockCreationEffects expectedResult)
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string packageLocation = _packageManager.PackTestTemplatesNuGetPackage();
            await bootstrapper.InstallTemplateAsync(packageLocation).ConfigureAwait(false);

            string name   = BasicParametersParser.GetNameFromParameterString(parameters);
            string output = BasicParametersParser.GetOutputFromParameterString(parameters);
            Dictionary <string, string> parametersDict = BasicParametersParser.ParseParameterString(parameters);

            var foundTemplates = await bootstrapper.GetTemplatesAsync(new[] { WellKnownSearchFilters.NameFilter(templateName) }).ConfigureAwait(false);

            ITemplateInfo template = foundTemplates.Single(template => template.Info.ShortNameList.Contains($"TestAssets.{templateName}")).Info;
            var           result   = await bootstrapper.CreateAsync(template, name, output, parametersDict, false, "").ConfigureAwait(false);

            Assert.Equal(expectedResult.CreationResult.PrimaryOutputs.Count, result.PrimaryOutputs.Count);
            Assert.Equal(
                expectedResult.CreationResult.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                result.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                StringComparer.OrdinalIgnoreCase);

            foreach (string file in expectedResult.FileChanges.Where(fc => fc.ChangeKind != ChangeKind.Delete).Select(fc => fc.TargetRelativePath))
            {
                string expectedFilePath = Path.Combine(output, file);
                Assert.True(File.Exists(expectedFilePath));
            }
            foreach (string file in expectedResult.FileChanges.Where(fc => fc.ChangeKind == ChangeKind.Delete).Select(fc => fc.TargetRelativePath))
            {
                string expectedFilePath = Path.Combine(output, file);
                Assert.False(File.Exists(expectedFilePath));
            }

            foreach (string file in expectedResult.AbsentFiles)
            {
                string expectedFilePath = Path.Combine(output, file);
                Assert.False(File.Exists(expectedFilePath));
            }

            foreach (string dir in expectedResult.AbsentDirectories)
            {
                string expectedPath = Path.Combine(output, dir);
                Assert.False(Directory.Exists(expectedPath));
            }
        }
Example #20
0
        internal async Task CreateTest(string templateName, string parameters, MockCreationEffects expectedResult)
        {
            Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();

            bootstrapper.InstallTestTemplate(templateName);

            string name   = BasicParametersParser.GetNameFromParameterString(parameters);
            string output = BasicParametersParser.GetOutputFromParameterString(parameters);
            Dictionary <string, string> parametersDict = BasicParametersParser.ParseParameterString(parameters);

            ITemplateInfo template = bootstrapper.ListTemplates(true, WellKnownSearchFilters.NameFilter(templateName)).First().Info;
            var           result   = await bootstrapper.CreateAsync(template, name, output, parametersDict, false, "").ConfigureAwait(false);

            Assert.Equal(expectedResult.CreationResult.PrimaryOutputs.Count, result.PrimaryOutputs.Count);
            Assert.Equal(
                expectedResult.CreationResult.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                result.PrimaryOutputs.Select(po => po.Path).OrderBy(s => s, StringComparer.OrdinalIgnoreCase),
                StringComparer.OrdinalIgnoreCase);

            foreach (string file in expectedResult.FileChanges.Where(fc => fc.ChangeKind != ChangeKind.Delete).Select(fc => fc.TargetRelativePath))
            {
                string expectedFilePath = Path.Combine(output, file);
                Assert.True(File.Exists(expectedFilePath));
            }
            foreach (string file in expectedResult.FileChanges.Where(fc => fc.ChangeKind == ChangeKind.Delete).Select(fc => fc.TargetRelativePath))
            {
                string expectedFilePath = Path.Combine(output, file);
                Assert.False(File.Exists(expectedFilePath));
            }

            foreach (string file in expectedResult.AbsentFiles)
            {
                string expectedFilePath = Path.Combine(output, file);
                Assert.False(File.Exists(expectedFilePath));
            }

            foreach (string dir in expectedResult.AbsentDirectories)
            {
                string expectedPath = Path.Combine(output, dir);
                Assert.False(Directory.Exists(expectedPath));
            }
        }
        internal async Task CanCheckForLatestVersion_NuGetPackage()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            InstallRequest installRequest = new InstallRequest("Microsoft.DotNet.Common.ProjectTemplates.5.0", "5.0.0");

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            IManagedTemplatePackage source = result[0].TemplatePackage;

            IReadOnlyList <CheckUpdateResult> checkUpdateResults = await bootstrapper.GetLatestVersionsAsync(new[] { source }, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, checkUpdateResults.Count);
            Assert.True(checkUpdateResults[0].Success);
            Assert.Equal(InstallerErrorCode.Success, checkUpdateResults[0].Error);
            Assert.True(string.IsNullOrEmpty(checkUpdateResults[0].ErrorMessage));
            Assert.Equal(source, checkUpdateResults[0].TemplatePackage);
            Assert.False(checkUpdateResults[0].IsLatestVersion);
            Assert.NotEqual("5.0.0", checkUpdateResults[0].LatestVersion);
        }
        internal async Task CanCheckForLatestVersion_Folder()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithSourceName");

            InstallRequest installRequest = new InstallRequest(Path.GetFullPath(templateLocation));

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            IManagedTemplatePackage source = result[0].TemplatePackage;

            IReadOnlyList <CheckUpdateResult> checkUpdateResults = await bootstrapper.GetLatestVersionsAsync(new[] { source }, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, checkUpdateResults.Count);
            Assert.True(checkUpdateResults[0].Success);
            Assert.Equal(InstallerErrorCode.Success, checkUpdateResults[0].Error);
            Assert.True(string.IsNullOrEmpty(checkUpdateResults[0].ErrorMessage));
            Assert.Equal(source, checkUpdateResults[0].TemplatePackage);
            Assert.True(checkUpdateResults[0].IsLatestVersion);
        }
        internal async Task CanInstall_RemoteNuGetPackage()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            InstallRequest installRequest = new InstallRequest(
                "Take.Blip.Client.Templates",
                "0.5.135",
                details: new Dictionary <string, string>
            {
                { InstallerConstants.NuGetSourcesKey, "https://api.nuget.org/v3/index.json" }
            });

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            Assert.Equal(InstallerErrorCode.Success, result[0].Error);
            Assert.True(string.IsNullOrEmpty(result[0].ErrorMessage));
            Assert.Equal(installRequest, result[0].InstallRequest);

            IManagedTemplatePackage source = result[0].TemplatePackage;

            Assert.Equal("Take.Blip.Client.Templates", source.Identifier);
            Assert.Equal("Global Settings", source.Provider.Factory.DisplayName);
            Assert.Equal("NuGet", source.Installer.Factory.Name);
            source.GetDetails()["Author"].Should().NotBeNullOrEmpty();
            Assert.Equal("https://api.nuget.org/v3/index.json", source.GetDetails()["NuGetSource"]);
            Assert.Equal("0.5.135", source.Version);

            IReadOnlyList <IManagedTemplatePackage> managedTemplatesPackages = await bootstrapper.GetManagedTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, managedTemplatesPackages.Count);
            managedTemplatesPackages[0].Should().BeEquivalentTo(source);

            IReadOnlyList <ITemplatePackage> templatePackages = await bootstrapper.GetTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, templatePackages.Count);
            Assert.IsAssignableFrom <IManagedTemplatePackage>(templatePackages[0]);
            templatePackages[0].Should().BeEquivalentTo((ITemplatePackage)source);
        }
        internal async Task CanUpdate_NuGetPackage()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper();
            InstallRequest installRequest = new InstallRequest("Microsoft.DotNet.Common.ProjectTemplates.5.0", "5.0.0");

            IReadOnlyList <InstallResult> result = await bootstrapper.InstallTemplatePackagesAsync(new[] { installRequest }, InstallationScope.Global, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, result.Count);
            Assert.True(result[0].Success);
            IManagedTemplatePackage source = result[0].TemplatePackage;

            UpdateRequest updateRequest = new UpdateRequest(source, "5.0.1");

            IReadOnlyList <UpdateResult> updateResults = await bootstrapper.UpdateTemplatePackagesAsync(new[] { updateRequest }, CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, updateResults.Count);
            Assert.True(updateResults[0].Success);
            Assert.Equal(InstallerErrorCode.Success, updateResults[0].Error);
            Assert.True(string.IsNullOrEmpty(updateResults[0].ErrorMessage));
            Assert.Equal(updateRequest, updateResults[0].UpdateRequest);

            IManagedTemplatePackage updatedSource = updateResults[0].TemplatePackage;

            Assert.Equal("Global Settings", updatedSource.Provider.Factory.DisplayName);
            Assert.Equal("NuGet", updatedSource.Installer.Factory.Name);
            Assert.Equal("5.0.1", updatedSource.Version);

            IReadOnlyList <IManagedTemplatePackage> managedTemplatesPackages = await bootstrapper.GetManagedTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, managedTemplatesPackages.Count);
            managedTemplatesPackages[0].Should().BeEquivalentTo(updatedSource);

            IReadOnlyList <ITemplatePackage> templatePackages = await bootstrapper.GetTemplatePackages(CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(1, templatePackages.Count);
            Assert.IsAssignableFrom <IManagedTemplatePackage>(templatePackages[0]);
            templatePackages[0].Should().BeEquivalentTo((ITemplatePackage)updatedSource);
        }
Example #25
0
        internal async Task GetTemplates_BasicTest()
        {
            using Bootstrapper bootstrapper = BootstrapperFactory.GetBootstrapper(loadBuiltInTemplates: true);

            var result1 = await bootstrapper.GetTemplatesAsync(default).ConfigureAwait(false);