PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Mercurial.Net.Tests/TagTests.cs

#
C# | 138 lines | 117 code | 21 blank | 0 comment | 0 complexity | a035e9c89c46bb4eb679371037bffd47 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. using System.Linq;
  2. using NUnit.Framework;
  3. namespace Mercurial.Tests
  4. {
  5. [TestFixture]
  6. public class TagTests : SingleRepositoryTestsBase
  7. {
  8. [Test]
  9. [Category("Integration")]
  10. public void Tag_Changeset_AddsTagToChangeset()
  11. {
  12. Repo.Init();
  13. WriteTextFileAndCommit(Repo, "test.txt", "dummy", "dummy", true);
  14. Repo.Tag("tagname");
  15. Changeset[] log = Repo.Log().ToArray();
  16. Assert.That(log.Length, Is.EqualTo(2));
  17. Assert.That(log[1].Tags.FirstOrDefault(), Is.EqualTo("tagname"));
  18. }
  19. [Test]
  20. [Category("Integration")]
  21. public void Tag_MultipleTagsForChangeset_ProducesLogWithAllTagsPresent()
  22. {
  23. Repo.Init();
  24. WriteTextFileAndCommit(Repo, "test.txt", "dummy1", "dummy", true);
  25. Repo.Tag("test1", new TagCommand().WithRevision(0));
  26. Repo.Tag("test2", new TagCommand().WithRevision(0));
  27. Changeset[] log = Repo.Log().ToArray();
  28. Assert.That(log.Length, Is.EqualTo(3));
  29. CollectionAssert.AreEqual(
  30. log[2].Tags, new[]
  31. {
  32. "test1", "test2"
  33. });
  34. }
  35. [Test]
  36. [Category("Integration")]
  37. public void Tag_RemoveTagFromChangesetWithTag_RemovesTag()
  38. {
  39. Repo.Init();
  40. WriteTextFileAndCommit(Repo, "test.txt", "dummy1", "dummy", true);
  41. Repo.Tag("tagname");
  42. Changeset[] log = Repo.Log().ToArray();
  43. Assert.That(log[1].Tags.FirstOrDefault(), Is.EqualTo("tagname"));
  44. Repo.Tag(
  45. "tagname", new TagCommand
  46. {
  47. Action = TagAction.Remove
  48. });
  49. log = Repo.Log().ToArray();
  50. Assert.That(log[2].Tags.Count(), Is.EqualTo(0));
  51. }
  52. [Test]
  53. [Category("Integration")]
  54. public void Tag_RemoveTagWhenTagDoesNotExist_ThrowsMercurialExecutionException()
  55. {
  56. Repo.Init();
  57. WriteTextFileAndCommit(Repo, "test.txt", "dummy1", "dummy", true);
  58. Assert.Throws<MercurialExecutionException>(
  59. () => Repo.Tag(
  60. "tagname", new TagCommand
  61. {
  62. Action = TagAction.Remove
  63. }));
  64. }
  65. [Test]
  66. [Category("Integration")]
  67. public void Tag_UninitializedRepository_ThrowsMercurialExecutionException()
  68. {
  69. Assert.Throws<MercurialExecutionException>(() => Repo.Tag("tagname"));
  70. }
  71. [Test]
  72. [Category("Integration")]
  73. public void Tag_WithExistingTagAndNotReplacingExisting_ThrowsMercurialExecutionException()
  74. {
  75. Repo.Init();
  76. WriteTextFileAndCommit(Repo, "test.txt", "dummy1", "dummy", true);
  77. Repo.Tag("tagname");
  78. Assert.Throws<MercurialExecutionException>(() => Repo.Tag("tagname"));
  79. }
  80. [Test]
  81. [Category("Integration")]
  82. public void Tag_WithExistingTagAndReplacingExisting_MovesTagToNewChangeset()
  83. {
  84. Repo.Init();
  85. WriteTextFileAndCommit(Repo, "test.txt", "dummy1", "dummy", true);
  86. Repo.Tag("tagname");
  87. Repo.Tag(
  88. "tagname", new TagCommand
  89. {
  90. ReplaceExisting = true
  91. });
  92. Changeset[] log = Repo.Log().ToArray();
  93. Assert.That(log.Length, Is.EqualTo(3));
  94. Assert.That(log[1].Tags.FirstOrDefault(), Is.EqualTo("tagname"));
  95. Assert.That(log[2].Tags.Count(), Is.EqualTo(0));
  96. }
  97. [Test]
  98. [Category("Integration")]
  99. public void Tag_WithRevision_AppliesTagToCorrectChangeset()
  100. {
  101. Repo.Init();
  102. WriteTextFileAndCommit(Repo, "test.txt", "dummy1", "dummy", true);
  103. WriteTextFileAndCommit(Repo, "test.txt", "dummy2", "dummy", false);
  104. Changeset[] log = Repo.Log().ToArray();
  105. Assert.That(log.Length, Is.EqualTo(2));
  106. RevSpec rev = log[1].Revision;
  107. Repo.Tag(
  108. "tagname", new TagCommand
  109. {
  110. Revision = rev
  111. });
  112. log = Repo.Log().ToArray();
  113. Assert.That(log.Length, Is.EqualTo(3));
  114. Assert.That(log[2].Tags.FirstOrDefault(), Is.EqualTo("tagname"));
  115. }
  116. }
  117. }