-
Notifications
You must be signed in to change notification settings - Fork 565
[dotnet] Add test project templates for all Apple platforms #25195
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
Merged
+1,391
−0
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
25c8860
Add test project templates for all Apple platforms
jonathanpeppers 4f56ac6
Auto-format source code
cac67af
Set MtouchInterpreter=all globally when EnableMSTestRunner=true
jonathanpeppers c8156d7
Remove TrimMode from test templates
jonathanpeppers f7ec8e4
Fix test templates to target net11.0
jonathanpeppers 6c28c5d
Move MSTest workarounds to shared targets, remove obsolete API
jonathanpeppers d21d13c
Fix Info.plist orientation warnings and CS8601 nullable warning
jonathanpeppers 71682b3
Set NO_COLOR=1 for MSTest runner projects to fix garbled output
jonathanpeppers 68b9e8b
Move MSTest properties to Xamarin.Shared.Sdk.MSTest.props
jonathanpeppers ef0580e
Remove unnecessary Entitlements.plist from test templates
jonathanpeppers b2e69a4
Update MSTest to 4.2.1 in test templates
jonathanpeppers c93208d
Inline ResultConsumer as nested class in Main.cs
jonathanpeppers d010091
Fix minOSVersion defaults in test templates to match app templates
jonathanpeppers 6990b32
Add localization files.
rolfbjarne fb16525
Merge remote-tracking branch 'origin/net11.0' into jonathanpeppers/ap…
rolfbjarne 1481a3d
Suppress trim analysis warnings for MSTest projects
jonathanpeppers a3dc29b
Fix tvOS test template to match existing tvOS app template
jonathanpeppers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.cs.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.de.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.en.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.es.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.fr.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.it.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.ja.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.ko.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.pl.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...yst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.pt-BR.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.ru.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...talyst.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.tr.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...t.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.zh-Hans.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...t.Templates/maccatalysttest/csharp/.template.config/localize/templatestrings.zh-Hant.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "Microsoft", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "symbols/bundleId/description": "Overrides the ApplicationId in the project file", | ||
| "symbols/minOSVersion/description": "Overrides SupportedOSPlatformVersion in the project file" | ||
| } |
41 changes: 41 additions & 0 deletions
41
...tes/Microsoft.MacCatalyst.Templates/maccatalysttest/csharp/.template.config/template.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "Microsoft", | ||
| "classifications": [ "macOS", "Mac Catalyst", "Test" ], | ||
| "groupIdentity": "Microsoft.MacCatalyst.MacCatalystTest", | ||
| "identity": "Microsoft.MacCatalyst.MacCatalystTest.CSharp", | ||
| "name": "Mac Catalyst Test Project", | ||
| "description": "A project for creating a .NET Mac Catalyst test project using MSTest", | ||
| "shortName": "maccatalysttest", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "project" | ||
| }, | ||
| "sourceName": "MacCatalystTest1", | ||
| "sources": [ | ||
| { | ||
| "source": "./", | ||
| "target": "./" | ||
| } | ||
| ], | ||
| "preferNameDirectory": true, | ||
| "primaryOutputs": [ | ||
| { "path": "MacCatalystTest1.csproj" } | ||
| ], | ||
| "symbols": { | ||
| "bundleId": { | ||
| "type": "parameter", | ||
| "description": "Overrides the ApplicationId in the project file", | ||
| "datatype": "string", | ||
| "replaces": "com.companyname.MacCatalystTest1" | ||
| }, | ||
| "minOSVersion": { | ||
| "type": "parameter", | ||
| "description": "Overrides SupportedOSPlatformVersion in the project file", | ||
| "replaces": "minOSVersion", | ||
| "datatype": "string", | ||
| "defaultValue": "17.0" | ||
| } | ||
| }, | ||
| "defaultName": "MacCatalystTest1" | ||
| } |
41 changes: 41 additions & 0 deletions
41
dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalysttest/csharp/Info.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleDisplayName</key> | ||
| <string>MacCatalystTest1</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>com.companyname.MacCatalystTest1</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>1.0</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>1.0</string> | ||
| <key>UIDeviceFamily</key> | ||
| <array> | ||
| <integer>2</integer> | ||
| </array> | ||
| <key>UISupportedInterfaceOrientations</key> | ||
| <array> | ||
| <string>UIInterfaceOrientationPortrait</string> | ||
| <string>UIInterfaceOrientationLandscapeLeft</string> | ||
| <string>UIInterfaceOrientationLandscapeRight</string> | ||
| </array> | ||
| <key>UIApplicationSceneManifest</key> | ||
| <dict> | ||
| <key>UIApplicationSupportsMultipleScenes</key> | ||
| <false/> | ||
| <key>UISceneConfigurations</key> | ||
| <dict> | ||
| <key>UIWindowSceneSessionRoleApplication</key> | ||
| <array> | ||
| <dict> | ||
| <key>UISceneConfigurationName</key> | ||
| <string>Default Configuration</string> | ||
| <key>UISceneDelegateClassName</key> | ||
| <string>SceneDelegate</string> | ||
| </dict> | ||
| </array> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
21 changes: 21 additions & 0 deletions
21
.../Templates/Microsoft.MacCatalyst.Templates/maccatalysttest/csharp/MacCatalystTest1.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net11.0-maccatalyst</TargetFramework> | ||
| <RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">MacCatalystTest1</RootNamespace> | ||
| <OutputType>Exe</OutputType> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>true</ImplicitUsings> | ||
| <EnableMSTestRunner>true</EnableMSTestRunner> | ||
| <SupportedOSPlatformVersion>minOSVersion</SupportedOSPlatformVersion> | ||
| <ApplicationId>com.companyname.MacCatalystTest1</ApplicationId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="MSTest" Version="4.2.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
133 changes: 133 additions & 0 deletions
133
dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalysttest/csharp/Main.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| using System.Diagnostics; | ||
| using Microsoft.Testing.Extensions; | ||
| using Microsoft.Testing.Platform.Builder; | ||
| using Microsoft.Testing.Platform.Extensions; | ||
| using Microsoft.Testing.Platform.Extensions.Messages; | ||
| using MacCatalystTest1; | ||
|
|
||
| [assembly: Parallelize (Scope = ExecutionScope.MethodLevel)] | ||
|
|
||
| // UIApplication.Main() provides a proper UIKit run loop, | ||
| // preventing watchdog kills during long test runs. | ||
| UIApplication.Main (args, null, typeof (AppDelegate)); | ||
|
|
||
| [Register ("AppDelegate")] | ||
| class AppDelegate : UIApplicationDelegate { | ||
| public override UISceneConfiguration GetConfiguration (UIApplication application, | ||
| UISceneSession connectingSceneSession, UISceneConnectionOptions options) | ||
| { | ||
| return new UISceneConfiguration ("Default Configuration", connectingSceneSession.Role); | ||
| } | ||
| } | ||
|
|
||
| [Register ("SceneDelegate")] | ||
| class SceneDelegate : UIResponder, IUIWindowSceneDelegate { | ||
| [Export ("window")] | ||
| public UIWindow? Window { get; set; } | ||
|
|
||
| [Export ("scene:willConnectToSession:options:")] | ||
| public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions) | ||
| { | ||
| if (scene is not UIWindowScene windowScene) | ||
| return; | ||
|
|
||
| Window = new UIWindow (windowScene); | ||
| var vc = new UIViewController (); | ||
| var view = vc.View; | ||
| Debug.Assert (view is not null, "UIViewController.View should not be null"); | ||
| view.BackgroundColor = UIColor.SystemBackground; | ||
|
|
||
| var label = new UILabel { | ||
| Text = "Running tests...\n", | ||
| TextAlignment = UITextAlignment.Left, | ||
| Lines = 0, | ||
| Font = UIFont.GetMonospacedSystemFont (12, UIFontWeight.Regular)!, | ||
|
jonathanpeppers marked this conversation as resolved.
|
||
| TextColor = UIColor.Label, | ||
| TranslatesAutoresizingMaskIntoConstraints = false, | ||
| }; | ||
| view.AddSubview (label); | ||
| var guide = view.SafeAreaLayoutGuide; | ||
| label.TopAnchor.ConstraintEqualTo (guide.TopAnchor, 8).Active = true; | ||
| label.LeadingAnchor.ConstraintEqualTo (guide.LeadingAnchor, 8).Active = true; | ||
| label.TrailingAnchor.ConstraintLessThanOrEqualTo (guide.TrailingAnchor, -8).Active = true; | ||
|
|
||
| Window.RootViewController = vc; | ||
| Window.MakeKeyAndVisible (); | ||
|
|
||
| var consumer = new ResultConsumer (); | ||
| consumer.StatusChanged += line => | ||
| vc.InvokeOnMainThread (() => label.Text += line + "\n"); | ||
|
|
||
| Task.Run (async () => { | ||
| try { | ||
| var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); | ||
| var resultsPath = Path.Combine (documentsPath, "TestResults"); | ||
|
|
||
| var builder = await TestApplication.CreateBuilderAsync ([ | ||
| "--results-directory", resultsPath, | ||
| "--report-trx" | ||
| ]); | ||
| builder.AddMSTest (() => [typeof (Test1).Assembly]); | ||
| builder.AddTrxReportProvider (); | ||
| builder.TestHost.AddDataConsumer (_ => consumer); | ||
|
|
||
| using ITestApplication app = await builder.BuildAsync (); | ||
| await app.RunAsync (); | ||
| // UIApplication.Main() keeps the process alive, so exit explicitly | ||
| Environment.Exit (consumer.Failed > 0 ? 1 : 0); | ||
| } catch (Exception ex) { | ||
| Console.WriteLine ($"Error running tests: {ex}"); | ||
| Environment.Exit (1); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| class ResultConsumer : IDataConsumer { | ||
| int _passed, _failed, _skipped; | ||
| public int Passed => _passed; | ||
| public int Failed => _failed; | ||
| public int Skipped => _skipped; | ||
| public string? TrxReportPath; | ||
| public event Action<string>? StatusChanged; | ||
|
|
||
| public string Uid => nameof (ResultConsumer); | ||
| public string DisplayName => nameof (ResultConsumer); | ||
| public string Description => ""; | ||
| public string Version => "1.0"; | ||
| public Task<bool> IsEnabledAsync () => Task.FromResult (true); | ||
|
|
||
| public Type [] DataTypesConsumed => [typeof (TestNodeUpdateMessage), typeof (SessionFileArtifact)]; | ||
|
|
||
| public Task ConsumeAsync (IDataProducer dataProducer, IData value, CancellationToken cancellationToken) | ||
| { | ||
| if (value is SessionFileArtifact artifact) { | ||
| TrxReportPath = artifact.FileInfo.FullName; | ||
|
|
||
| Console.WriteLine ($"Results: passed={Passed}, failed={Failed}, skipped={Skipped}"); | ||
| Console.WriteLine ($"TRX report: {TrxReportPath}"); | ||
| StatusChanged?.Invoke ($"\n✅ {Passed} passed ❌ {Failed} failed ⏭️ {Skipped} skipped"); | ||
| } else if (value is TestNodeUpdateMessage { TestNode: var node }) { | ||
| var state = node.Properties.SingleOrDefault<TestNodeStateProperty> (); | ||
| string? outcome = state switch { | ||
| PassedTestNodeStateProperty => "passed", | ||
| FailedTestNodeStateProperty or ErrorTestNodeStateProperty | ||
| or TimeoutTestNodeStateProperty => "failed", | ||
| SkippedTestNodeStateProperty => "skipped", | ||
| _ => null | ||
| }; | ||
| if (outcome is null) | ||
| return Task.CompletedTask; | ||
|
|
||
| _ = outcome switch { "passed" => Interlocked.Increment (ref _passed), "failed" => Interlocked.Increment (ref _failed), _ => Interlocked.Increment (ref _skipped) }; | ||
|
|
||
| var id = node.Properties.SingleOrDefault<TestMethodIdentifierProperty> (); | ||
| var testName = id is not null ? $"{id.Namespace}.{id.TypeName}.{id.MethodName}" : node.DisplayName; | ||
| Console.WriteLine ($"[{outcome.ToUpperInvariant ()}] {testName}"); | ||
|
|
||
| var icon = outcome switch { "passed" => "✅", "failed" => "❌", _ => "⏭️" }; | ||
| StatusChanged?.Invoke ($"{icon} {testName}"); | ||
| } | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalysttest/csharp/Test1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| namespace MacCatalystTest1; | ||
|
|
||
| [TestClass] | ||
| public sealed class Test1 { | ||
| [TestMethod] | ||
| public void TestMethod1 () | ||
| { | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void TestMethod2 () | ||
| { | ||
| Assert.Fail ("This test is expected to fail"); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void TestMethod3 () | ||
| { | ||
| Assert.Inconclusive ("This test is expected to be skipped"); | ||
|
jonathanpeppers marked this conversation as resolved.
|
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.