PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/Mercurial.Net.Tests/ObserverTests.cs

#
C# | 110 lines | 91 code | 18 blank | 1 comment | 0 complexity | 72c3db2b9fe141368041c7099d64ffda MD5 | raw file
  1using System.Collections.Generic;
  2using System.IO;
  3using NUnit.Framework;
  4
  5namespace Mercurial.Tests
  6{
  7    [TestFixture]
  8    public class ObserverTests : SingleRepositoryTestsBase, IMercurialCommandObserver
  9    {
 10        #region Setup/Teardown
 11
 12        public override void SetUp()
 13        {
 14            base.SetUp();
 15
 16            _Output = new List<string>();
 17            _ErrorOutput = new List<string>();
 18            _ExecutingWasCalled = false;
 19            _ExecutedWasCalled = false;
 20        }
 21
 22        #endregion
 23
 24        private List<string> _Output;
 25        private List<string> _ErrorOutput;
 26        private bool _ExecutingWasCalled;
 27        private bool _ExecutedWasCalled;
 28
 29        private void CallLogMethodWithObserver()
 30        {
 31            try
 32            {
 33                Repo.Log(
 34                    new LogCommand
 35                    {
 36                        Observer = this,
 37                    });
 38            }
 39            catch (MercurialExecutionException)
 40            {
 41                // Swallow this one
 42            }
 43        }
 44
 45        public void Output(string line)
 46        {
 47            _Output.Add(line);
 48        }
 49
 50        public void ErrorOutput(string line)
 51        {
 52            _ErrorOutput.Add(line);
 53        }
 54
 55        public void Executing(string command, string arguments)
 56        {
 57            _ExecutingWasCalled = true;
 58        }
 59
 60        public void Executed(string command, string arguments, int exitCode, string output, string errorOutput)
 61        {
 62            _ExecutedWasCalled = true;
 63        }
 64
 65        [Test]
 66        [Category("Integration")]
 67        public void Log_AgainstInitializedRepositoryWithOneChangeset_ProducesStandardOutput()
 68        {
 69            Repo.Init();
 70            File.WriteAllText(Path.Combine(Repo.Path, "test1.txt"), "dummy content");
 71            Repo.Commit(
 72                "dummy", new CommitCommand
 73                {
 74                    AddRemove = true,
 75                });
 76            CallLogMethodWithObserver();
 77
 78            Assert.That(_Output.Count, Is.GreaterThan(0));
 79        }
 80
 81        [Test]
 82        [Category("Integration")]
 83        public void Log_AgainstUninitializedRepository_InvokesExecutedObserverMethod()
 84        {
 85            Repo.Init();
 86            CallLogMethodWithObserver();
 87
 88            Assert.That(_ExecutedWasCalled, Is.True);
 89        }
 90
 91        [Test]
 92        [Category("Integration")]
 93        public void Log_AgainstUninitializedRepository_InvokesExecutingObserverMethod()
 94        {
 95            Repo.Init();
 96            CallLogMethodWithObserver();
 97
 98            Assert.That(_ExecutingWasCalled, Is.True);
 99        }
100
101        [Test]
102        [Category("Integration")]
103        public void Log_AgainstUninitializedRepository_ProducesErrorOutput()
104        {
105            CallLogMethodWithObserver();
106
107            Assert.That(_ErrorOutput.Count, Is.GreaterThan(0));
108        }
109    }
110}