From e977700b36d6a60780ff0d81a75b5668600adc8b Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 22 Feb 2024 18:43:53 +0100 Subject: [PATCH] add tests --- .../Service/OpenEditorDesktopService.cs | 2 +- .../Service/OpenEditorDesktopServiceTest.cs | 132 ++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/starsky/starsky.feature.desktop/Service/OpenEditorDesktopService.cs b/starsky/starsky.feature.desktop/Service/OpenEditorDesktopService.cs index 25e8aae808..8e38a478a3 100644 --- a/starsky/starsky.feature.desktop/Service/OpenEditorDesktopService.cs +++ b/starsky/starsky.feature.desktop/Service/OpenEditorDesktopService.cs @@ -114,7 +114,7 @@ public bool IsEnabled() /// /// /// - private static (List, List<(string FullFilePath, string AppPath)>) + internal static (List, List<(string FullFilePath, string AppPath)>) FilterListOpenDefaultEditorAndSpecificEditor( IReadOnlyCollection subPathAndImageFormatList) { diff --git a/starsky/starskytest/starsky.feature.desktop/Service/OpenEditorDesktopServiceTest.cs b/starsky/starskytest/starsky.feature.desktop/Service/OpenEditorDesktopServiceTest.cs index c447258c5b..b262c5f3fc 100644 --- a/starsky/starskytest/starsky.feature.desktop/Service/OpenEditorDesktopServiceTest.cs +++ b/starsky/starskytest/starsky.feature.desktop/Service/OpenEditorDesktopServiceTest.cs @@ -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(), "test"), + new FakeIOpenEditorPreflight(new List())); + 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(), "test"), + new FakeIOpenEditorPreflight(new List())); + 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(), "test", false), + new FakeIOpenEditorPreflight(new List())); + var result = service.IsEnabled(); + Assert.IsFalse(result); + } + + [TestMethod] + public void FilterListOpenDefaultEditorAndSpecificEditor_Test() + { + // Arrange + var inputList = new List + { + 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 + { + 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 + } }