/IntegrationTests/UI.IntegrationTests/CommandsDialogs/FormPushTests.cs
C# | 94 lines | 79 code | 11 blank | 4 comment | 1 complexity | 18ef2554936ae4eaf341bac3ce621e1b MD5 | raw file
Possible License(s): GPL-3.0
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- using CommonTestUtils;
- using FluentAssertions;
- using GitCommands.Git;
- using GitUI;
- using GitUI.CommandsDialogs;
- using NUnit.Framework;
- namespace GitExtensions.UITests.CommandsDialogs
- {
- [Apartment(ApartmentState.STA)]
- public class FormPushTests
- {
- // Created once for the fixture
- private ReferenceRepository _referenceRepository;
- // Created once for each test
- private GitUICommands _commands;
- [SetUp]
- public void SetUp()
- {
- if (_referenceRepository is null)
- {
- _referenceRepository = new ReferenceRepository();
- }
- else
- {
- _referenceRepository.Reset();
- }
- _commands = new GitUICommands(_referenceRepository.Module);
- }
- [TearDown]
- public void TearDown()
- {
- }
- [OneTimeTearDown]
- public void OneTimeTearDown()
- {
- _referenceRepository.Dispose();
- }
- // Note: the DataBindings between ForcePushTags and ForcePushBranches or ckForceWithLease (depending on Git version) do not function in this test environment
- [TestCase(false, false, false, ForcePushOptions.DoNotForce)]
- [TestCase(false, true, false, ForcePushOptions.Force)]
- [TestCase(false, false, true, ForcePushOptions.Force)] // ForcePushTag requires normal force as with-lease is not allowed for tags
- [TestCase(false, true, true, ForcePushOptions.Force)]
- [TestCase(true, false, false, ForcePushOptions.ForceWithLease)] // would be ForcePushOptions.DoNotForce if DataBindings were working
- [TestCase(true, true, false, ForcePushOptions.Force)]
- [TestCase(true, false, true, ForcePushOptions.Force)] // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
- [TestCase(true, true, true, ForcePushOptions.Force)] // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
- public void Should_choose_correct_force_push_option_for_checkbox_state(
- bool forcePushBranchWithLeaseChecked, bool forcePushBranchChecked, bool forcePushTagChecked, ForcePushOptions forcePushOption)
- {
- RunFormTest(
- form =>
- {
- var accessor = form.GetTestAccessor();
- accessor.ForcePushTags.Checked = forcePushTagChecked;
- accessor.ckForceWithLease.Checked = forcePushBranchWithLeaseChecked;
- accessor.ForcePushBranches.Checked = forcePushBranchChecked;
- accessor.GetForcePushOption().Should().Be(forcePushOption);
- });
- }
- private void RunFormTest(Action<FormPush> testDriver)
- {
- RunFormTest(
- form =>
- {
- testDriver(form);
- return Task.CompletedTask;
- });
- }
- private void RunFormTest(Func<FormPush, Task> testDriverAsync)
- {
- UITest.RunForm(
- () =>
- {
- // False because we haven't performed any actions
- Assert.False(_commands.StartPushDialog(owner: null, pushOnShow: false, forceWithLease: false, out _));
- },
- testDriverAsync);
- }
- }
- }