/Mercurial.Net.Tests/Hooks/PreCommitHookTests.cs
# · C# · 49 lines · 41 code · 8 blank · 0 comment · 0 complexity · 6ec335a81c2a78a33f9d78dbb07c1aa3 MD5 · raw file
- using System.IO;
- using System.Linq;
- using NUnit.Framework;
-
- namespace Mercurial.Tests.Hooks
- {
- [TestFixture]
- [Category("Integration")]
- public class PreCommitHookTests : SingleRepositoryTestsBase
- {
- [SetUp]
- public override void SetUp()
- {
- base.SetUp();
-
- Repo.Init();
- File.WriteAllText(Path.Combine(Repo.Path, "dummy.txt"), "dummy");
- Repo.Add("dummy.txt");
- }
-
- [Test]
- public void Commit_HookThatPasses_AllowsCommit()
- {
- Repo.SetHook("precommit", "ok");
-
- var command = new CustomCommand("commit")
- .WithAdditionalArgument("-m")
- .WithAdditionalArgument("dummy");
- Repo.Execute(command);
-
- Assert.That(command.RawExitCode, Is.EqualTo(0));
- Assert.That(Repo.Log().Count(), Is.EqualTo(1));
- }
-
- [Test]
- public void Commit_HookThatFails_DoesNotAllowCommit()
- {
- Repo.SetHook("precommit", "fail");
-
- var command = new CustomCommand("commit")
- .WithAdditionalArgument("-m")
- .WithAdditionalArgument("dummy");
- Assert.Throws<MercurialExecutionException>(() => Repo.Execute(command));
-
- Assert.That(command.RawExitCode, Is.Not.EqualTo(0));
- Assert.That(Repo.Log().Count(), Is.EqualTo(0));
- }
- }
- }