diff --git a/src/electrifier.Tests.MSTest/Initialize.cs b/src/electrifier.Tests.MSTest/Initialize.cs deleted file mode 100644 index 7f3ce2b4..00000000 --- a/src/electrifier.Tests.MSTest/Initialize.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.Windows.ApplicationModel.DynamicDependency; - -[assembly: WinUITestTarget(typeof(electrifier.App))] - -namespace electrifier.Tests.MSTest; - -[TestClass] -public class Initialize -{ - [AssemblyInitialize] - public static void AssemblyInitialize(TestContext context) - { - // TODO: Initialize the appropriate version of the Windows App SDK. - // This is required when testing MSIX apps that are framework-dependent on the Windows App SDK. - //Assert.IsTrue(Bootstrap.TryInitialize(0x00010001, out var _)); - } - - [TestMethod] - public void TestMethod() - { - Assert.IsTrue(true); - } - - [AssemblyCleanup] - public static void AssemblyCleanup() - { - Bootstrap.Shutdown(); - } -} diff --git a/src/electrifier.Tests.MSTest/README.md b/src/electrifier.Tests.MSTest/README.md deleted file mode 100644 index ab7f7934..00000000 --- a/src/electrifier.Tests.MSTest/README.md +++ /dev/null @@ -1,67 +0,0 @@ -*Recommended Markdown Viewer: [Markdown Editor](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.MarkdownEditor2)* - -## Getting Started - -[Get started with unit testing](https://docs.microsoft.com/visualstudio/test/getting-started-with-unit-testing?view=vs-2022&tabs=dotnet%2Cmstest), [Use the MSTest framework in unit tests](https://docs.microsoft.com/visualstudio/test/using-microsoft-visualstudio-testtools-unittesting-members-in-unit-tests), and [Run unit tests with Test Explorer](https://docs.microsoft.com/visualstudio/test/run-unit-tests-with-test-explorer) provide an overview of the MSTest framework and Test Explorer. - -## Testing UI Controls - -Unit tests that exercise UI controls must run on the WinUI UI thread or they will throw an exception. To run a test on the WinUI UI thread, mark the test method with `[UITestMethod]` instead of `[TestMethod]`. During test execution, the test host will launch the app and dispatch the test to the app's UI thread. - -The below example creates a `new Grid()` and then validates that its `ActualWidth` is `0`. - -```csharp -[UITestMethod] -public void UITestMethod() -{ - Assert.AreEqual(0, new Grid().ActualWidth); -} -``` - -## Dependency Injection and Mocking - -Template Studio uses [dependency injection](https://docs.microsoft.com/dotnet/core/extensions/dependency-injection) which means class dependencies implement interfaces and those dependencies are injected via class constructors. - -One of the many benefits of this approach is improved testability, since tests can produce mock implementations of the interfaces and pass them into the object being tested, isolating the object being tested from its dependencies. To mock an interface, create a class that implements the interface, create stub implementations of the interface members, then pass an instance of the class into the object constructor. - -The below example demonstrates testing the ViewModel for the Settings page. `SettingsViewModel` depends on `IThemeSelectorService`, so a `MockThemeSelectorService` class is introduced that implements the interface with stub implementations, and then an instance of that class is passed into the `SettingsViewModel` constructor. The `VerifyVersionDescription` test then validates that the `VersionDescription` property of the `SettingsViewModel` returns the expected value. - -```csharp -// SettingsViewModelTests.cs - -[TestClass] -public class SettingsViewModelTests -{ - private readonly SettingsViewModel _viewModel; - - public SettingsViewModelTests() - { - _viewModel = new SettingsViewModel(new MockThemeSelectorService()); - } - - [TestMethod] - public void VerifyVersionDescription() - { - Assert.IsTrue(Regex.IsMatch(_viewModel.VersionDescription, @"App1 - \d\.\d\.\d\.\d")); - } -} -``` - -```csharp -// Mocks/MockThemeSelectorService.cs - -internal class MockThemeSelectorService : IThemeSelectorService -{ - public ElementTheme Theme => ElementTheme.Default; - - public Task InitializeAsync() => Task.CompletedTask; - - public Task SetRequestedThemeAsync() => Task.CompletedTask; - - public Task SetThemeAsync(ElementTheme theme) => Task.CompletedTask; -} -``` - -## CI Pipelines - -See [README.md](https://github.com/microsoft/TemplateStudio/blob/main/docs/WinUI/pipelines/README.md) for guidance on building and testing projects in CI pipelines. diff --git a/src/electrifier.Tests.MSTest/SimpleUnitTest.cs b/src/electrifier.Tests.MSTest/SimpleUnitTest.cs deleted file mode 100644 index 3bfb640a..00000000 --- a/src/electrifier.Tests.MSTest/SimpleUnitTest.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Diagnostics; -using Microsoft.UI.Xaml.Controls; - -namespace electrifier.Tests.MSTest; - -[TestClass] -public class SimpleUnitTest -{ - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Debug.WriteLine("ClassInitialize"); - } - - [ClassCleanup] - public static void ClassCleanup() - { - Debug.WriteLine("ClassCleanup"); - } - - [TestInitialize] - public void TestInitialize() - { - Debug.WriteLine("TestInitialize"); - } - - [TestCleanup] - public void TestCleanup() - { - Debug.WriteLine("TestCleanup"); - } - - [TestMethod] - public void TestMethod() - { - Assert.IsTrue(true); - } - - [UITestMethod] - public void UiTestMethod() - { - Assert.AreEqual(0, new Grid().ActualWidth); - } - - [TestMethod] - public void TestStringWriter() - { - //using var sw = new StringWriter(); - //Console.SetOut(sw); - ////HelloWorld.Program.Main(); - - //var result = sw.ToString().Trim(); - ////Assert.AreEqual(Expected, result); - } -} diff --git a/src/electrifier.Tests.MSTest/TestClass.cs b/src/electrifier.Tests.MSTest/TestClass.cs deleted file mode 100644 index 777a84c8..00000000 --- a/src/electrifier.Tests.MSTest/TestClass.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Diagnostics; -using Microsoft.UI.Xaml.Controls; - -namespace electrifier.Tests.MSTest; - -/// -/// Summary description for TestClass -///
-///
-///
-///
-[TestClass] -public class TestClass -{ - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Debug.WriteLine("ClassInitialize"); - } - - [ClassCleanup] - public static void ClassCleanup() - { - Debug.WriteLine("ClassCleanup"); - } - - [TestInitialize] - public void TestInitialize() - { - Debug.WriteLine("TestInitialize"); - } - - [TestCleanup] - public void TestCleanup() - { - Debug.WriteLine("TestCleanup"); - } - - [TestMethod] - public void TestMethod() - { - Assert.IsTrue(true); - } - - [UITestMethod] - public void UiTestMethod() - { - Assert.AreEqual(0, new Grid().ActualWidth); - } -} diff --git a/src/electrifier.Tests.MSTest/Usings.cs b/src/electrifier.Tests.MSTest/Usings.cs deleted file mode 100644 index e91519c9..00000000 --- a/src/electrifier.Tests.MSTest/Usings.cs +++ /dev/null @@ -1,2 +0,0 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; -global using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; diff --git a/src/electrifier.Tests.MSTest/electrifier.Tests.MSTest.csproj b/src/electrifier.Tests.MSTest/electrifier.Tests.MSTest.csproj deleted file mode 100644 index 5e8f7053..00000000 --- a/src/electrifier.Tests.MSTest/electrifier.Tests.MSTest.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - net7.0-windows10.0.19041.0 - electrifier.Tests.MSTest - x86;x64;arm64 - false - enable - enable - true - true - resources.pri - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - diff --git a/src/electrifier/electrifier.sln b/src/electrifier/electrifier.sln index e7cb196d..24600e6b 100644 --- a/src/electrifier/electrifier.sln +++ b/src/electrifier/electrifier.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.9.34526.213 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "electrifier", "electrifier.csproj", "{E0A53ED6-B06A-4F8A-8A7F-EB4EB3D24B91}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "electrifier.Tests.MSTest", "..\electrifier.Tests.MSTest\electrifier.Tests.MSTest.csproj", "{B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,22 +41,6 @@ Global {E0A53ED6-B06A-4F8A-8A7F-EB4EB3D24B91}.Release|x86.ActiveCfg = Release|x86 {E0A53ED6-B06A-4F8A-8A7F-EB4EB3D24B91}.Release|x86.Build.0 = Release|x86 {E0A53ED6-B06A-4F8A-8A7F-EB4EB3D24B91}.Release|x86.Deploy.0 = Release|x86 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|Any CPU.ActiveCfg = Debug|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|Any CPU.Build.0 = Debug|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|arm64.ActiveCfg = Debug|arm64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|arm64.Build.0 = Debug|arm64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|x64.ActiveCfg = Debug|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|x64.Build.0 = Debug|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|x86.ActiveCfg = Debug|x86 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Debug|x86.Build.0 = Debug|x86 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|Any CPU.ActiveCfg = Release|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|Any CPU.Build.0 = Release|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|arm64.ActiveCfg = Release|arm64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|arm64.Build.0 = Release|arm64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|x64.ActiveCfg = Release|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|x64.Build.0 = Release|x64 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|x86.ActiveCfg = Release|x86 - {B1671FF3-90B2-4FD0-B0AA-D8C7027C66DF}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE