白色测试 - 文件夹浏览器对话框

时间:2015-12-11 07:01:13

标签: c# wpf testing white

我在使用白色的FolderBrowserDialog时遇到问题。我认为它应该被指定为模态窗口,但它不是。

DialogService.cs中的FolderBrowserDialog:

 public FolderBrowserResult ShowFolderbrowserDialog(string storageFolder)
    {
        var dialog = new FolderBrowserDialog
        {               
            Description = storageFolder
        };

        var result = new FolderBrowserResult
        {
            Result = dialog.ShowDialog() != DialogResult.OK,
            Path = dialog.SelectedPath          
        };

        return result;
    }

点击浏览按钮后调用的方法:

private void OnBrowseForTargetFolder(object sender, RoutedEventArgs e)
    {
        var result = dialogService.ShowFolderbrowserDialog(Properties.Resources.StorageFolder);
        if (result.Result) return;

        Project.PathToStorage = result.Path;
        completePath = string.Format("{0}\\{1}", result.Path, Guid.NewGuid());
        Directory.CreateDirectory(completePath);
    }

测试:

public class LoggerTests
{
    private Application application;

    private MainWindowPage mainWindowPage;

    [TestInitialize]
    public void TestInitialize()
    {
        application = Application.Launch(@"PML.exe");
        StartBlankApplication();
    }

    [TestMethod]
    public void StartExistingProject()
    {
        mainWindowPage.StartExistingProjectButton.Click();
        var modalWindows = new List<Window>();
        Retry.For(() =>
        {
            modalWindows = mainWindowPage.applicationWindow.ModalWindows();
        }, TimeSpan.FromSeconds(5));

        var mod = modalWindows;
    }

    private MainWindowPage StartBlankApplication()
    {
        var appWindow = application.GetWindow("PML");
        mainWindowPage = new MainWindowPage(appWindow);
        return mainWindowPage;
    }

    private NewProjectConfigurationPage ConfigureBlankProject()
    {
        Window secondAppWindow = null;
        Retry.For(() =>
        {
            secondAppWindow = application.GetWindow("PML");
        }, TimeSpan.FromSeconds(5));

        var newProjectConfiguration = new NewProjectConfigurationPage(secondAppWindow);

        newProjectConfiguration.VesselName.Text = "Test";
        newProjectConfiguration.BrowseButton.Click();

        return newProjectConfiguration;
    }
}

StartExistingProject 方法中,变量 mod 为空的问题。并且没有打开FolderBrowserDialog。但是当我正常运行app时,一切运行正常。

1 个答案:

答案 0 :(得分:1)

已解决 - 必须将所有者设置为模态对话框。所以

 var wrapper = new WindowWrapper(this);

 dialog.ShowDialog(wrapper)

解决了我的问题。