Exemplo n.º 1
0
        protected void AssertCorrectProjectConfigInfo(UserSelectionContext context)
        {
            var projectConfigInfoService = new ProjectConfigInfoService(GenContext.ToolBox.Shell);
            var info = projectConfigInfoService.ReadProjectConfiguration();

            Assert.Equal(context.ProjectType, info.ProjectType);
            Assert.Equal(context.FrontEndFramework, info.Framework);
            Assert.Equal(context.Platform, info.Platform);
            if (!string.IsNullOrEmpty(context.GetAppModel()))
            {
                Assert.Equal(context.GetAppModel(), info.AppModel);
            }
        }
        public override void Initialize(UserSelectionContext context)
        {
            switch (context.Platform)
            {
            case Platforms.Uwp:
                WizardStatus.Title = $"{StringRes.NewProjectTitleUWP} ({GenContext.Current.ProjectName})";
                break;

            case Platforms.Wpf:
                WizardStatus.Title = $"{StringRes.NewProjectTitleWPF} ({GenContext.Current.ProjectName})";
                break;

            case Platforms.WinUI:
                switch (context.GetAppModel())
                {
                case AppModels.Desktop:
                    WizardStatus.Title = $"{StringRes.NewProjectTitleWinUIDesktop} ({GenContext.Current.ProjectName})";
                    break;

                case AppModels.Uwp:
                    WizardStatus.Title = $"{StringRes.NewProjectTitleWinUIUWP} ({GenContext.Current.ProjectName})";
                    break;
                }

                break;

            default:
                break;
            }

            base.Initialize(context);
        }
        protected void AssertProjectConfigInfoRecreated(UserSelectionContext context)
        {
            var metadataFileNames = new List<string>() { "Package.appxmanifest", "WTS.ProjectConfig.xml" };
            var metadataFile = metadataFileNames.FirstOrDefault(fileName => File.Exists(Path.Combine(GenContext.Current.DestinationPath, fileName)));
            var metadataFilePath = Path.Combine(GenContext.Current.DestinationPath, metadataFile);

            var content = File.ReadAllText(metadataFilePath);
            var expectedFxText = $"Name=\"framework\" Value=\"{context.FrontEndFramework}\"";
            var expectedPtText = $"Name=\"projectType\" Value=\"{context.ProjectType}\"";
            var expectedPfText = $"Name=\"platform\" Value=\"{context.Platform}\"";


            Assert.Contains(expectedFxText, content, StringComparison.OrdinalIgnoreCase);
            Assert.Contains(expectedPtText, content, StringComparison.OrdinalIgnoreCase);
            Assert.Contains(expectedPfText, content, StringComparison.OrdinalIgnoreCase);
            if (!string.IsNullOrEmpty(context.GetAppModel()))
            {
                var expectedAmText = $"Name=\"appmodel\" Value=\"{context.GetAppModel()}\"";
                Assert.Contains(expectedAmText, content, StringComparison.OrdinalIgnoreCase);
            }
        }
Exemplo n.º 4
0
        protected async Task <string> AssertGenerateRightClickAsync(string projectName, UserSelectionContext context, bool emptyProject, List <string> excludedGroupIdentity = null)
        {
            BaseGenAndBuildFixture.SetCurrentLanguage(context.Language);
            BaseGenAndBuildFixture.SetCurrentPlatform(context.Platform);
            var path = Path.Combine(_fixture.TestNewItemPath, projectName, projectName);

            GenContext.Current = new FakeContextProvider
            {
                ProjectName          = projectName,
                DestinationPath      = path,
                GenerationOutputPath = path,
            };

            var userSelection = _fixture.SetupProject(context);
            var appModel      = context.GetAppModel();

            if (!emptyProject)
            {
                var templates = _fixture.Templates().Where(
                    t => t.GetTemplateType().IsItemTemplate() &&
                    (t.GetProjectTypeList().Contains(context.ProjectType) || t.GetProjectTypeList().Contains(All)) &&
                    (t.GetFrontEndFrameworkList().Contains(context.FrontEndFramework) || t.GetFrontEndFrameworkList().Contains(All)) &&
                    t.GetPlatform() == context.Platform &&
                    (string.IsNullOrEmpty(appModel) || t.GetPropertyBagValuesList("appmodel").Contains(appModel) || t.GetPropertyBagValuesList("appmodel").Contains(All)) &&
                    (excludedGroupIdentity == null || (!excludedGroupIdentity.Contains(t.GroupIdentity))) &&
                    !t.GetIsHidden());

                var templatesInfo = GenContext.ToolBox.Repo.GetTemplatesInfo(templates, context);

                _fixture.AddItems(userSelection, templatesInfo, BaseGenAndBuildFixture.GetDefaultName);
            }

            await NewProjectGenController.Instance.UnsafeGenerateProjectAsync(userSelection);

            var project = Path.Combine(_fixture.TestNewItemPath, projectName);

            // Assert on project
            Assert.True(Directory.Exists(project));

            int emptyProjecFileCount = Directory.GetFiles(project, "*.*", SearchOption.AllDirectories).Count();

            Assert.True(emptyProjecFileCount > 2);

            var rightClickTemplates = _fixture.Templates().Where(
                t => t.GetTemplateType().IsItemTemplate() &&
                (t.GetProjectTypeList().Contains(context.ProjectType) || t.GetProjectTypeList().Contains(All)) &&
                (t.GetFrontEndFrameworkList().Contains(context.FrontEndFramework) || t.GetFrontEndFrameworkList().Contains(All)) &&
                t.GetPlatform() == context.Platform &&
                (string.IsNullOrEmpty(appModel) || t.GetPropertyBagValuesList("appmodel").Contains(appModel) || t.GetPropertyBagValuesList("appmodel").Contains(All)) &&
                !t.GetIsHidden() &&
                (excludedGroupIdentity == null || (!excludedGroupIdentity.Contains(t.GroupIdentity))) &&
                t.GetRightClickEnabled());

            await AddRightClickTemplatesAsync(path, rightClickTemplates, projectName, context.ProjectType, context.FrontEndFramework, context.Platform, context.Language);

            var finalProjectPath      = Path.Combine(_fixture.TestNewItemPath, projectName);
            int finalProjectFileCount = Directory.GetFiles(finalProjectPath, "*.*", SearchOption.AllDirectories).Count();

            if (emptyProject)
            {
                Assert.True(finalProjectFileCount > emptyProjecFileCount);
            }
            else
            {
                Assert.True(finalProjectFileCount == emptyProjecFileCount);
            }

            return(finalProjectPath);
        }