PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Mercurial.Net.Tests/PullTests.cs

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