Source

hgAssist / HgCliTests / HgTest.cs

using System;
using NUnit.Framework;
using HgCli;

namespace HgCliTests
{
    [TestFixture]
    class HgTest
    {
        [Test]
        public void ParseVersion()
        {
            var hg = new Hg();

            var given = "Mercurial Distributed SCM (version 1.5.2)";
            var expected = new Version(1, 5, 2);

            Assert.That(hg.ParseVersion(given), Is.EqualTo(expected));
        }

        [Test]
        public void ParseVersion1_9_tip()
        {
            var hg = new Hg();

            var given = "Mercurial Distributed SCM (version 1.9+10-e9264b45237d)";
            var expected = new Version(1, 9, 10);

            Assert.That(hg.ParseVersion(given), Is.EqualTo(expected));
        }

        [Test]
        public void ParseSummaryOnlyIncoming()
        {
            var hg = new Hg();

            var given = @"parent: 3:b15b4d357e6f tip
 Merge
branch: default
commit: (clean)
update: (current)
remote: 1 or more incoming";

            var result = hg.ParseSummary(given);
            Assert.That(result.Incoming, Is.EqualTo(1));
            Assert.That(result.IsIncoming, Is.True);
        }

        [Test]
        public void ParseSummaryOnlyOutgoing()
        {
            var hg = new Hg();

            var given = @"parent: 1:0fce5ec7e7cc
 slave
branch: default
commit: (clean)
update: 1 new changesets, 2 branch heads (merge)
remote: 2 outgoing";

            var result = hg.ParseSummary(given);

            Assert.That(result.Incoming, Is.EqualTo(0));
            Assert.That(result.IsIncoming, Is.False);
            Assert.That(result.Outgoing, Is.EqualTo(2));
            Assert.That(result.IsOutgoing, Is.True);
        }

        [Test]
        public void ParseSummaryIncomingAndOutgoing()
        {
            var hg = new Hg();

            var given = @"parent: 1:0fce5ec7e7cc tip
 slave
branch: default
commit: (clean)
update: (current)
remote: 1 or more incoming, 2 outgoing";

            var result = hg.ParseSummary(given);

            Assert.That(result.Incoming, Is.EqualTo(1));
            Assert.That(result.IsIncoming, Is.True);
            Assert.That(result.Outgoing, Is.EqualTo(2));
            Assert.That(result.IsOutgoing, Is.True);
        }

        [Test]
        public void ParseIncoming()
        {
            var hg = new Hg();

            var given = @"comparing with c:\projects\test\master
searching for changes
changeset:   5:bbbe7fbdc81b
user:        meze
date:        Fri Aug 27 22:59:30 2010 +0400
summary:     88

changeset:   6:9e9678a6424c
tag:         tip
user:        meze
date:        Fri Aug 27 22:59:42 2010 +0400
summary:     88";

            var result = hg.ParseIncoming(given);

            Assert.That(result, Is.EqualTo(2));
        }

        [Test]
        public void ParseIncomingNone()
        {
            var hg = new Hg();

            var given = @"comparing with ssh://hg@test/hgassist
searching for changes
no changes found";

            var result = hg.ParseIncoming(given);

            Assert.That(result, Is.EqualTo(0));
        }

        [Test]
        public void ParseKeyRefused()
        {
            var hg = new Hg();

            var given = @"parent: 179:b773b8ea2919
 update HG path in HgCli. Adding more comments
branch: default
commit: (clean)
update: (current)
remote: Server refused our key
abort: no suitable response from remote hg!";

            Assert.Throws<KeyRefusedException>(
                () => hg.ParseSummary(given)
            );
        }

        [Test]
        public void HostDoesNotExist()
        {
            var given = @"parent: 179:b773b8ea2919
 update HG path in HgCli. Adding more comments
branch: default
commit: (clean)
update: (current)
remote: Unable to open connection:
remote: Host does not existabort: no suitable response from remote hg!";

            var hg = new Hg();

            Assert.Throws<HostDoesNotExistException>(
                () => hg.ParseSummary(given)
            );
        }

        [Test]
        public void NoSuitableResponseFromRemote()
        {
            var given = @"parent: 199:0ad7943571d4 tip
forgot to commit some changes
branch: default
commit: (clean)
update: (current)
abort: no suitable response from remote hg!";

            var hg = new Hg();

            Assert.Throws<NoSuitableResponseFromRemote>(
                () => hg.ParseSummary(given)
            );
        }
    }
}