Esempio n. 1
0
        public void TraverseDependencies_ShouldNotThrow_WithNullDirectory()
        {
            var visitor  = Mock.Create <IVisitor>();
            var instance = new DependencyVisitorAlgorithm();

            instance.TraverseDependencies(visitor, null);
        }
Esempio n. 2
0
        public void TraverseDependencies_ShouldReturnFailureCode_WhenVisitingDependencyReturnsFailureCode()
        {
            var visitor    = Mock.Create <IVisitor>();
            var fileSystem = RegisterMockFileSystem();
            var factory    = Container.Resolve <IGitDependFileFactory>();
            var git        = Container.Resolve <IGit>();
            var instance   = new DependencyVisitorAlgorithm();

            visitor.Arrange(v => v.VisitDependency(Arg.AnyString, Arg.IsAny <Dependency>()))
            .Returns(ReturnCode.FailedToRunBuildScript);

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

            string lib2Dir = PROJECT_DIRECTORY;

            ReturnCode lib2Code;

            factory.Arrange(f => f.LoadFromDirectory(lib2Dir, out lib2Dir, out lib2Code))
            .Returns(Lib2Config);

            git.Arrange(g => g.Clone(Arg.AnyString, Arg.AnyString, Arg.AnyString))
            .Returns((string url, string directory, string branch) =>
            {
                fileSystem.Directory.CreateDirectory(directory);
                return(ReturnCode.Success);
            });

            instance.TraverseDependencies(visitor, PROJECT_DIRECTORY);
            Assert.AreEqual(ReturnCode.FailedToRunBuildScript, visitor.ReturnCode, "Invalid ReturnCode");
        }
Esempio n. 3
0
        public void TraverseDependencies_ShouldOnlyVisitEachNodeOnce()
        {
            var fileSystem = RegisterMockFileSystem();
            var factory    = Container.Resolve <IGitDependFileFactory>();
            var git        = Container.Resolve <IGit>();
            var instance   = new DependencyVisitorAlgorithm();

            List <string> visitedDependencies = new List <string>();
            List <string> visitedProjects     = new List <string>();

            var visitor = Mock.Create <IVisitor>();

            visitor.Arrange(v => v.VisitDependency(Arg.AnyString, Arg.IsAny <Dependency>()))
            .Returns((string directory, Dependency dependency) =>
            {
                Assert.IsFalse(visitedDependencies.Contains(dependency.Directory), "This dependency has already been visited");

                visitedDependencies.Add(dependency.Directory);
                return(ReturnCode.Success);
            });

            visitor.Arrange(v => v.VisitProject(Arg.AnyString, Arg.IsAny <GitDependFile>()))
            .Returns((string directory, GitDependFile config) =>
            {
                Assert.IsFalse(visitedProjects.Contains(directory), "This project has already been visited");

                visitedProjects.Add(directory);
                return(ReturnCode.Success);
            });

            string lib2Dir = PROJECT_DIRECTORY;
            var    dir     = Lib2Config.Dependencies.First(d => d.Name == "Lib1").Directory;
            string lib1Dir = fileSystem.Path.GetFullPath(fileSystem.Path.Combine(lib2Dir, dir));

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

            ReturnCode lib1Code;
            ReturnCode lib2Code;

            factory.Arrange(f => f.LoadFromDirectory(lib1Dir, out lib1Dir, out lib1Code))
            .Returns(Lib1Config);

            factory.Arrange(f => f.LoadFromDirectory(lib2Dir, out lib2Dir, out lib2Code))
            .Returns(Lib2Config);

            git.Arrange(g => g.Clone(Arg.AnyString, Arg.AnyString, Arg.AnyString))
            .Returns((string url, string directory, string branch) =>
            {
                fileSystem.Directory.CreateDirectory(directory);
                return(ReturnCode.Success);
            });

            instance.TraverseDependencies(visitor, PROJECT_DIRECTORY);

            Assert.AreEqual(ReturnCode.Success, visitor.ReturnCode, "Invalid ReturnCode");
            Assert.AreEqual(1, visitedDependencies.Count, "Incorrect number of visited dependencies");
            Assert.AreEqual(2, visitedProjects.Count, "Incorrect number of visited projects");
        }
Esempio n. 4
0
        public void TraverseDependencies_ShouldReturn_GitRepositoryNotFound_WhenDirectoryDoesNotExist()
        {
            var visitor  = Mock.Create <IVisitor>();
            var instance = new DependencyVisitorAlgorithm();

            instance.TraverseDependencies(visitor, PROJECT_DIRECTORY);

            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, visitor.ReturnCode, "Invalid ReturnCode");
        }
Esempio n. 5
0
        public void TraverseDependencies_ShouldReturn_GitRepositoryNotFound_WhenUnableToLoadFile()
        {
            var visitor    = Mock.Create <IVisitor>();
            var factory    = Container.Resolve <IGitDependFileFactory>();
            var fileSystem = RegisterMockFileSystem();
            var instance   = new DependencyVisitorAlgorithm();

            // LoadFromDirectory returns null
            string     dir;
            ReturnCode code = ReturnCode.GitRepositoryNotFound;

            factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out code))
            .Returns(null as GitDependFile);

            // The directory needs to exist
            fileSystem.Directory.CreateDirectory(PROJECT_DIRECTORY);

            instance.TraverseDependencies(visitor, PROJECT_DIRECTORY);

            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, visitor.ReturnCode, "Invalid ReturnCode");
        }
Esempio n. 6
0
        public void TraverseDependencies_ShouldReturn_FailedToRunGitCommand_WhenFailingToCloneRepository()
        {
            var visitor    = Mock.Create <IVisitor>();
            var fileSystem = RegisterMockFileSystem();
            var factory    = Container.Resolve <IGitDependFileFactory>();
            var git        = Container.Resolve <IGit>();
            var instance   = new DependencyVisitorAlgorithm();

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

            string lib2Dir = PROJECT_DIRECTORY;

            ReturnCode lib1Code;

            factory.Arrange(f => f.LoadFromDirectory(lib2Dir, out lib2Dir, out lib1Code))
            .Returns(Lib2Config);

            git.Arrange(g => g.Clone(Arg.AnyString, Arg.AnyString, Arg.AnyString))
            .Returns(ReturnCode.FailedToRunGitCommand);

            instance.TraverseDependencies(visitor, PROJECT_DIRECTORY);
            Assert.AreEqual(ReturnCode.FailedToRunGitCommand, visitor.ReturnCode, "Invalid ReturnCode");
        }
Esempio n. 7
0
        public void TraverseDependencies_ShouldNotThrow_WithNullVisitor()
        {
            var instance = new DependencyVisitorAlgorithm();

            instance.TraverseDependencies(null, @"C:\testdir");
        }
Esempio n. 8
0
        public void TraverseDependencies_ShouldNotThrow_WithNullVisitorAndNullDirectory()
        {
            var instance = new DependencyVisitorAlgorithm();

            instance.TraverseDependencies(null, null);
        }