public void VisitDependency_ShouldReturn_GitDependFileNotFound_WhenUnableToLoadConfigFile()
        {
            var factory  = Container.Resolve <IGitDependFileFactory>();
            var instance = new BuildAndUpdateDependenciesVisitor(new List <string>());

            string     dir;
            ReturnCode loadCode = ReturnCode.GitRepositoryNotFound;

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

            var code = instance.VisitDependency(Lib2Directory, Lib1Dependency);

            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, code, "Invalid ReturnCode");
            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, instance.ReturnCode, "Invalid ReturnCode");
        }
        public void VisitDependency_ShouldRunBuildScript()
        {
            var factory        = Container.Resolve <IGitDependFileFactory>();
            var processManager = Container.Resolve <IProcessManager>();
            var fileSystem     = RegisterMockFileSystem();
            var instance       = new BuildAndUpdateDependenciesVisitor(new List <string>());

            string     dir;
            ReturnCode loadCode = ReturnCode.Success;

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

            bool scriptExecuted = false;

            processManager.Arrange(m => m.Start(Arg.IsAny <ProcessStartInfo>()))
            .Returns((ProcessStartInfo info) =>
            {
                scriptExecuted = true;
                EnsureFiles(fileSystem, Lib1PackagesDirectory, Lib1Packages);

                return(new FakeProcess
                {
                    ExitCode = 0,
                    HasExited = true
                });
            });


            var code = instance.VisitDependency(Lib2Directory, Lib1Dependency);

            var cachedPackages = fileSystem.Directory.GetFiles(instance.GetCacheDirectory(), "*.nupkg");

            Assert.AreEqual(Lib1Packages.Count, cachedPackages.Length, "Invalid number of cached nuget packages");

            foreach (var package in cachedPackages)
            {
                var name = fileSystem.Path.GetFileName(package);
                // Make sure that name shows up in the original list.
                Assert.IsTrue(Lib1Packages.Any(p => fileSystem.Path.GetFileName(p) == name));
            }

            Assert.IsTrue(scriptExecuted, "Build Script was not executed");
            Assert.AreEqual(ReturnCode.Success, code, "Invalid ReturnCode");
            Assert.AreEqual(ReturnCode.Success, instance.ReturnCode, "Invalid ReturnCode");
        }
        public void VisitDependency_ShouldReturn_CouldNotCreateCacheDirectory_IfCacheDirectoryFailsToCreate()
        {
            var factory = Container.Resolve <IGitDependFileFactory>();

            string     dir;
            ReturnCode loadCode = ReturnCode.Success;

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

            var fileSystem = Container.Resolve <IFileSystem>();

            fileSystem.Directory.Arrange(d => d.CreateDirectory(Arg.AnyString))
            .Throws <IOException>("Access Denied");

            var instance = new BuildAndUpdateDependenciesVisitor(new List <string>());

            var code = instance.VisitDependency(Lib2Directory, Lib1Dependency);

            Assert.AreEqual(ReturnCode.CouldNotCreateCacheDirectory, code, "Invalid ReturnCode");
            Assert.AreEqual(ReturnCode.CouldNotCreateCacheDirectory, instance.ReturnCode, "Invalid ReturnCode");
        }