Ejemplo n.º 1
0
        public void Fail_When_IncorrectWebAppName()
        {
            FileModifierResult result = SlnModifier.AddFile(this.slnFilePathWithoutElements, this.csProjFilePath, this.projectGuid, this.incorrectWebAppName);

            Assert.IsFalse(result.Success);
            Assert.AreEqual("Unable to read solution", result.Message);
        }
Ejemplo n.º 2
0
        public void Fail_When_SolutionPathIsIncorrect()
        {
            FileModifierResult result = SlnModifier.AddFile(this.incorrectSlnFilePath, this.csProjFilePath, this.projectGuid, this.correctWebAppName);

            Assert.IsFalse(result.Success);
            Assert.AreEqual($"Unable to find {this.incorrectSlnFilePath}", result.Message);
        }
Ejemplo n.º 3
0
        public void SuccessfullyAddNewProject_When_AllIsCorrect()
        {
            FileModifierResult result = SlnModifier.AddFile(this.slnFilePathWithElements, this.csProjFilePath, this.projectGuid, this.correctWebAppName);

            Assert.IsTrue(result.Success);

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

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

            var csProjRelativeFilePath = Path.GetRelativePath(Path.GetDirectoryName(this.slnFilePathWithElements), this.csProjFilePath);

            Assert.IsTrue(slnContents.Contains(csProjRelativeFilePath));
        }
Ejemplo n.º 4
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));

            var slnAddResult = SlnModifier.AddFile(this.SolutionPath, project, this.ProjectGuid, webAppProjectName);

            if (slnAddResult.Success)
            {
                Utils.WriteLine(string.Format(Constants.AddFilesToSolutionSuccessMessage, project), ConsoleColor.Green);
            }
            else if (slnAddResult.Message != null)
            {
                Utils.WriteLine(slnAddResult.Message, ConsoleColor.Yellow);
            }
            else
            {
                Utils.WriteLine(string.Format(Constants.AddFilesToSolutionFailureMessage, project), ConsoleColor.Yellow);
            }

            return((int)ExitCode.OK);
        }