PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

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