TestDataHelper.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.CmdPal.Ext.Apps.Programs; 6 7 namespace Microsoft.CmdPal.Ext.Apps.UnitTests; 8 9 /// <summary> 10 /// Helper class to create test data for unit tests. 11 /// </summary> 12 public static class TestDataHelper 13 { 14 /// <summary> 15 /// Creates a test Win32 program with the specified parameters. 16 /// </summary> 17 /// <param name="name">The name of the application.</param> 18 /// <param name="fullPath">The full path to the application executable.</param> 19 /// <param name="enabled">A value indicating whether the application is enabled.</param> 20 /// <param name="valid">A value indicating whether the application is valid.</param> 21 /// <returns>A new Win32Program instance with the specified parameters.</returns> 22 public static Win32Program CreateTestWin32Program( 23 string name = "Test App", 24 string fullPath = "C:\\TestApp\\app.exe", 25 bool enabled = true, 26 bool valid = true) 27 { 28 return new Win32Program 29 { 30 Name = name, 31 FullPath = fullPath, 32 Enabled = enabled, 33 Valid = valid, 34 UniqueIdentifier = $"win32_{name}", 35 Description = $"Test description for {name}", 36 ExecutableName = "app.exe", 37 ParentDirectory = "C:\\TestApp", 38 AppType = Win32Program.ApplicationType.Win32Application, 39 }; 40 } 41 42 /// <summary> 43 /// Creates a test UWP application with the specified parameters. 44 /// </summary> 45 /// <param name="displayName">The display name of the application.</param> 46 /// <param name="userModelId">The user model ID of the application.</param> 47 /// <param name="enabled">A value indicating whether the application is enabled.</param> 48 /// <returns>A new IUWPApplication instance with the specified parameters.</returns> 49 public static IUWPApplication CreateTestUWPApplication( 50 string displayName = "Test UWP App", 51 string userModelId = "TestPublisher.TestUWPApp_1.0.0.0_neutral__8wekyb3d8bbwe", 52 bool enabled = true) 53 { 54 return new MockUWPApplication 55 { 56 DisplayName = displayName, 57 UserModelId = userModelId, 58 Enabled = enabled, 59 UniqueIdentifier = $"uwp_{userModelId}", 60 Description = $"Test UWP description for {displayName}", 61 AppListEntry = "default", 62 BackgroundColor = "#000000", 63 EntryPoint = "TestApp.App", 64 CanRunElevated = false, 65 LogoPath = string.Empty, 66 Package = CreateMockUWPPackage(displayName, userModelId), 67 }; 68 } 69 70 /// <summary> 71 /// Creates a mock UWP package for testing purposes. 72 /// </summary> 73 /// <param name="displayName">The display name of the package.</param> 74 /// <param name="userModelId">The user model ID of the package.</param> 75 /// <returns>A new UWP package instance.</returns> 76 private static UWP CreateMockUWPPackage(string displayName, string userModelId) 77 { 78 var mockPackage = new MockPackage 79 { 80 Name = displayName, 81 FullName = userModelId, 82 FamilyName = $"{displayName}_8wekyb3d8bbwe", 83 InstalledLocation = $"C:\\Program Files\\WindowsApps\\{displayName}", 84 }; 85 86 return new UWP(mockPackage) 87 { 88 Location = mockPackage.InstalledLocation, 89 LocationLocalized = mockPackage.InstalledLocation, 90 }; 91 } 92 93 /// <summary> 94 /// Mock implementation of IPackage for testing purposes. 95 /// </summary> 96 private sealed class MockPackage : IPackage 97 { 98 /// <summary> 99 /// Gets or sets the name of the package. 100 /// </summary> 101 public string Name { get; set; } = string.Empty; 102 103 /// <summary> 104 /// Gets or sets the full name of the package. 105 /// </summary> 106 public string FullName { get; set; } = string.Empty; 107 108 /// <summary> 109 /// Gets or sets the family name of the package. 110 /// </summary> 111 public string FamilyName { get; set; } = string.Empty; 112 113 /// <summary> 114 /// Gets or sets a value indicating whether the package is a framework package. 115 /// </summary> 116 public bool IsFramework { get; set; } 117 118 /// <summary> 119 /// Gets or sets a value indicating whether the package is in development mode. 120 /// </summary> 121 public bool IsDevelopmentMode { get; set; } 122 123 /// <summary> 124 /// Gets or sets the installed location of the package. 125 /// </summary> 126 public string InstalledLocation { get; set; } = string.Empty; 127 } 128 }