public void SuccessfullyAddNewProject_When_AllIsCorrect()
        {
            SolutionProject solutionProject = new SolutionProject(this.projectGuid, this.csProjFilePath, this.slnFilePathWithElements, SolutionProjectType.WebProject);

            SolutionFileEditor.AddProject(this.slnFilePathWithElements, solutionProject);

            var slnContents = File.ReadAllText(this.slnFilePathWithElements);

            Assert.IsFalse(string.IsNullOrEmpty(slnContents));

            IEnumerable <SolutionProject> solutionProjects = SolutionFileEditor.GetProjects(this.slnFilePathWithElements);
            bool hasProject = solutionProjects.Any(sp => sp.ProjectGuid == this.projectGuid &&
                                                   sp.AbsolutePath.Equals(this.csProjFilePath, StringComparison.InvariantCultureIgnoreCase) &&
                                                   sp.ProjectType == SolutionProjectType.WebProject);

            Assert.IsTrue(hasProject);
        }
Exemple #2
0
        /// <summary>
        /// A method containing the logic of the command
        /// </summary>
        /// <param name="config"></param>
        /// <returns>0 for success; 1 for failure</returns>
        public override int OnExecute(CommandLineApplication config)
        {
            var currentPath = this.ProjectRootPath;

            if (!Directory.Exists(currentPath))
            {
                currentPath = Path.GetDirectoryName(currentPath);
            }

            var webAppProjectName = Path.GetFileName(Directory.EnumerateFiles(currentPath, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault());

            while (Directory.EnumerateFiles(currentPath, @"*.sln", SearchOption.TopDirectoryOnly).FirstOrDefault() == null)
            {
                currentPath = Directory.GetParent(currentPath)?.ToString();
                if (string.IsNullOrEmpty(currentPath))
                {
                    Utils.WriteLine(Constants.SolutionNotFoundMessage, ConsoleColor.Red);
                    return((int)ExitCode.GeneralError);
                }
            }

            this.SolutionPath = Directory.EnumerateFiles(currentPath, @"*.sln", SearchOption.TopDirectoryOnly).FirstOrDefault();

            var sitefinityPath = Directory.EnumerateFiles(currentPath, "Telerik.Sitefinity.dll", SearchOption.AllDirectories).FirstOrDefault();

            var binFolder = Path.GetDirectoryName(sitefinityPath);

            if (string.IsNullOrEmpty(binFolder))
            {
                Utils.WriteLine(Constants.ProjectNotFound, ConsoleColor.Red);
                return((int)ExitCode.GeneralError);
            }

            this.SitefinityVersion = FileVersionInfo.GetVersionInfo(sitefinityPath).ProductVersion;
            this.ProjectRootPath   = Path.Combine(currentPath, this.PascalCaseName);

            if (Path.IsPathRooted(binFolder))
            {
                binFolder = Path.GetRelativePath(this.ProjectRootPath, binFolder);
            }

            this.BinFolder = binFolder;

            Directory.CreateDirectory(this.ProjectRootPath);

            if (base.OnExecute(config) == 1)
            {
                return((int)ExitCode.GeneralError);
            }

            var project = this.createdFiles.FirstOrDefault(x => x.EndsWith(Constants.CsprojFileExtension));

            try
            {
                SolutionProject solutionProject = new SolutionProject(this.ProjectGuid, project, this.SolutionPath, SolutionProjectType.ManagedCsProject);
                SolutionFileEditor.AddProject(this.SolutionPath, solutionProject);

                Utils.WriteLine(string.Format(Constants.AddFilesToSolutionSuccessMessage, project), ConsoleColor.Green);
            }
            catch (Exception ex)
            {
                Utils.WriteLine(ex.Message, ConsoleColor.Yellow);
            }

            return((int)ExitCode.OK);
        }