Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(qm): add query manager tests #193

Merged
merged 6 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BSH.Engine/Contracts/IQueryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IQueryManager
Task<string> GetBackVersionWhereFileAsync(string startVersion, string searchString);
Task<string> GetBackVersionWhereFilesInFolderAsync(string startVersion, string path);
string GetFileNameFromDrive(FileTableRow file);
Task<Tuple<string, bool>> GetFileNameFromDriveAsync(int versionId, string fileName, string filePath, SecureString password);
Task<ValueTuple<string, bool>> GetFileNameFromDriveAsync(int versionId, string fileName, string filePath, SecureString password);
Task<List<FileTableRow>> GetFilesByVersionAsync(string version, string path);
Task<List<string>> GetFolderListAsync(string version, string path);
Task<string> GetFullRestoreFolderAsync(string folder, string version);
Expand Down
14 changes: 7 additions & 7 deletions src/BSH.Engine/QueryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public async Task<string> GetBackVersionWhereFilesInFolderAsync(string startVers
"WHERE a.versionID < @startVersion " +
"AND a.versionStatus = 0 " +
"AND EXISTS (SELECT 1 FROM fileversiontable, filelink, filetable " +
"WHERE fileversiontable.fileversionid = filelink.fileversionid " +
"WHERE fileversiontable.fileversionID = filelink.fileversionID " +
"AND filelink.versionID = a.versionID " +
"AND filetable.fileID = fileversiontable.fileID " +
"AND filetable.filePath = @path) " +
Expand Down Expand Up @@ -579,7 +579,7 @@ public string GetFileNameFromDrive(FileTableRow file)
/// <param name="password"></param>
/// <param name="temp"></param>
/// <returns></returns>
public async Task<Tuple<string, bool>> GetFileNameFromDriveAsync(int versionId, string fileName, string filePath, SecureString password)
public async Task<ValueTuple<string, bool>> GetFileNameFromDriveAsync(int versionId, string fileName, string filePath, SecureString password)
{
using var dbClient = dbClientFactory.CreateDbClient();
using var storage = storageFactory.GetCurrentStorageProvider();
Expand Down Expand Up @@ -651,7 +651,7 @@ public async Task<Tuple<string, bool>> GetFileNameFromDriveAsync(int versionId,
reader.Close();
}

return new Tuple<string, bool>(result, temp);
return (result, temp);
}

/// <summary>
Expand Down Expand Up @@ -703,14 +703,14 @@ public async Task<string> GetFullRestoreFolderAsync(string folder, string versio

foreach (var destination in destFolders)
{
var directory = new DirectoryInfo(destination);
var directoryName = destination.Split("\\", StringSplitOptions.RemoveEmptyEntries)[^1];

if (folder.StartsWith("\\" + directory.Name + "\\"))
if (folder.StartsWith("\\" + directoryName + "\\"))
{
var idx = folder.IndexOf("\\" + directory.Name + "\\");
var idx = folder.IndexOf("\\" + directoryName + "\\");

// path found
var result = Path.Combine(destination, folder[(idx + directory.Name.Length + 2)..]);
var result = Path.Combine(destination, folder[(idx + directoryName.Length + 2)..]);

if (result.EndsWith("\\"))
{
Expand Down
49 changes: 20 additions & 29 deletions src/BSH.Main/Dialogs/frmBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,52 +1141,43 @@ private async void ToolStripSchnellansicht_Click(object sender, EventArgs e)
}

// Schnellansicht laden
Tuple<string, bool> tmpFile = null;
try
{
var password = BackupLogic.BackupService.GetPassword();
tmpFile = await BackupLogic.QueryManager.GetFileNameFromDriveAsync(int.Parse(selectedVersion.Id), lvFiles.SelectedItems[0].Text, lvFiles.SelectedItems[0].Tag.ToString(), password);
var tmpFile = await BackupLogic.QueryManager.GetFileNameFromDriveAsync(int.Parse(selectedVersion.Id), lvFiles.SelectedItems[0].Text, lvFiles.SelectedItems[0].Tag.ToString(), password);

#if !WIN_UWP
var procInfo = new ProcessStartInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\SmartPreview.exe", " -file:\"" + tmpFile.Item1 + "\"" + (tmpFile.Item2 ? " -c" : ""));
procInfo.WindowStyle = ProcessWindowStyle.Normal;

var proc = Process.Start(procInfo);
proc.WaitForExit();
#else
var procInfo = new ProcessStartInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\..\SmartPreview\SmartPreview.exe", " -file:\"" + tmpFile.Item1 + "\"" + (isTmp.Item2 ? " -c" : ""));
procInfo.WindowStyle = ProcessWindowStyle.Normal;

var proc = Process.Start(procInfo);
proc.WaitForExit();
#endif
}
catch
{
// Fehler: Feature nicht installiert?
MessageBox.Show(Resources.DLG_FEATURE_NOT_AVAILABLE_TEXT, Resources.DLG_FEATURE_NOT_AVAILABLE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

if (tmpFile != null && tmpFile.Item2)
{
for (int i = 0; i <= 5; i++)
if (tmpFile.Item1 != null && tmpFile.Item2)
{
try
for (var i = 0; i <= 5; i++)
{
if (i == 5)
try
{
return;
}
if (i == 5)
{
return;
}

System.IO.File.Delete(tmpFile.Item1);
break;
}
catch
{
// ignore error
System.IO.File.Delete(tmpFile.Item1);
break;
}
catch
{
// ignore error
}
}
}
}
catch
{
// Fehler: Feature nicht installiert?
MessageBox.Show(Resources.DLG_FEATURE_NOT_AVAILABLE_TEXT, Resources.DLG_FEATURE_NOT_AVAILABLE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}

Expand Down
43 changes: 17 additions & 26 deletions src/BSH.Main/Dialogs/frmFileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,40 @@ private async void cmdPreview_Click(object sender, EventArgs e)
}

// Schnellansicht laden
Tuple<string, bool> tmpFile = null;
try
{
int id = int.Parse(((FileTableRow)lvVersions.SelectedItems[0].Tag).FilePackage);
var id = int.Parse(((FileTableRow)lvVersions.SelectedItems[0].Tag).FilePackage);

var password = BackupLogic.BackupService.GetPassword();
tmpFile = await BackupLogic.QueryManager.GetFileNameFromDriveAsync(id, lblFileName.Text, CurrentFileFolder, password);
var tmpFile = await BackupLogic.QueryManager.GetFileNameFromDriveAsync(id, lblFileName.Text, CurrentFileFolder, password);

#if !WIN_UWP
var procInfo = new ProcessStartInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\SmartPreview.exe", " -file:\"" + tmpFile.Item1 + "\"" + (tmpFile.Item2 ? " -c" : ""));
procInfo.WindowStyle = ProcessWindowStyle.Normal;

var proc = Process.Start(procInfo);
proc.WaitForExit();
#else
var procInfo = new ProcessStartInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\..\SmartPreview\SmartPreview.exe", " -file:\"" + tmpFile.Item1 + "\"" + (isTmp.Item2 ? " -c" : ""));
procInfo.WindowStyle = ProcessWindowStyle.Normal;

var proc = Process.Start(procInfo);
proc.WaitForExit();
#endif
if (tmpFile.Item1 != null && tmpFile.Item2)
{
for (var i = 0; i < 5; i++)
{
try
{
System.IO.File.Delete(tmpFile.Item1);
break;
}
catch
{
// next try
}
}
}
}
catch
{
// Fehler: Feature nicht installiert?
MessageBox.Show(Resources.DLG_FEATURE_NOT_AVAILABLE_TEXT, Resources.DLG_FEATURE_NOT_AVAILABLE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

if (tmpFile != null && tmpFile.Item2)
{
for (int i = 0; i < 5; i++)
{
try
{
System.IO.File.Delete(tmpFile.Item1);
break;
}
catch
{
// next try
}
}
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/BSH.Test/Mocks/StorageFactoryMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Brightbits.BSH.Engine.Contracts.Storage;
using Brightbits.BSH.Engine.Storage;

namespace BSH.Test.Mocks;
public class StorageFactoryMock : IStorageFactory
{
public IStorage GetCurrentStorageProvider() => new StorageMock();
}
Loading