Ejemplo n.º 1
0
        public void Execute_ShouldUseDefaultValues_WhenNoInputIsGiven()
        {
            var factory    = Container.Resolve <IGitDependFileFactory>();
            var console    = Container.Resolve <IConsole>();
            var fileSystem = Container.Resolve <IFileSystem>();

            var        config   = new GitDependFile();
            string     dir      = Lib1Directory;
            ReturnCode loadCode = ReturnCode.Success;

            factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out loadCode))
            .Returns(config);

            fileSystem.Arrange(f => f.File.WriteAllText(Arg.AnyString, Arg.AnyString))
            .MustBeCalled();

            int index = 0;

            string[] responses =
            {
                "",
                ""
            };
            console.Arrange(c => c.ReadLine())
            .Returns(() => responses[index++]);

            var options  = new InitSubOptions();
            var instance = new InitCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
            fileSystem.Assert("WriteAllText should have been caleld");
            Assert.AreEqual("make.bat", config.Build.Script, "Invalid Build Script");
            Assert.AreEqual("artifacts/NuGet/Debug", config.Packages.Directory, "Invalid Packages Directory");
        }
Ejemplo n.º 2
0
        public void LoadFromDirectory_ShouldReturn_InvalidUrlFormat_WhenUrlIsNotHttps()
        {
            var fileSystem     = RegisterMockFileSystem();
            var expectedConfig = new GitDependFile
            {
                Name         = "testing",
                Dependencies =
                {
                    new Dependency
                    {
                        Url       = "[email protected]:kjjuno/Lib2.git",
                        Directory = "..\\Lib2"
                    }
                }
            };

            var instance = new GitDependFileFactory();

            string directory = @"C:\projects\GitDepend";

            fileSystem.Directory.CreateDirectory(directory);
            fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(directory, ".git"));
            var path = fileSystem.Path.Combine(directory, "GitDepend.json");

            fileSystem.File.WriteAllText(path, expectedConfig.ToString());

            string     dir;
            ReturnCode code;
            var        config = instance.LoadFromDirectory(directory, out dir, out code);

            Assert.IsNull(config, "Config file should be null");
            Assert.AreEqual(directory, dir, "Invalid directory");
            Assert.AreEqual(ReturnCode.InvalidUrlFormat, code, "Invalid Return Code");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Visists a project.
        /// </summary>
        /// <param name="directory">The directory of the project.</param>
        /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
        /// <returns>The return code.</returns>
        public ReturnCode VisitProject(string directory, GitDependFile config)
        {
            _console.WriteLine(Force
                ? $"forcefully deleting the {BranchName} branch from {config.Name}"
                : $"Deleting the {BranchName} branch from {config.Name}");

            _git.WorkingDirectory = directory;
            return(ReturnCode = _git.DeleteBranch(BranchName, Force));
        }
Ejemplo n.º 4
0
        public void DefaultValuesTest()
        {
            var file     = new GitDependFile();
            var build    = new Build();
            var packages = new Packages();

            Assert.IsNotNull(file.Build);
            Assert.AreEqual(build.ToString(), file.Build.ToString());

            Assert.IsNotNull(file.Packages);
            Assert.AreEqual(packages.ToString(), file.Packages.ToString());

            Assert.IsNotNull(file.Dependencies);
            Assert.IsEmpty(file.Dependencies);
        }
Ejemplo n.º 5
0
        public void LoadFromDirectory_ShoulReturnEmptyFile_WhenNoGitDependFileExistsInGitRepo()
        {
            var fileSystem = RegisterMockFileSystem();
            var instance   = new GitDependFileFactory();

            string directory = @"C:\projects\GitDepend";

            fileSystem.Directory.CreateDirectory(directory);
            fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(directory, ".git"));

            string     dir;
            ReturnCode code;
            var        config   = instance.LoadFromDirectory(directory, out dir, out code);
            var        expected = new GitDependFile();

            Assert.IsNotNull(config, "Config file should not be null");
            Assert.AreEqual(directory, dir, "Invalid directory");
            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
            Assert.AreEqual(expected.ToString(), config.ToString(), "File does not match");
        }
Ejemplo n.º 6
0
        protected TestFixtureBase()
        {
            Lib1Config = new GitDependFile
            {
                Name     = "Lib1",
                Build    = { Script = "make.bat" },
                Packages = { Directory = "artifacts/NuGet/Debug" }
            };

            Lib1Dependency = new Dependency
            {
                Directory     = "..\\Lib1",
                Url           = "https://github.com/kjjuno/Lib1.git",
                Branch        = "develop",
                Configuration = Lib1Config
            };

            Lib1Packages = new List <string>
            {
                "Lib1.Core.0.1.0-alpha0003.nupkg",
                "Lib1.Busi.0.1.0-alpha0003.nupkg",
                "Lib1.Data.0.1.0-alpha0003.nupkg"
            };

            Lib2Config = new GitDependFile
            {
                Name         = "Lib2",
                Build        = { Script = "make.bat" },
                Packages     = { Directory = "artifacts/NuGet/Debug" },
                Dependencies = { Lib1Dependency }
            };

            Lib2Solutions = new List <string>
            {
                "Lib2.sln",
                "Lib2.UnitTests.sln"
            };
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Visists a project.
 /// </summary>
 /// <param name="directory">The directory of the project.</param>
 /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
 /// <returns>The return code.</returns>
 public ReturnCode VisitProject(string directory, GitDependFile config)
 {
     return(ReturnCode.Success);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Visists a project.
 /// </summary>
 /// <param name="directory">The directory of the project.</param>
 /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
 /// <returns>The return code.</returns>
 public ReturnCode VisitProject(string directory, GitDependFile config)
 {
     _git.WorkingDirectory = directory;
     return(ReturnCode = _git.Checkout(_branchName, _createBranch));
 }
        /// <summary>
        /// Visists a project.
        /// </summary>
        /// <param name="directory">The directory of the project.</param>
        /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
        /// <returns>The return code.</returns>
        public ReturnCode VisitProject(string directory, GitDependFile config)
        {
            if (config == null)
            {
                return(ReturnCode = ReturnCode.Success);
            }

            if (string.IsNullOrEmpty(directory) || !_fileSystem.Directory.Exists(directory))
            {
                return(ReturnCode = ReturnCode.DirectoryDoesNotExist);
            }

            foreach (var dependency in config.Dependencies)
            {
                var dependencyDir = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(directory, dependency.Directory));
                var dir           = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(dependencyDir, dependency.Configuration.Packages.Directory));

                foreach (var file in _fileSystem.Directory.GetFiles(dir, "*.nupkg"))
                {
                    var name = _fileSystem.Path.GetFileNameWithoutExtension(file);


                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    var match = Pattern.Match(name);

                    if (!match.Success)
                    {
                        continue;
                    }

                    var id      = match.Groups["id"].Value;
                    var version = match.Groups["version"].Value;

                    _nuget.WorkingDirectory = directory;

                    foreach (var solution in _fileSystem.Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories))
                    {
                        var cacheDir = GetCacheDirectory();

                        if (string.IsNullOrEmpty(cacheDir))
                        {
                            return(ReturnCode = ReturnCode.CouldNotCreateCacheDirectory);
                        }

                        _nuget.Restore(solution);
                        _nuget.Update(solution, id, version, cacheDir);
                    }
                }
            }

            _console.WriteLine("================================================================================");
            _console.WriteLine($"Making update commit on {directory}");
            _git.WorkingDirectory = directory;
            _git.Add("*.csproj", @"*\packages.config");
            _console.WriteLine("================================================================================");
            _git.Status();
            _git.Commit("GitDepend: updating dependencies");

            return(ReturnCode = ReturnCode.Success);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Visists a project.
        /// </summary>
        /// <param name="directory">The directory of the project.</param>
        /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
        /// <returns>The return code.</returns>
        public ReturnCode VisitProject(string directory, GitDependFile config)
        {
            if (config == null)
            {
                return(ReturnCode = ReturnCode.Success);
            }

            // If there are specific dependencies specified
            // and this one isn't in the list
            // skip it.
            if (_whitelist.Any() &&
                _whitelist.All(d => !string.Equals(d, config.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                return(ReturnCode.Success);
            }

            if (string.IsNullOrEmpty(directory) || !_fileSystem.Directory.Exists(directory))
            {
                return(ReturnCode = ReturnCode.DirectoryDoesNotExist);
            }

            StringBuilder commitMessage = new StringBuilder();

            commitMessage.AppendLine("GitDepend: updating dependencies");
            commitMessage.AppendLine();

            var solutions = _fileSystem.Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories);

            foreach (var solution in solutions)
            {
                _nuget.Restore(solution);
            }

            foreach (var solution in solutions)
            {
                var path = solution.Remove(0, directory.Length + 1);
                commitMessage.AppendLine(path);

                foreach (var dependency in config.Dependencies)
                {
                    // If there are specific dependencies specified
                    // and this one isn't in the list
                    // skip it.
                    if (_whitelist.Any() &&
                        _whitelist.All(d => !string.Equals(d, dependency.Configuration.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }

                    var dependencyDir = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(directory, dependency.Directory));
                    var dir           = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(dependencyDir, dependency.Configuration.Packages.Directory));

                    foreach (var file in _fileSystem.Directory.GetFiles(dir, "*.nupkg"))
                    {
                        var name = _fileSystem.Path.GetFileNameWithoutExtension(file);


                        if (string.IsNullOrEmpty(name))
                        {
                            continue;
                        }

                        var match = Pattern.Match(name);

                        if (!match.Success)
                        {
                            continue;
                        }

                        var id      = match.Groups["id"].Value;
                        var version = match.Groups["version"].Value;

                        commitMessage.AppendLine($"* {id}.{version}");

                        _nuget.WorkingDirectory = directory;

                        var cacheDir = GetCacheDirectory();

                        if (string.IsNullOrEmpty(cacheDir))
                        {
                            return(ReturnCode = ReturnCode.CouldNotCreateCacheDirectory);
                        }

                        _nuget.Update(solution, id, version, cacheDir);

                        var package = $"{id}.{version}";
                        if (!UpdatedPackages.Contains(package))
                        {
                            UpdatedPackages.Add(package);
                        }
                    }
                }
            }

            _console.WriteLine("================================================================================");
            _console.WriteLine($"Making update commit on {directory}");
            _git.WorkingDirectory = directory;
            _git.Add("*.csproj", @"*\packages.config");
            _console.WriteLine("================================================================================");
            _git.Status();

            _git.Commit(commitMessage.ToString());

            return(ReturnCode = ReturnCode.Success);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Visists a project.
 /// </summary>
 /// <param name="directory">The directory of the project.</param>
 /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
 /// <returns>The return code.</returns>
 public ReturnCode VisitProject(string directory, GitDependFile config)
 {
     _console.WriteLine($"Creating the {BranchName} branch on {config.Name}");
     _git.WorkingDirectory = directory;
     return(ReturnCode = _git.CreateBranch(BranchName));
 }