Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 22, 2024
1 parent 5674fdf commit e977700
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public bool IsEnabled()
/// </summary>
/// <param name="subPathAndImageFormatList"></param>
/// <returns></returns>
private static (List<string>, List<(string FullFilePath, string AppPath)>)
internal static (List<string>, List<(string FullFilePath, string AppPath)>)
FilterListOpenDefaultEditorAndSpecificEditor(
IReadOnlyCollection<PathImageFormatExistsAppPathModel> subPathAndImageFormatList)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,136 @@ public void OpenAmountConfirmationChecker_1File()
var result = service.OpenAmountConfirmationChecker("/test.jpg");
Assert.IsTrue(result);
}

[TestMethod]
public void IsEnabled_FalseDueFeatureFlag()
{
var appSettings = new AppSettings { UseLocalDesktop = false };
var service = new OpenEditorDesktopService(appSettings,
new FakeIOpenApplicationNativeService(new List<string>(), "test"),
new FakeIOpenEditorPreflight(new List<PathImageFormatExistsAppPathModel>()));
var result = service.IsEnabled();
Assert.IsFalse(result);
}

[TestMethod]
public void IsEnabled_True()
{
var appSettings = new AppSettings
{
UseLocalDesktop = true // feature flag enabled
};
var service = new OpenEditorDesktopService(appSettings,
// Default is supported in mock service
new FakeIOpenApplicationNativeService(new List<string>(), "test"),
new FakeIOpenEditorPreflight(new List<PathImageFormatExistsAppPathModel>()));
var result = service.IsEnabled();
Assert.IsTrue(result);
}

[TestMethod]
public void IsEnabled_FalseDuePlatformNotSupported()
{
var appSettings = new AppSettings { UseLocalDesktop = true };
var service = new OpenEditorDesktopService(appSettings,
// Is supported false! =>
new FakeIOpenApplicationNativeService(new List<string>(), "test", false),
new FakeIOpenEditorPreflight(new List<PathImageFormatExistsAppPathModel>()));
var result = service.IsEnabled();
Assert.IsFalse(result);
}

[TestMethod]
public void FilterListOpenDefaultEditorAndSpecificEditor_Test()
{
// Arrange
var inputList = new List<PathImageFormatExistsAppPathModel>
{
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file1.txt",
Status = FileIndexItem.ExifStatus.Ok,
AppPath = string.Empty
},
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file2.txt",
Status = FileIndexItem.ExifStatus.Ok,
AppPath = "editor.exe"
},
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file3.txt",
Status = FileIndexItem.ExifStatus.OperationNotSupported,
AppPath = string.Empty
},
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file4.txt",
Status = FileIndexItem.ExifStatus.Ok,
AppPath = string.Empty
}
};

// Act
var result =
OpenEditorDesktopService.FilterListOpenDefaultEditorAndSpecificEditor(inputList);

// Assert
Assert.AreEqual(2, result.Item1.Count); // Expected number of files without AppPath
Assert.IsTrue(
result.Item1
.Contains("file1.txt")); // Make sure file1.txt is in the list without AppPath
Assert.IsFalse(
result.Item1
.Contains("file2.txt")); // Make sure file2.txt is not in the list without AppPath
Assert.AreEqual(1, result.Item2.Count); // Expected number of files with AppPath
Assert.IsTrue(result.Item2.Exists(x =>
x.FullFilePath == "file2.txt" &&
x.AppPath ==
"editor.exe")); // Make sure file2.txt is in the list with AppPath and has correct editor
}

[TestMethod]
public void FilterListOpenSpecificEditor_Test()
{
// Arrange
var inputList = new List<PathImageFormatExistsAppPathModel>
{
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file1.txt",
Status = FileIndexItem.ExifStatus.Ok,
AppPath = ""
},
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file2.txt",
Status = FileIndexItem.ExifStatus.Ok,
AppPath = "editor.exe"
},
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file3.txt",
Status = FileIndexItem.ExifStatus.NotFoundNotInIndex,
AppPath = ""
},
new PathImageFormatExistsAppPathModel
{
FullFilePath = "file4.txt",
Status = FileIndexItem.ExifStatus.Ok,
AppPath = string.Empty
}
};

// Act
var result =
OpenEditorDesktopService.FilterListOpenDefaultEditorAndSpecificEditor(inputList);

// Assert
Assert.AreEqual(1, result.Item2.Count); // Expected number of files with AppPath
Assert.IsTrue(result.Item2.Exists(x =>
x is { FullFilePath: "file2.txt", AppPath: "editor.exe" }));
// Make sure file2.txt is in the list with AppPath and has correct editor
}
}

0 comments on commit e977700

Please sign in to comment.