示例#1
0
        private void RunFormTest(Func <FormCommit, Task> testDriverAsync, CommitKind commitKind = CommitKind.Normal)
        {
            UITest.RunForm(
                () =>
            {
                switch (commitKind)
                {
                case CommitKind.Normal:
                    Assert.True(_commands.StartCommitDialog(owner: null));
                    break;

                case CommitKind.Squash:
                    Assert.True(_commands.StartSquashCommitDialog(owner: null, _referenceRepository.Module.GetRevision()));
                    break;

                case CommitKind.Fixup:
                    Assert.True(_commands.StartFixupCommitDialog(owner: null, _referenceRepository.Module.GetRevision()));
                    break;

                default:
                    throw new ArgumentException($"Unsupported commit kind: {commitKind}", nameof(commitKind));
                }
            },
                testDriverAsync);
        }
        private void RunSetAndApplyBranchFilterTest(string initialFilter, Action <RevisionGridControl> runTest)
        {
            UITest.RunForm <FormBrowse>(
                showForm: () => _commands.StartBrowseDialog(owner: null).Should().BeTrue(),
                runTestAsync: async formBrowse =>
            {
                DoEvents();

                // wait for the revisions to be loaded
                await AsyncTestHelper.JoinPendingOperationsAsync(AsyncTestHelper.UnexpectedTimeout);

                formBrowse.RevisionGridControl.SetAndApplyBranchFilter(initialFilter);

                // Refresh the grid, to reflect the filter
                RefreshRevisions(formBrowse.RevisionGridControl);

                try
                {
                    runTest(formBrowse.RevisionGridControl);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{runTest.Method.Name} failed: {ex.Demystify()}");
                    Console.WriteLine(_referenceRepository.Module.GitExecutable.GetOutput("status"));
                    throw;
                }
            });
        }
        private void Should_preserve_encoding(Encoding encoding)
        {
            Assert.AreEqual(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), _commands.Module.FilesEncoding);

            string filePath = Path.Combine(_referenceRepository.Module.WorkingDir, Path.GetRandomFileName());

            try
            {
                File.WriteAllText(filePath, "Hello↔world", encoding);

                UITest.RunForm <FormEditor>(
                    () =>
                {
                    using (var formEditor = new FormEditor(_commands, filePath, showWarning: false))
                    {
                        formEditor.ShowDialog();
                    }
                },
                    form =>
                {
                    var fileViewerInternal = form.GetTestAccessor().FileViewer.GetTestAccessor().FileViewerInternal;
                    fileViewerInternal.SetText(fileViewerInternal.GetText() + "!", openWithDifftool: null, isDiff: false);
                    form.GetTestAccessor().SaveChanges();
                    return(Task.CompletedTask);
                });

                Assert.That(File.ReadAllBytes(filePath), Is.EquivalentTo(encoding.GetPreamble().Concat(encoding.GetBytes("Hello↔world!"))));
            }
            finally
            {
                File.Delete(filePath);
            }
        }
示例#4
0
        private void RunSetAndApplyBranchFilterTest(string initialFilter, Action <RevisionGridControl> runTest)
        {
            // Disable artificial commits as they appear to destabilise these tests
            AppSettings.RevisionGraphShowArtificialCommits = false;

            UITest.RunForm <FormBrowse>(
                showForm: () => _commands.StartBrowseDialog(owner: null).Should().BeTrue(),
                runTestAsync: async formBrowse =>
            {
                DoEvents();

                // wait for the revisions to be loaded
                await AsyncTestHelper.JoinPendingOperationsAsync(AsyncTestHelper.UnexpectedTimeout);

                formBrowse.RevisionGridControl.SetSelectedRevision(ObjectId.Parse(_headCommit));

                formBrowse.RevisionGridControl.SetAndApplyBranchFilter(initialFilter);

                // wait for the revisions to be loaded
                await AsyncTestHelper.JoinPendingOperationsAsync(AsyncTestHelper.UnexpectedTimeout);

                try
                {
                    runTest(formBrowse.RevisionGridControl);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{runTest.Method.Name} failed: {ex.Demystify()}");
                    Console.WriteLine(_referenceRepository.Module.GitExecutable.GetOutput("status"));
                    throw;
                }
            });
        }
示例#5
0
 private void RunFormTest(Func <FormBrowse, Task> testDriverAsync)
 {
     UITest.RunForm(
         () =>
     {
         Assert.True(_commands.StartBrowseDialog(owner: null));
     },
         testDriverAsync);
 }
示例#6
0
 private void RunFormTest(Func <FormClone, Task> testDriverAsync)
 {
     UITest.RunForm(
         () =>
     {
         _commands.StartCloneDialog(owner: null, url: null);
     },
         testDriverAsync);
 }
 private void RunFormTest(Func <BugReportForm, Task> testDriverAsync, SerializableException exception, string environmentInfo, DialogResult expected)
 {
     UITest.RunForm(
         () =>
     {
         Assert.AreEqual(expected, _form.ShowDialog(owner: null, exception, environmentInfo, canIgnore: true, showIgnore: false, focusDetails: false));
     },
         testDriverAsync);
 }
示例#8
0
 private void RunFormTest(Func <FormInit, Task> testDriverAsync, string path)
 {
     UITest.RunForm(
         () =>
     {
         Assert.True(_commands.StartInitializeDialog(owner: null, path));
     },
         testDriverAsync);
 }
 private void RunFormTest(Func <FormPull, Task> testDriverAsync, string remoteBranch, string remote, AppSettings.PullAction pullAction)
 {
     UITest.RunForm(
         () =>
     {
         // False because we haven't performed any actions
         Assert.False(_commands.StartPullDialog(owner: null, remoteBranch: remoteBranch, remote: remote, pullAction: pullAction));
     },
         testDriverAsync);
 }
 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);
 }
示例#11
0
 private void RunFormTest(Func <FormRebase, Task> testDriverAsync, string from, string to,
                          string onto, bool interactive, bool startRebaseImmediately)
 {
     UITest.RunForm(
         () =>
     {
         _commands.StartRebaseDialog(owner: null, from, to, onto, interactive, startRebaseImmediately);
     },
         testDriverAsync);
 }
示例#12
0
 private static void RunFormTest(Action <FormBrowse> testDriver, GitUICommands commands)
 {
     UITest.RunForm(
         showForm: () => commands.StartBrowseDialog(owner: null).Should().BeTrue(),
         (FormBrowse form) =>
     {
         testDriver(form);
         return(Task.CompletedTask);
     });
 }
        private void RunFormTest(Func <FormBrowse, Task> testDriverAsync)
        {
            // Needed for FormBrowse, ScriptOptionsParser
            ManagedExtensibility.Initialise(new[]
            {
                typeof(GitUI.GitExtensionsForm).Assembly,
                typeof(GitCommands.GitModule).Assembly
            });

            UITest.RunForm(
                showForm: () => _uiCommands.StartBrowseDialog(owner: null).Should().BeTrue(),
                testDriverAsync);
        }
示例#14
0
        public void Should_display_detached_head_info_in_statusbar()
        {
            using (var repository = new ReferenceRepository(new GitModuleTestHelper("detached_head")))
            {
                var commands = new GitUICommands(repository.Module);
                repository.CheckoutRevision();
                UITest.RunForm <FormCommit>(
                    () => { Assert.True(commands.StartCommitDialog(owner: null)); },
                    form =>
                {
                    var currentBranchNameLabelStatus = form.GetTestAccessor().CurrentBranchNameLabelStatus;
                    var remoteNameLabelStatus        = form.GetTestAccessor().RemoteNameLabelStatus;

                    Assert.AreEqual("(no branch)", currentBranchNameLabelStatus.Text);
                    Assert.AreEqual(string.Empty, remoteNameLabelStatus.Text);
                    return(Task.CompletedTask);
                });
            }
        }
示例#15
0
        public void Should_display_branch_and_no_remote_info_in_statusbar()
        {
            using (var repository = new ReferenceRepository(new GitModuleTestHelper("branch_and_no_remote")))
            {
                var commands = new GitUICommands(repository.Module);
                repository.CheckoutMaster();
                UITest.RunForm <FormCommit>(
                    () => { Assert.True(commands.StartCommitDialog(owner: null)); },
                    form =>
                {
                    var currentBranchNameLabelStatus = form.GetTestAccessor().CurrentBranchNameLabelStatus;
                    var remoteNameLabelStatus        = form.GetTestAccessor().RemoteNameLabelStatus;

                    Assert.AreEqual("master →", currentBranchNameLabelStatus.Text);
                    Assert.AreEqual("(remote not configured)", remoteNameLabelStatus.Text);
                    return(Task.CompletedTask);
                });
            }
        }
        private void RunToggleBetweenArtificialAndHeadCommitsTest(bool showGitStatusForArtificialCommits, Action <RevisionGridControl> runTest)
        {
            AppSettings.ShowGitStatusForArtificialCommits = showGitStatusForArtificialCommits;

            UITest.RunForm <FormBrowse>(
                showForm: () => _commands.StartBrowseDialog(owner: null).Should().BeTrue(),
                runTestAsync: async formBrowse =>
            {
                DoEvents();

                // wait for the revisions to be loaded
                await AsyncTestHelper.JoinPendingOperationsAsync(AsyncTestHelper.UnexpectedTimeout);

                formBrowse.RevisionGridControl.LatestSelectedRevision.Guid.Should().Be(_headCommit);

                var ta = formBrowse.GetTestAccessor();
                ta.CommitInfoTabControl.SelectedTab = ta.TreeTabPage;

                // let the focus events be handled
                DoEvents();

                try
                {
                    runTest(formBrowse.RevisionGridControl);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{runTest.Method.Name} failed: {ex.Demystify()}");
                    Console.WriteLine(_referenceRepository.Module.GitExecutable.GetOutput("status"));
                    throw;
                }

                // let the focus events be handled
                DoEvents();

                Assert.IsTrue(ta.CommitInfoTabControl.SelectedTab == ta.DiffTabPage, "Diff tab should be active");
            });
        }
        public void HasChanges_updated_correctly()
        {
            string filePath = Path.Combine(_referenceRepository.Module.WorkingDir, Path.GetRandomFileName());

            try
            {
                File.WriteAllText(filePath, "Hello↔world", _commands.Module.FilesEncoding);

                UITest.RunForm <FormEditor>(
                    () =>
                {
                    using (var formEditor = new FormEditor(_commands, filePath, showWarning: false))
                    {
                        formEditor.ShowDialog();
                    }
                },
                    form =>
                {
                    Assert.False(form.GetTestAccessor().HasChanges);

                    var fileViewerInternal = form.GetTestAccessor().FileViewer.GetTestAccessor().FileViewerInternal;
                    fileViewerInternal.SetText(fileViewerInternal.GetText() + "!", openWithDifftool: null, isDiff: false);

                    Assert.True(form.GetTestAccessor().HasChanges);

                    form.GetTestAccessor().SaveChanges();

                    Assert.False(form.GetTestAccessor().HasChanges);

                    return(Task.CompletedTask);
                });
            }
            finally
            {
                File.Delete(filePath);
            }
        }
示例#18
0
 private void RunFormTest(Func <FormBrowse, Task> testDriverAsync)
 {
     UITest.RunForm(
         showForm: () => _uiCommands.StartBrowseDialog(owner: null).Should().BeTrue(),
         testDriverAsync);
 }