PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Mercurial.Net.Tests/VerifyTests.cs

#
C# | 68 lines | 60 code | 8 blank | 0 comment | 0 complexity | f682a4015fff892facaabbc735fe7dbf MD5 | raw file
 1using System.IO;
 2using NUnit.Framework;
 3
 4namespace Mercurial.Tests
 5{
 6    [TestFixture]
 7    public class VerifyTests : SingleRepositoryTestsBase
 8    {
 9        [Test]
10        [Category("Integration")]
11        public void Verify_CorruptFilelog_ThrowsMercurialExecutionException()
12        {
13            Repo.Init();
14            WriteTextFileAndCommit(Repo, "test.txt", "dummy", "dummy", true);
15            string fileName = PathEx.Combine(Repo.Path, ".hg", "store", "data", "test.txt.i");
16            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
17            {
18                stream.Position = stream.Length - 1;
19                int b = stream.ReadByte();
20                stream.Position = stream.Length - 1;
21                stream.WriteByte((byte)(b ^ 0xff));
22            }
23
24            Assert.Throws<MercurialExecutionException>(() => Repo.Verify());
25        }
26
27        [Test]
28        [Category("Integration")]
29        public void Verify_MissingFilelog_ThrowsMercurialExecutionException()
30        {
31            Repo.Init();
32            WriteTextFileAndCommit(Repo, "test.txt", "dummy", "dummy", true);
33            File.Delete(PathEx.Combine(Repo.Path, ".hg", "store", "data", "test.txt.i"));
34
35            Assert.Throws<MercurialExecutionException>(() => Repo.Verify());
36        }
37
38        [Test]
39        [Category("Integration")]
40        public void Verify_NoProblems_ReturnsWithoutThrowingException()
41        {
42            Repo.Init();
43            Repo.Verify();
44        }
45
46        [Test]
47        [Category("Integration")]
48        public void Verify_NoRepository_ThrowsMercurialExecutionException()
49        {
50            Assert.Throws<MercurialExecutionException>(() => Repo.Verify());
51        }
52
53        [Test]
54        [Category("Integration")]
55        public void Verify_TruncatedFilelog_ThrowsMercurialExecutionException()
56        {
57            Repo.Init();
58            WriteTextFileAndCommit(Repo, "test.txt", "dummy", "dummy", true);
59            string fileName = PathEx.Combine(Repo.Path, ".hg", "store", "data", "test.txt.i");
60            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
61            {
62                stream.SetLength(stream.Length - 1);
63            }
64
65            Assert.Throws<MercurialExecutionException>(() => Repo.Verify());
66        }
67    }
68}