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 ShouldSetupApplicationLocallyAfterCreationIfNotConfigured([Frozen]Mock<IApplicationConfiguration> applicationConfiguration, [Frozen]Mock<IAppHarborClient> client, CreateAppCommand command, CreateResult result, User user, string[] arguments) { client.Setup(x => x.CreateApplication(It.IsAny<string>(), It.IsAny<string>())).Returns(result); client.Setup(x => x.GetUser()).Returns(user); applicationConfiguration.Setup(x => x.GetApplicationId()).Throws<ApplicationConfigurationException>(); command.Execute(arguments); applicationConfiguration.Verify(x => x.SetupApplication(result.Id, user), Times.Once()); }
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 ShouldAddConfigurationVariables([Frozen]Mock<IAppHarborClient> client, [Frozen]Mock<TextWriter> writer, UserCommand command, User user, string applicationId) { client.Setup(x => x.GetUser()).Returns(user); command.Execute(new string[0]); writer.Verify(x => x.WriteLine("Username: {0}", user.Username)); writer.Verify(x => x.WriteLine("Email addresses: [{0}]", string.Join(" ", user.Email_Addresses))); }
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(); }
public void ShouldCreateAppHarborConfigurationFileIfGitSetupFailed([Frozen]Mock<IGitRepositoryConfigurer> repositoryConfigurer, [Frozen]Mock<IFileSystem> fileSystem, ApplicationConfiguration applicationConfiguration, string id, User user) { repositoryConfigurer.Setup(x => x.Configure(It.IsAny<string>(), It.IsAny<User>())).Throws<RepositoryConfigurationException>(); Action<MemoryStream> VerifyConfigurationContent = stream => Assert.Equal(Encoding.Default.GetBytes(id), stream.ToArray()); using (var stream = new DelegateOutputStream(VerifyConfigurationContent)) { fileSystem.Setup(x => x.OpenWrite(ConfigurationFile)).Returns(stream); applicationConfiguration.SetupApplication(id, user); } fileSystem.Verify(x => x.OpenWrite(ConfigurationFile), Times.Once()); }
public void ShouldSetupApplication([Frozen]Mock<IApplicationConfiguration> applicationConfiguration, [Frozen]Mock<IAppHarborClient> appharborClient, LinkAppCommand command, Application application, User user) { appharborClient.Setup(x => x.GetApplication(application.Slug)).Returns(application); appharborClient.Setup(x => x.GetUser()).Returns(user); applicationConfiguration.Setup(x => x.SetupApplication(application.Slug, user)); command.Execute(new List<string> { application.Slug }.ToArray()); applicationConfiguration.Verify(x => x.SetupApplication(application.Slug, user)); }
public void Configure(string id, User user) { var repositoryUrl = string.Format("https://{0}@appharbor.com/{1}.git", user.Username, id); try { _gitCommand.Execute("--version"); } catch (GitCommandException) { throw new RepositoryConfigurationException(string.Format("Git is not installed.")); } try { _gitCommand.Execute("status"); } catch (GitCommandException) { _writer.Write("Git repository is not initialized in this folder. Do you want to initialize it (type \"y\")?"); if (_reader.ReadLine() != "y") { throw new RepositoryConfigurationException("Git repository was not initialized."); } _gitCommand.Execute("init"); using (var stream = _fileSystem.OpenWrite(Path.Combine(Directory.GetCurrentDirectory(), ".gitignore"))) { using (var writer = new StreamWriter(stream)) { writer.Write(DefaultGitIgnore); } } _writer.WriteLine("Git repository was initialized with default .gitignore file."); } try { _gitCommand.Execute(string.Format("remote add appharbor {0}", repositoryUrl)); _writer.WriteLine("Added \"appharbor\" as a remote repository. Push to AppHarbor with git push appharbor master."); } catch (GitCommandException) { throw new RepositoryConfigurationException( string.Format("Couldn't add appharbor repository as a git remote. Repository URL is: {0}.", repositoryUrl)); } }
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 virtual void SetupApplication(string id, User user) { try { _repositoryConfigurer.Configure(id, user); return; } catch (RepositoryConfigurationException exception) { _writer.WriteLine(exception.Message); } using (var stream = _fileSystem.OpenWrite(ConfigurationFile.FullName)) { using (var writer = new StreamWriter(stream)) { writer.Write(id); } } _writer.WriteLine("Wrote application configuration to {0}. Make sure not to delete this file", ConfigurationFile.FullName); }
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()); }
private static string GetRepositoryUrl(string id, User user) { return string.Format("https://{0}@appharbor.com/{1}.git", user.Username, id); }