-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make FileDialog.FileName consistent across platforms
Mac: Fix setting FileName to null Mac/Gtk: Remember set value before/after dialog is shown Added test to ensure things work as expected
- Loading branch information
Showing
9 changed files
with
123 additions
and
29 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using NUnit.Framework; | ||
|
||
namespace Eto.Test.UnitTests.Forms | ||
{ | ||
[TestFixture] | ||
public class OpenFileDialogTests : FileDialogTests<OpenFileDialog> | ||
{ | ||
} | ||
|
||
[TestFixture] | ||
public class SaveFileDialogTests : FileDialogTests<SaveFileDialog> | ||
{ | ||
} | ||
|
||
public class FileDialogTests<T> : TestBase | ||
where T: FileDialog, new() | ||
{ | ||
[Test, InvokeOnUI, ManualTest] | ||
public void FileNameShouldHaveConsistentValues() | ||
{ | ||
var fd = new T(); | ||
fd.Filters.Add(new FileFilter("Text Files (*.txt)", ".txt")); | ||
|
||
Assert.That(fd.FileName, Is.Null.Or.Empty.Or.EqualTo("Untitled"), "#1"); | ||
|
||
fd.FileName = null; | ||
Assert.That(fd.FileName, Is.Null.Or.Empty.Or.EqualTo("Untitled"), "#2"); | ||
|
||
fd.FileName = "SomeFile.txt"; | ||
|
||
Assert.AreEqual("SomeFile.txt", Path.GetFileName(fd.FileName), "#3"); | ||
|
||
var result = fd.ShowDialog(null); | ||
|
||
if (result == DialogResult.Cancel || typeof(T) == typeof(SaveFileDialog)) | ||
Assert.AreEqual("SomeFile.txt", Path.GetFileName(fd.FileName), "#4"); | ||
|
||
if (result == DialogResult.Ok) | ||
{ | ||
var directoryName = Path.GetDirectoryName(fd.FileName); | ||
Assert.IsNotNull(directoryName, "#5.1"); | ||
Assert.IsNotEmpty(directoryName, "#5.2"); | ||
Console.WriteLine($"Directory: {directoryName}"); | ||
} | ||
|
||
Console.WriteLine($"FileName: {fd.FileName}"); | ||
|
||
} | ||
} | ||
} |