forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dotnet#11973 from ricardobossan/Issue_10773_Add_Co…
…verage_FolderNameEditor Adds code coverage to FolderNameEditor
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/FolderNameEditorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.ComponentModel; | ||
using System.Windows.Forms.Design; | ||
using FluentAssertions; | ||
using Moq; | ||
using Xunit.Abstractions; | ||
|
||
namespace System.Windows.Forms.UITests; | ||
|
||
public class FolderNameEditorTests : ControlTestBase | ||
{ | ||
public FolderNameEditorTests(ITestOutputHelper testOutputHelper) | ||
: base(testOutputHelper) | ||
{ | ||
} | ||
|
||
[WinFormsFact] | ||
public void FolderNameEditor_EditValue_ReturnsExpected() | ||
{ | ||
TestFolderNameEditor editor = new(); | ||
Mock<IServiceProvider> serviceProviderMock = new(); | ||
var serviceProvider = serviceProviderMock.Object; | ||
string value = "value"; | ||
|
||
object? result = editor.EditValue(context: null, provider: serviceProvider, value: value); | ||
|
||
result.Should().Be(value); | ||
} | ||
|
||
private class TestFolderNameEditor : FolderNameEditor | ||
{ | ||
private FolderBrowser? _folderBrowser; | ||
|
||
public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value) | ||
{ | ||
using DialogHostForm dialogOwnerForm = new(); | ||
|
||
if (_folderBrowser is null) | ||
{ | ||
_folderBrowser = new FolderBrowser(); | ||
InitializeDialog(_folderBrowser); | ||
} | ||
|
||
if (_folderBrowser.ShowDialog(dialogOwnerForm) == DialogResult.OK) | ||
{ | ||
return _folderBrowser.DirectoryPath; | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
} | ||
|