Ejemplo n.º 1
0
        public void ShouldTryAndSetUpGitRemoteIfPossible([Frozen] Mock <IGitCommand> gitCommand, [Frozen] Mock <TextWriter> writer, GitRepositoryConfigurer repositoryConfigurer, User user, string id)
        {
            repositoryConfigurer.Configure(id, user);

            writer.Verify(x => x.WriteLine("Added \"appharbor\" as a remote repository. Push to AppHarbor with git push appharbor master."));
            gitCommand.Verify(x => x.Execute(string.Format("remote add appharbor {0}", GetRepositoryUrl(id, user))), Times.Once());
        }
        public void ShouldThrowIfGitIsNotInstalled([Frozen]Mock<IGitCommand> gitCommand, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            gitCommand.Setup(x => x.Execute("--version")).Throws<GitCommandException>();

            var exception = Assert.Throws<RepositoryConfigurationException>(() => repositoryConfigurer.Configure(id, user));
            Assert.Equal(string.Format("Git is not installed.", GetRepositoryUrl(id, user)), exception.Message);
        }
Ejemplo n.º 3
0
        public void ShouldThrowIfGitIsNotInstalled([Frozen] Mock <IGitCommand> gitCommand, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            gitCommand.Setup(x => x.Execute("--version")).Throws <GitCommandException>();

            var exception = Assert.Throws <RepositoryConfigurationException>(() => repositoryConfigurer.Configure(id, user));

            Assert.Equal(string.Format("Git is not installed.", GetRepositoryUrl(id, user)), exception.Message);
        }
        public void ShouldThrowExceptionIfGitRemoteCantBeAdded([Frozen]Mock<IGitCommand> gitCommand, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            var repositoryUrl = GetRepositoryUrl(id, user);
            gitCommand.Setup(x => x.Execute(string.Format("remote add appharbor {0}", repositoryUrl))).Throws<GitCommandException>();

            var exception = Assert.Throws<RepositoryConfigurationException>(() => repositoryConfigurer.Configure(id, user));
            Assert.Equal(string.Format("Couldn't add appharbor repository as a git remote. Repository URL is: {0}.", repositoryUrl),
                exception.Message);
        }
Ejemplo n.º 5
0
        public void ShouldAskForGitInitializationAndThrowIfNotWanted([Frozen] Mock <IGitCommand> gitCommand, [Frozen] Mock <TextReader> reader, [Frozen] Mock <TextWriter> writer, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            gitCommand.Setup(x => x.Execute("status")).Throws <GitCommandException>();
            reader.Setup(x => x.ReadLine()).Returns("n");

            var exception = Assert.Throws <RepositoryConfigurationException>(() => repositoryConfigurer.Configure(id, user));

            Assert.Equal("Git repository was not initialized.", exception.Message);
            writer.Verify(x => x.Write("Git repository is not initialized in this folder. Do you want to initialize it (type \"y\")?"));
            reader.VerifyAll();
        }
Ejemplo n.º 6
0
        public void ShouldThrowExceptionIfGitRemoteCantBeAdded([Frozen] Mock <IGitCommand> gitCommand, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            var repositoryUrl = GetRepositoryUrl(id, user);

            gitCommand.Setup(x => x.Execute(string.Format("remote add appharbor {0}", repositoryUrl))).Throws <GitCommandException>();

            var exception = Assert.Throws <RepositoryConfigurationException>(() => repositoryConfigurer.Configure(id, user));

            Assert.Equal(string.Format("Couldn't add appharbor repository as a git remote. Repository URL is: {0}.", repositoryUrl),
                         exception.Message);
        }
        public void ShouldAskForGitInitializationAndThrowIfNotWanted([Frozen]Mock<IGitCommand> gitCommand, [Frozen]Mock<TextReader> reader, [Frozen]Mock<TextWriter> writer, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            gitCommand.Setup(x => x.Execute("status")).Throws<GitCommandException>();
            reader.Setup(x => x.ReadLine()).Returns("n");

            var exception = Assert.Throws<RepositoryConfigurationException>(() => repositoryConfigurer.Configure(id, user));

            Assert.Equal("Git repository was not initialized.", exception.Message);
            writer.Verify(x => x.Write("Git repository is not initialized in this folder. Do you want to initialize it (type \"y\")?"));
            reader.VerifyAll();
        }
Ejemplo n.º 8
0
        public void ShouldInitializeRepositoryIfUserWantIt([Frozen] Mock <IFileSystem> fileSystem, [Frozen] Mock <TextReader> reader, [Frozen] Mock <TextWriter> writer, [Frozen] Mock <IGitCommand> gitCommand, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            gitCommand.Setup(x => x.Execute("status")).Throws <GitCommandException>();
            reader.Setup(x => x.ReadLine()).Returns("y");
            var gitIgnoreFile = Path.Combine(Directory.GetCurrentDirectory(), ".gitignore");
            Action <MemoryStream> VerifyGitIgnoreContent = stream =>
                                                           Assert.Equal(Encoding.Default.GetBytes(GitRepositoryConfigurer.DefaultGitIgnore), stream.ToArray());

            using (var stream = new DelegateOutputStream(VerifyGitIgnoreContent))
            {
                fileSystem.Setup(x => x.OpenWrite(gitIgnoreFile)).Returns(stream);
                repositoryConfigurer.Configure(id, user);
            }

            fileSystem.Verify(x => x.OpenWrite(gitIgnoreFile), Times.Once());
            gitCommand.Verify(x => x.Execute("init"), Times.Once());
            writer.Verify(x => x.WriteLine("Git repository was initialized with default .gitignore file."));
        }
        public void ShouldInitializeRepositoryIfUserWantIt([Frozen]Mock<IFileSystem> fileSystem, [Frozen]Mock<TextReader> reader, [Frozen]Mock<TextWriter> writer, [Frozen]Mock<IGitCommand> gitCommand, GitRepositoryConfigurer repositoryConfigurer, string id, User user)
        {
            gitCommand.Setup(x => x.Execute("status")).Throws<GitCommandException>();
            reader.Setup(x => x.ReadLine()).Returns("y");
            var gitIgnoreFile = Path.Combine(Directory.GetCurrentDirectory(), ".gitignore");
            Action<MemoryStream> VerifyGitIgnoreContent = stream =>
                Assert.Equal(Encoding.Default.GetBytes(GitRepositoryConfigurer.DefaultGitIgnore), stream.ToArray());

            using (var stream = new DelegateOutputStream(VerifyGitIgnoreContent))
            {
                fileSystem.Setup(x => x.OpenWrite(gitIgnoreFile)).Returns(stream);
                repositoryConfigurer.Configure(id, user);
            }

            fileSystem.Verify(x => x.OpenWrite(gitIgnoreFile), Times.Once());
            gitCommand.Verify(x => x.Execute("init"), Times.Once());
            writer.Verify(x => x.WriteLine("Git repository was initialized with default .gitignore file."));
        }
        public void ShouldTryAndSetUpGitRemoteIfPossible([Frozen]Mock<IGitCommand> gitCommand, [Frozen]Mock<TextWriter> writer, GitRepositoryConfigurer repositoryConfigurer, User user, string id)
        {
            repositoryConfigurer.Configure(id, user);

            writer.Verify(x => x.WriteLine("Added \"appharbor\" as a remote repository. Push to AppHarbor with git push appharbor master."));
            gitCommand.Verify(x => x.Execute(string.Format("remote add appharbor {0}", GetRepositoryUrl(id, user))), Times.Once());
        }