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