PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Mercurial.Net.Tests/PullTests.cs

#
C# | 166 lines | 139 code | 27 blank | 0 comment | 0 complexity | 3dc5e9daae01f439e051aba7fc2a8e04 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using NUnit.Framework;
  5. namespace Mercurial.Tests
  6. {
  7. [TestFixture]
  8. public class PullTests : DualRepositoryTestsBase
  9. {
  10. #region Setup/Teardown
  11. public override void SetUp()
  12. {
  13. base.SetUp();
  14. Repo1.Init();
  15. Repo2.Init();
  16. }
  17. #endregion
  18. [TestCase((string)null)]
  19. [TestCase("")]
  20. [TestCase(" \n\r\t")]
  21. [Test]
  22. [Category("API")]
  23. public void Pull_WithNullOrEmptySource_ThrowsMercurialExecutionException(string source)
  24. {
  25. Assert.Throws<ArgumentNullException>(() => Repo2.Pull(source));
  26. }
  27. [TestCase(false)]
  28. [TestCase(true)]
  29. [Test]
  30. [Category("Integration")]
  31. public void Pull_WithUpdateOption_UpdatesAccordingly(bool doUpdate)
  32. {
  33. WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
  34. Repo2.Pull(
  35. Repo1.Path, new PullCommand
  36. {
  37. Update = doUpdate,
  38. });
  39. Assert.That(File.Exists(Path.Combine(Repo2.Path, "test1.txt")), Is.EqualTo(doUpdate));
  40. }
  41. [Test]
  42. [Category("Integration")]
  43. public void Pull_Branch_OnlyPullsThatBranch()
  44. {
  45. WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
  46. Repo2.Pull(Repo1.Path);
  47. Repo1.Branch("newbranch");
  48. WriteTextFileAndCommit(Repo1, "test2.txt", "initial contents", "2nd commit", true);
  49. Repo1.Update(0);
  50. WriteTextFileAndCommit(Repo1, "test3.txt", "initial contents", "3rd commit", true);
  51. Changeset[] log = Repo2.Log().ToArray();
  52. Assert.That(log.Length, Is.EqualTo(1));
  53. Repo2.Pull(
  54. Repo1.Path, new PullCommand
  55. {
  56. Branches =
  57. {
  58. "newbranch",
  59. },
  60. });
  61. log = Repo2.Log().ToArray();
  62. Assert.That(log.Length, Is.EqualTo(2));
  63. }
  64. [Test]
  65. [Category("Integration")]
  66. public void Pull_ForceIntoUnrelatedNonEmptyRepository_PerformsPull()
  67. {
  68. WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
  69. WriteTextFileAndCommit(Repo2, "test2.txt", "initial contents", "initial commit", true);
  70. Repo2.Pull(
  71. Repo1.Path, new PullCommand
  72. {
  73. Force = true,
  74. });
  75. Assert.That(Repo2.Log().Count(), Is.EqualTo(2));
  76. }
  77. [Test]
  78. [Category("Integration")]
  79. public void Pull_FromClone_GetsNewChangesets()
  80. {
  81. Repository clone = GetRepository();
  82. WriteTextFileAndCommit(Repo1, "test1.txt", "dummy contents", "dummy", true);
  83. clone.Clone(Repo1.Path);
  84. Assert.That(clone.Log().Count(), Is.EqualTo(1));
  85. WriteTextFileAndCommit(Repo1, "test2.txt", "dummy contents", "dummy", true);
  86. clone.Pull();
  87. Assert.That(clone.Log().Count(), Is.EqualTo(2));
  88. }
  89. [Test]
  90. [Category("Integration")]
  91. public void Pull_FromOtherWithRevisionSpecification_OnlyPullsInRelevantChanges()
  92. {
  93. WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
  94. WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents", "2nd commit", false);
  95. WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents again", "3rd commit", false);
  96. Repo2.Pull(
  97. Repo1.Path, new PullCommand
  98. {
  99. Revisions =
  100. {
  101. RevSpec.Single(1),
  102. },
  103. });
  104. Changeset[] pulledChangesets = Repo2.Log().OrderBy(c => c.RevisionNumber).ToArray();
  105. Changeset[] originalChangesets = Repo1.Log(
  106. new LogCommand
  107. {
  108. Revisions =
  109. {
  110. RevSpec.Range(0, 1),
  111. },
  112. }).OrderBy(c => c.RevisionNumber).ToArray();
  113. CollectionAssert.AreEqual(pulledChangesets, originalChangesets);
  114. }
  115. [Test]
  116. [Category("Integration")]
  117. public void Pull_FromOther_PullsInAllChanges()
  118. {
  119. WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
  120. WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents", "2nd commit", false);
  121. Repo2.Pull(Repo1.Path);
  122. CollectionAssert.AreEqual(Repo2.Log(), Repo1.Log());
  123. }
  124. [Test]
  125. [Category("Integration")]
  126. public void Pull_IntoUnrelatedNonEmptyRepository_ThrowsMercurialExecutionException()
  127. {
  128. WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
  129. WriteTextFileAndCommit(Repo2, "test2.txt", "initial contents", "initial commit", true);
  130. Assert.Throws<MercurialExecutionException>(() => Repo2.Pull(Repo1.Path));
  131. }
  132. [Test]
  133. [Category("Integration")]
  134. public void Pull_WithoutSource_ThrowsMercurialExecutionException()
  135. {
  136. Assert.Throws<MercurialExecutionException>(() => Repo2.Pull());
  137. }
  138. }
  139. }