PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/IntegrationTests/UI.IntegrationTests/CommandsDialogs/FormPushTests.cs

https://github.com/gitextensions/gitextensions
C# | 94 lines | 79 code | 11 blank | 4 comment | 1 complexity | 18ef2554936ae4eaf341bac3ce621e1b MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using CommonTestUtils;
  5. using FluentAssertions;
  6. using GitCommands.Git;
  7. using GitUI;
  8. using GitUI.CommandsDialogs;
  9. using NUnit.Framework;
  10. namespace GitExtensions.UITests.CommandsDialogs
  11. {
  12. [Apartment(ApartmentState.STA)]
  13. public class FormPushTests
  14. {
  15. // Created once for the fixture
  16. private ReferenceRepository _referenceRepository;
  17. // Created once for each test
  18. private GitUICommands _commands;
  19. [SetUp]
  20. public void SetUp()
  21. {
  22. if (_referenceRepository is null)
  23. {
  24. _referenceRepository = new ReferenceRepository();
  25. }
  26. else
  27. {
  28. _referenceRepository.Reset();
  29. }
  30. _commands = new GitUICommands(_referenceRepository.Module);
  31. }
  32. [TearDown]
  33. public void TearDown()
  34. {
  35. }
  36. [OneTimeTearDown]
  37. public void OneTimeTearDown()
  38. {
  39. _referenceRepository.Dispose();
  40. }
  41. // Note: the DataBindings between ForcePushTags and ForcePushBranches or ckForceWithLease (depending on Git version) do not function in this test environment
  42. [TestCase(false, false, false, ForcePushOptions.DoNotForce)]
  43. [TestCase(false, true, false, ForcePushOptions.Force)]
  44. [TestCase(false, false, true, ForcePushOptions.Force)] // ForcePushTag requires normal force as with-lease is not allowed for tags
  45. [TestCase(false, true, true, ForcePushOptions.Force)]
  46. [TestCase(true, false, false, ForcePushOptions.ForceWithLease)] // would be ForcePushOptions.DoNotForce if DataBindings were working
  47. [TestCase(true, true, false, ForcePushOptions.Force)]
  48. [TestCase(true, false, true, ForcePushOptions.Force)] // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
  49. [TestCase(true, true, true, ForcePushOptions.Force)] // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
  50. public void Should_choose_correct_force_push_option_for_checkbox_state(
  51. bool forcePushBranchWithLeaseChecked, bool forcePushBranchChecked, bool forcePushTagChecked, ForcePushOptions forcePushOption)
  52. {
  53. RunFormTest(
  54. form =>
  55. {
  56. var accessor = form.GetTestAccessor();
  57. accessor.ForcePushTags.Checked = forcePushTagChecked;
  58. accessor.ckForceWithLease.Checked = forcePushBranchWithLeaseChecked;
  59. accessor.ForcePushBranches.Checked = forcePushBranchChecked;
  60. accessor.GetForcePushOption().Should().Be(forcePushOption);
  61. });
  62. }
  63. private void RunFormTest(Action<FormPush> testDriver)
  64. {
  65. RunFormTest(
  66. form =>
  67. {
  68. testDriver(form);
  69. return Task.CompletedTask;
  70. });
  71. }
  72. private void RunFormTest(Func<FormPush, Task> testDriverAsync)
  73. {
  74. UITest.RunForm(
  75. () =>
  76. {
  77. // False because we haven't performed any actions
  78. Assert.False(_commands.StartPushDialog(owner: null, pushOnShow: false, forceWithLease: false, out _));
  79. },
  80. testDriverAsync);
  81. }
  82. }
  83. }