/Mercurial.Net.Tests/Hooks/PreCommitHookTests.cs

# · C# · 49 lines · 41 code · 8 blank · 0 comment · 0 complexity · 6ec335a81c2a78a33f9d78dbb07c1aa3 MD5 · raw file

  1. using System.IO;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. namespace Mercurial.Tests.Hooks
  5. {
  6. [TestFixture]
  7. [Category("Integration")]
  8. public class PreCommitHookTests : SingleRepositoryTestsBase
  9. {
  10. [SetUp]
  11. public override void SetUp()
  12. {
  13. base.SetUp();
  14. Repo.Init();
  15. File.WriteAllText(Path.Combine(Repo.Path, "dummy.txt"), "dummy");
  16. Repo.Add("dummy.txt");
  17. }
  18. [Test]
  19. public void Commit_HookThatPasses_AllowsCommit()
  20. {
  21. Repo.SetHook("precommit", "ok");
  22. var command = new CustomCommand("commit")
  23. .WithAdditionalArgument("-m")
  24. .WithAdditionalArgument("dummy");
  25. Repo.Execute(command);
  26. Assert.That(command.RawExitCode, Is.EqualTo(0));
  27. Assert.That(Repo.Log().Count(), Is.EqualTo(1));
  28. }
  29. [Test]
  30. public void Commit_HookThatFails_DoesNotAllowCommit()
  31. {
  32. Repo.SetHook("precommit", "fail");
  33. var command = new CustomCommand("commit")
  34. .WithAdditionalArgument("-m")
  35. .WithAdditionalArgument("dummy");
  36. Assert.Throws<MercurialExecutionException>(() => Repo.Execute(command));
  37. Assert.That(command.RawExitCode, Is.Not.EqualTo(0));
  38. Assert.That(Repo.Log().Count(), Is.EqualTo(0));
  39. }
  40. }
  41. }