2020-03-28 21:52:43 +00:00
|
|
|
|
using System.IO;
|
2019-12-14 20:11:39 +00:00
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DynamicData;
|
|
|
|
|
using Wabbajack.Common;
|
2020-03-28 21:52:43 +00:00
|
|
|
|
using Xunit;
|
2019-12-14 20:11:39 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
|
|
|
|
public class FilePickerTests
|
|
|
|
|
{
|
|
|
|
|
public static TempFile CreateSetFile(FilePickerVM vm)
|
|
|
|
|
{
|
|
|
|
|
var temp = new TempFile();
|
|
|
|
|
using (new FileStream(temp.File.FullName, FileMode.CreateNew)) { }
|
2020-03-28 21:52:43 +00:00
|
|
|
|
vm.TargetPath = temp.Path;
|
2019-12-14 20:11:39 +00:00
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task Stock()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.Equal(FilePickerVM.PathTypeOptions.Off, vm.PathType);
|
|
|
|
|
Assert.Equal(FilePickerVM.CheckOptions.Off, vm.ExistCheckOption);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileNoExistsCheck_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.Off;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded, vm.ErrorState.Reason);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileNoExistsCheck_Exists()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using (CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.Off;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task ExistCheckTypeOff_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Off;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task ExistCheckTypeOff_Exists()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using (CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Off;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileIfNotEmptyCheck_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileIfNotEmptyCheck_SetPath_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
2020-03-28 21:52:43 +00:00
|
|
|
|
vm.TargetPath = (AbsolutePath)"SomePath.jpg";
|
2019-12-14 20:11:39 +00:00
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileIfNotEmptyCheck_Exists()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using (CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.True(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileOnExistsCheck_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileOnExistsCheck_Exists()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using (CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.True(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FolderIfNotEmptyCheck_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Folder;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded, vm.ErrorState.Reason);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FolderIfNotEmptyCheck_SetPath_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Folder;
|
2020-03-28 21:52:43 +00:00
|
|
|
|
vm.TargetPath = (AbsolutePath)"SomePath.jpg";
|
2019-12-14 20:11:39 +00:00
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded, vm.ErrorState.Reason);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FolderIfNotEmptyCheck_Exists()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-04-28 04:03:57 +00:00
|
|
|
|
await using (await CreateSetFolder(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Folder;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.True(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FolderOnExistsCheck_DoesNotExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Folder;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FolderOnExistsCheck_Exists()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-04-28 04:03:57 +00:00
|
|
|
|
await using (await CreateSetFolder(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Folder;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.True(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task AdditionalError_Success()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.AdditionalError = Observable.Return<IErrorResponse>(ErrorResponse.Succeed());
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task AdditionalError_Fail()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2019-12-15 03:55:16 +00:00
|
|
|
|
string errText = "An error";
|
|
|
|
|
vm.AdditionalError = Observable.Return<IErrorResponse>(ErrorResponse.Fail(errText));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(errText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileExistsButSetToFolder()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using (CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.Folder;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FolderExistsButSetToFile()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-04-28 04:03:57 +00:00
|
|
|
|
await using (await CreateSetFolder(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.On;
|
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileWithFilters_Passes()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2021-03-19 04:14:07 +00:00
|
|
|
|
await using (var file = CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.Off;
|
2021-03-19 04:14:07 +00:00
|
|
|
|
vm.Filters.Add(new Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFilter("test", $"*{vm.TargetPath.Extension}"));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileWithFilters_ExistsButFails()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using (CreateSetFile(vm))
|
2019-12-14 20:11:39 +00:00
|
|
|
|
{
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.Off;
|
2021-03-19 04:14:07 +00:00
|
|
|
|
vm.Filters.Add(new Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFilter("test", $"*{vm.TargetPath.Extension}z"));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.False(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.True(vm.InError);
|
|
|
|
|
Assert.Equal(FilePickerVM.DoesNotPassFiltersText, vm.ErrorTooltip);
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileWithFilters_PassesButDoesntExist()
|
|
|
|
|
{
|
|
|
|
|
var vm = new FilePickerVM();
|
|
|
|
|
vm.PathType = FilePickerVM.PathTypeOptions.File;
|
|
|
|
|
vm.ExistCheckOption = FilePickerVM.CheckOptions.Off;
|
2020-03-28 21:52:43 +00:00
|
|
|
|
vm.TargetPath = (AbsolutePath)"SomePath.png";
|
2021-03-19 04:14:07 +00:00
|
|
|
|
vm.Filters.Add(new Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFilter("test", $"*{vm.TargetPath.Extension}"));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded, vm.ErrorState.Reason);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:52:43 +00:00
|
|
|
|
[Fact]
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public async Task FileWithFilters_IfNotEmptyCheck_DoesntExist()
|
|
|
|
|
{
|
2020-03-28 21:52:43 +00:00
|
|
|
|
var vm = new FilePickerVM
|
|
|
|
|
{
|
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.File,
|
|
|
|
|
ExistCheckOption = FilePickerVM.CheckOptions.Off,
|
|
|
|
|
FilterCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty
|
|
|
|
|
};
|
2021-03-19 04:14:07 +00:00
|
|
|
|
vm.Filters.Add(new Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFilter("test", $"*{vm.TargetPath.Extension}"));
|
2019-12-14 20:11:39 +00:00
|
|
|
|
await Task.Delay(250);
|
2020-03-28 21:52:43 +00:00
|
|
|
|
Assert.False(vm.Exists);
|
|
|
|
|
Assert.True(vm.ErrorState.Succeeded);
|
|
|
|
|
Assert.False(vm.InError);
|
|
|
|
|
Assert.True(string.IsNullOrEmpty(vm.ErrorTooltip));
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 04:03:57 +00:00
|
|
|
|
private static async Task<TempFolder> CreateSetFolder(FilePickerVM vm)
|
2020-03-28 21:52:43 +00:00
|
|
|
|
{
|
2020-04-28 04:03:57 +00:00
|
|
|
|
var temp = await TempFolder.Create();
|
2020-03-28 21:52:43 +00:00
|
|
|
|
vm.TargetPath = temp.Dir;
|
|
|
|
|
return temp;
|
2019-12-14 20:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|