PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Mercurial.Net.Tests/ObserverTests.cs

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