PageRenderTime 25ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/UnitTests/GitUI.Tests/CommandsDialogs/FormRemotesControllerTests.cs

https://github.com/gitextensions/gitextensions
C# | 125 lines | 103 code | 22 blank | 0 comment | 0 complexity | ba10cf351d81b55d0720f940afb2dc8e MD5 | raw file
Possible License(s): GPL-3.0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using FluentAssertions;
  4. using GitCommands.UserRepositoryHistory;
  5. using GitUI.CommandsDialogs;
  6. using NUnit.Framework;
  7. namespace GitUITests.CommandsDialogs
  8. {
  9. [TestFixture]
  10. public class FormRemotesControllerTests
  11. {
  12. private FormRemotesController _controller;
  13. [SetUp]
  14. public void Setup()
  15. {
  16. _controller = new FormRemotesController();
  17. }
  18. [TestCase(null)]
  19. [TestCase("")]
  20. [TestCase("\t")]
  21. public void RemoteDelete_should_not_throw_or_mutate_list_of_remotes_if_oldRemoteUrl_null_or_empty(string oldRemoteUrl)
  22. {
  23. List<Repository> remotes = new()
  24. {
  25. new Repository("a"),
  26. new Repository("b")
  27. };
  28. _controller.RemoteDelete(remotes, oldRemoteUrl);
  29. remotes.Count.Should().Be(2);
  30. }
  31. [Test]
  32. public void RemoteDelete_should_not_throw_or_mutate_list_of_remotes_if_oldRemoteUrl_not_in_list()
  33. {
  34. List<Repository> remotes = new()
  35. {
  36. new Repository("a"),
  37. new Repository("b")
  38. };
  39. _controller.RemoteDelete(remotes, "foo");
  40. remotes.Count.Should().Be(2);
  41. }
  42. [Test]
  43. public void RemoteDelete_should_remove_remotes_matching_oldRemoteUrl()
  44. {
  45. List<Repository> remotes = new()
  46. {
  47. new Repository("a"),
  48. new Repository("b")
  49. };
  50. _controller.RemoteDelete(remotes, "b");
  51. remotes.Count.Should().Be(1);
  52. remotes[0].Path.Should().Be("a");
  53. }
  54. [TestCase(null)]
  55. [TestCase("")]
  56. [TestCase("\t")]
  57. public void RemoteUpdate_should_not_throw_or_mutate_list_of_remotes_if_newRemoteUrl_null_or_empty(string newRemoteUrl)
  58. {
  59. List<Repository> remotes = new()
  60. {
  61. new Repository("a"),
  62. new Repository("b")
  63. };
  64. _controller.RemoteUpdate(remotes, "who cares", newRemoteUrl);
  65. remotes.Count.Should().Be(2);
  66. remotes[0].Path.Should().Be("a");
  67. remotes[1].Path.Should().Be("b");
  68. }
  69. [Test]
  70. public void RemoteDelete_should_replace_matching_oldRemoteUrl()
  71. {
  72. List<Repository> remotes = new()
  73. {
  74. new Repository("a"),
  75. new Repository("b")
  76. };
  77. _controller.RemoteUpdate(remotes, "a", "a1");
  78. remotes.Count.Should().Be(2);
  79. remotes.Select(r => r.Path).Should().BeEquivalentTo(new[] { "a1", "b" });
  80. }
  81. [Test]
  82. public void RemoteDelete_should_place_newRemoteUrl_as_first()
  83. {
  84. List<Repository> remotes = new()
  85. {
  86. new Repository("a"),
  87. new Repository("b"),
  88. new Repository("c")
  89. };
  90. _controller.RemoteUpdate(remotes, "c", "a1");
  91. remotes.Count.Should().Be(3);
  92. remotes[0].Path.Should().Be("a1");
  93. remotes[1].Path.Should().Be("a");
  94. remotes[2].Path.Should().Be("b");
  95. _controller.RemoteUpdate(remotes, null, "q");
  96. remotes.Count.Should().Be(4);
  97. remotes[0].Path.Should().Be("q");
  98. remotes[1].Path.Should().Be("a1");
  99. remotes[2].Path.Should().Be("a");
  100. remotes[3].Path.Should().Be("b");
  101. }
  102. }
  103. }