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

/Mercurial.Net.Tests/RemoveTests.cs

#
C# | 90 lines | 83 code | 7 blank | 0 comment | 1 complexity | 9cb5f94379443e9f3f94ff717bafa405 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using NUnit.Framework;
  5. namespace Mercurial.Tests
  6. {
  7. [TestFixture]
  8. public class RemoveTests : SingleRepositoryTestsBase
  9. {
  10. [TestCase((string)null)]
  11. [TestCase("")]
  12. [TestCase(" \t\n\r")]
  13. [Test]
  14. [Category("API")]
  15. public void Remove_NullOrEmptyPath_ThrowsArgumentNullException(string input)
  16. {
  17. Assert.Throws<ArgumentNullException>(() => Repo.Remove(input));
  18. }
  19. [Test]
  20. [Category("Integration")]
  21. public void Remove_UncommittedFileWithForce_RemovesFile()
  22. {
  23. Repo.Init();
  24. File.WriteAllText(Path.Combine(Repo.Path, "test.txt"), "contents");
  25. Repo.Add("test.txt");
  26. Repo.Remove(
  27. "test.txt", new RemoveCommand
  28. {
  29. ForceRemoval = true,
  30. });
  31. CollectionAssert.AreEqual(
  32. Repo.Status(),
  33. new[]
  34. {
  35. new FileStatus(FileState.Unknown, "test.txt"),
  36. });
  37. }
  38. [Test]
  39. [Category("Integration")]
  40. public void Remove_DeletedFileWithRecordDeletesOption_RemovesFile()
  41. {
  42. Repo.Init();
  43. WriteTextFileAndCommit(Repo, "test.txt", "dummy", "dummy", true);
  44. File.Delete(Path.Combine(Repo.Path, "test.txt"));
  45. Repo.Remove(
  46. new RemoveCommand
  47. {
  48. RecordDeletes = true,
  49. });
  50. FileStatus[] status = Repo.Status().ToArray();
  51. CollectionAssert.AreEqual(
  52. status, new[]
  53. {
  54. new FileStatus(FileState.Removed, "test.txt"),
  55. });
  56. }
  57. [Test]
  58. [Category("Integration")]
  59. public void Remove_FileDoesNotExist_ThrowsMercurialExecutionException()
  60. {
  61. Repo.Init();
  62. Assert.Throws<MercurialExecutionException>(() => Repo.Remove("test.txt"));
  63. }
  64. [Test]
  65. [Category("Integration")]
  66. public void Remove_InUninitializedRepository_ThrowsMercurialExecutionException()
  67. {
  68. File.WriteAllText(Path.Combine(Repo.Path, "test.txt"), "contents");
  69. Assert.Throws<MercurialExecutionException>(() => Repo.Remove("test.txt"));
  70. }
  71. [Test]
  72. [Category("Integration")]
  73. public void Remove_UncommittedFile_ThrowsMercurialExecutionException()
  74. {
  75. if (ClientExecutable.GetVersion() < new Version(1, 7, 0, 0))
  76. Assert.Ignore("This is not reported as a problem in Mercurial <1.7");
  77. Repo.Init();
  78. File.WriteAllText(Path.Combine(Repo.Path, "test.txt"), "contents");
  79. Repo.Add("test.txt");
  80. Assert.Throws<MercurialExecutionException>(() => Repo.Remove("test.txt"));
  81. }
  82. }
  83. }