Exemple #1
0
        public async Task CreateFromLocalTemplate()
        {
            await EnsureCookiecutterInstalledAsync();

            _vm.SearchTerm = TestLocalTemplatePath;
            await _vm.SearchAsync();

            var template = _vm.Custom.Templates[0] as TemplateViewModel;
            await _vm.SelectTemplate(template);

            Assert.IsNull(_vm.SelectedImage);
            Assert.IsTrue(string.IsNullOrEmpty(_vm.SelectedDescription));

            await _vm.LoadTemplateAsync();

            // Local template doesn't need to be cloned
            Assert.AreEqual(OperationStatus.NotStarted, _vm.CloningStatus);

            PrintContextItems(_vm.ContextItems);
            CollectionAssert.AreEqual(LocalTemplateWithUserConfigContextItems, _vm.ContextItems, new ContextItemViewModelComparer());

            _vm.ContextItems.Single(item => item.Name == "full_name").Val           = "Integration Test User";
            _vm.ContextItems.Single(item => item.Name == "open_source_license").Val = "Apache Software License 2.0";

            var targetPath = _vm.OutputFolderPath;

            Assert.IsTrue(Path.IsPathRooted(targetPath), "{0} is not a full path".FormatInvariant(targetPath));
            Assert.IsTrue(PathUtils.IsSubpathOf(DefaultBasePath, targetPath),
                          "{0} is not in the {1} folder".FormatInvariant(targetPath, DefaultBasePath));

            try {
                await _vm.CreateFilesAsync();

                Assert.AreEqual(OperationStatus.Succeeded, _vm.CreatingStatus);

                var reportFilePath = Path.Combine(_vm.OutputFolderPath, "report.txt");
                Assert.IsTrue(File.Exists(reportFilePath), "Failed to generate some project files.");
                var report = CookiecutterClientTests.ReadReport(reportFilePath);

                var expected = new Dictionary <string, string>()
                {
                    { "full_name", "Integration Test User" },
                    { "email", "configured@email" },
                    { "github_username", "configuredgithubuser" },
                    { "project_name", "Default Project Name" },
                    { "project_slug", "default_project_name" },
                    { "pypi_username", "configuredgithubuser" },
                    { "version", "0.1.0" },
                    { "use_azure", "y" },
                    { "open_source_license", "Apache Software License 2.0" },
                    { "port", "5000" },
                };
                CollectionAssert.AreEqual(expected, report);
            } finally {
                FileUtils.DeleteDirectory(targetPath);
            }
        }
Exemple #2
0
        public async Task CreateFromLocalTemplate()
        {
            await EnsureCookiecutterInstalledAsync();

            _vm.SearchTerm = TestLocalTemplatePath;
            await _vm.SearchAsync();

            var template = _vm.Custom.Templates[0] as TemplateViewModel;
            await _vm.SelectTemplate(template);

            await _vm.LoadTemplateAsync();

            // Local template doesn't need to be cloned
            Assert.IsFalse(_vm.IsCloning);
            Assert.IsFalse(_vm.IsCloningError);
            Assert.IsFalse(_vm.IsCloningSuccess);

            PrintContextItems(_vm.ContextItems);
            CollectionAssert.AreEqual(LocalTemplateWithUserConfigContextItems, _vm.ContextItems, new ContextItemViewModelComparer());

            _vm.ContextItems.Single(item => item.Name == "full_name").Val           = "Integration Test User";
            _vm.ContextItems.Single(item => item.Name == "open_source_license").Val = "Apache Software License 2.0";
            _vm.OutputFolderPath = Path.Combine(_vm.OutputFolderPath, "LocalTemplate");

            await _vm.CreateFilesAsync();

            Assert.IsFalse(_vm.IsCreating);
            Assert.IsTrue(_vm.IsCreatingSuccess);
            Assert.IsFalse(_vm.IsCreatingError);

            var reportFilePath = Path.Combine(_vm.OutputFolderPath, "report.txt");

            Assert.IsTrue(File.Exists(reportFilePath), "Failed to generate some project files.");
            var report = CookiecutterClientTests.ReadReport(reportFilePath);

            var expected = new Dictionary <string, string>()
            {
                { "full_name", "Integration Test User" },
                { "email", "configured@email" },
                { "github_username", "configuredgithubuser" },
                { "project_name", "Default Project Name" },
                { "project_slug", "default_project_name" },
                { "pypi_username", "configuredgithubuser" },
                { "version", "0.1.0" },
                { "use_azure", "y" },
                { "open_source_license", "Apache Software License 2.0" },
                { "port", "5000" },
            };

            CollectionAssert.AreEqual(expected, report);
        }
        private void VerifyLocalTemplateReport(string fullNameOverride = null, string licenseOverride = null)
        {
            var reportFilePath = Path.Combine(_vm.OutputFolderPath, "report.txt");

            Assert.IsTrue(File.Exists(reportFilePath), "Failed to generate some project files.");
            var report = CookiecutterClientTests.ReadReport(reportFilePath);

            var expected = new Dictionary <string, string>()
            {
                { "full_name", fullNameOverride ?? "Configured User" },
                { "email", "configured@email" },
                { "github_username", "configuredgithubuser" },
                { "project_name", "Default Project Name" },
                { "project_slug", "default_project_name" },
                { "pypi_username", "configuredgithubuser" },
                { "version", "0.1.0" },
                { "use_azure", "y" },
                { "open_source_license", licenseOverride ?? "BSD license" },
                { "port", "5000" },
            };

            CollectionAssert.AreEqual(expected, report);
        }