PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Mercurial.Net.Tests/TagTests.cs

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