PageRenderTime 130ms CodeModel.GetById 111ms app.highlight 15ms RepoModel.GetById 3ms app.codeStats 0ms

/Mercurial.Net.Tests/SummaryTests.cs

#
C# | 255 lines | 200 code | 55 blank | 0 comment | 0 complexity | 278221f28c18278bedcbc6ab6b5115c0 MD5 | raw file
  1using System;
  2using System.IO;
  3using NUnit.Framework;
  4
  5namespace Mercurial.Tests
  6{
  7    [TestFixture]
  8    public class SummaryTests : MergeResolveTests
  9    {
 10        [Test]
 11        [Category("Integration")]
 12        public void Summary_NoRepository_ThrowsMercurialExecutionException()
 13        {
 14            Assert.Throws<MercurialExecutionException>(() => Repo.Summary());
 15        }
 16
 17        [Test]
 18        [Category("Integration")]
 19        public void Summary_InitializedRepo_HasNoNewChangesets()
 20        {
 21            Repo.Init();
 22
 23            RepositorySummary summary = Repo.Summary();
 24
 25            Assert.That(summary.NumberOfNewChangesets, Is.EqualTo(0));
 26        }
 27
 28        [Test]
 29        [Category("Integration")]
 30        public void Summary_InitializedRepo_ContainsRawOutput()
 31        {
 32            Repo.Init();
 33
 34            RepositorySummary summary = Repo.Summary();
 35
 36            Assert.That(summary.RawOutput, Is.StringContaining("(clean)"));
 37        }
 38
 39        [Test]
 40        [Category("Integration")]
 41        public void Summary_RepoAtHeadMinusOne_HasOneNewChangeset()
 42        {
 43            CreateRepoWithTwoChangesets();
 44            Repo.Update(0);
 45
 46            RepositorySummary summary = Repo.Summary();
 47
 48            Assert.That(summary.NumberOfNewChangesets, Is.EqualTo(1));
 49        }
 50
 51        [Test]
 52        [Category("Integration")]
 53        public void Summary_RepoAtHeadMinusOne_UpdateIsPossible()
 54        {
 55            CreateRepoWithTwoChangesets();
 56            Repo.Update(0);
 57
 58            RepositorySummary summary = Repo.Summary();
 59
 60            Assert.That(summary.UpdatePossible, Is.True);
 61        }
 62
 63        [Test]
 64        [Category("Integration")]
 65        public void Summary_InitializedRepo_ReportsDefaultBranch()
 66        {
 67            Repo.Init();
 68
 69            RepositorySummary summary = Repo.Summary();
 70
 71            Assert.That(summary.Branch, Is.EqualTo("default"));
 72        }
 73
 74        [Test]
 75        [Category("Integration")]
 76        public void Summary_NewButUncommittedBranchChange_ReturnsNewBranchName()
 77        {
 78            Repo.Init();
 79            Repo.Branch("newbranch");
 80
 81            RepositorySummary summary = Repo.Summary();
 82
 83            Assert.That(summary.Branch, Is.EqualTo("newbranch"));
 84        }
 85
 86        [Test]
 87        [Category("Integration")]
 88        public void Summary_InitializedRepo_ReportsNullParent()
 89        {
 90            Repo.Init();
 91
 92            RepositorySummary summary = Repo.Summary();
 93
 94            CollectionAssert.AreEqual(
 95                new[]
 96                {
 97                    -1,
 98                }, summary.ParentRevisionNumbers);
 99        }
100
101        [Test]
102        [Category("Integration")]
103        public void Summary_RepoAtChangesetZero_ReportsParentIsZero()
104        {
105            CreateRepoWithTwoChangesets();
106            Repo.Update(0);
107
108            RepositorySummary summary = Repo.Summary();
109
110            CollectionAssert.AreEqual(
111                new[]
112                {
113                    0,
114                }, summary.ParentRevisionNumbers);
115        }
116
117        [Test]
118        [Category("Integration")]
119        public void Summary_InitializedRepo_ReportsNoModifiedFiles()
120        {
121            Repo.Init();
122
123            RepositorySummary summary = Repo.Summary();
124
125            Assert.That(summary.NumberOfModifiedFiles, Is.EqualTo(0));
126        }
127
128        [Test]
129        [Category("Integration")]
130        public void Summary_NewFile_ReportsUnknownFile()
131        {
132            Repo.Init();
133            File.WriteAllText(Path.Combine(Repo.Path, "dummy.txt"), "dummy");
134
135            RepositorySummary summary = Repo.Summary();
136
137            Assert.That(summary.NumberOfUnknownFiles, Is.EqualTo(1));
138        }
139
140        [Test]
141        [Category("Integration")]
142        public void Summary_ChangeToTrackedFile_ReportsModifiedFile()
143        {
144            Repo.Init();
145            WriteTextFileAndCommit(Repo, "dummy.txt", "123", "123", true);
146            File.WriteAllText(Path.Combine(Repo.Path, "dummy.txt"), "dummy");
147
148            RepositorySummary summary = Repo.Summary();
149
150            Assert.That(summary.NumberOfModifiedFiles, Is.EqualTo(1));
151        }
152
153        [Test]
154        [Category("Integration")]
155        public void Summary_InitializedRepo_ReportsNoUnknownFiles()
156        {
157            Repo.Init();
158
159            RepositorySummary summary = Repo.Summary();
160
161            Assert.That(summary.NumberOfUnknownFiles, Is.EqualTo(0));
162        }
163
164        [Test]
165        [Category("Integration")]
166        public void Summary_InitializedRepo_ReportsNoUnresolvedFiles()
167        {
168            Repo.Init();
169
170            RepositorySummary summary = Repo.Summary();
171
172            Assert.That(summary.NumberOfUnresolvedFiles, Is.EqualTo(0));
173        }
174
175        [Test]
176        [Category("Integration")]
177        public void Summary_InitializedRepo_ReportsNotInMerge()
178        {
179            Repo.Init();
180
181            RepositorySummary summary = Repo.Summary();
182
183            Assert.That(summary.IsInMerge, Is.False);
184        }
185
186        [Test]
187        [Category("Integration")]
188        public void Summary_MergeWithConflicts_ReportsConflicts()
189        {
190            CreateRepositoryWithMergeConflicts();
191
192            try
193            {
194                Repo.Merge(new MergeCommand()
195                    .WithMergeTool(MergeTools.InternalMerge));
196            }
197            catch (NotSupportedException)
198            {
199                Assert.Inconclusive("Merge tool not supported in this version");
200            }
201
202            RepositorySummary summary = Repo.Summary();
203
204            Assert.That(summary.NumberOfUnresolvedFiles, Is.EqualTo(1));
205        }
206
207        [Test]
208        [Category("Integration")]
209        public void Summary_Merge_ReportsInMerge()
210        {
211            CreateRepositoryWithMergeConflicts();
212            try
213            {
214                Repo.Merge(new MergeCommand()
215                    .WithMergeTool(MergeTools.InternalMerge));
216            }
217            catch (NotSupportedException)
218            {
219                Assert.Inconclusive("Merge tool not supported in this version");
220            }
221
222            RepositorySummary summary = Repo.Summary();
223
224            Assert.That(summary.IsInMerge, Is.True);
225        }
226
227        [Test]
228        [Category("Integration")]
229        public void Summary_Merge_ReportsCorrectParents()
230        {
231            CreateRepositoryWithMergeConflicts();
232
233            try
234            {
235                Repo.Merge(new MergeCommand()
236                    .WithMergeTool(MergeTools.InternalMerge));
237            }
238            catch (NotSupportedException)
239            {
240                Assert.Inconclusive("Merge tool not supported in this version");
241            }
242
243            RepositorySummary summary = Repo.Summary();
244
245            CollectionAssert.AreEqual(new[] { 2, 1 }, summary.ParentRevisionNumbers);
246        }
247
248        private void CreateRepoWithTwoChangesets()
249        {
250            Repo.Init();
251            WriteTextFileAndCommit(Repo, "dummy.txt", "1", "1", true);
252            WriteTextFileAndCommit(Repo, "dummy.txt", "2", "2", false);
253        }
254    }
255}