Skip to content
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

chore(playwrighttesting): update public classes, methods and constants as per APIView review #47652

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.Developer.MicrosoftPlaywrightTesting'))">
<PackageReference Update="Microsoft.TestPlatform.ObjectModel" Version="17.10.0" />
<PackageReference Update="NUnit" Version="3.13.2" />
<PackageReference Update="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Update="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.Contains('CloudMachine'))">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit
[NUnit.Framework.SetUpFixtureAttribute]
public partial class PlaywrightServiceNUnit : Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightService
{
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? credential = null) : base (default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions), default(Azure.Core.TokenCredential), default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface.IFrameworkLogger)) { }
public static Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions playwrightServiceOptions { get { throw null; } }
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? credential = null) : base (default(Azure.Core.TokenCredential), default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions)) { }
public static Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions options { get { throw null; } }
[NUnit.Framework.OneTimeSetUpAttribute]
public System.Threading.Tasks.Task SetupAsync() { throw null; }
[NUnit.Framework.OneTimeTearDownAttribute]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit
[NUnit.Framework.SetUpFixtureAttribute]
public partial class PlaywrightServiceNUnit : Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightService
{
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? credential = null) : base (default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions), default(Azure.Core.TokenCredential), default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface.IFrameworkLogger)) { }
public static Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions playwrightServiceOptions { get { throw null; } }
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? credential = null) : base (default(Azure.Core.TokenCredential), default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions)) { }
public static Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions options { get { throw null; } }
[NUnit.Framework.OneTimeSetUpAttribute]
public System.Threading.Tasks.Task SetupAsync() { throw null; }
[NUnit.Framework.OneTimeTearDownAttribute]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\..\Azure.Developer.MicrosoftPlaywrightTesting.TestLogger\src\Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.csproj" />
<PackageReference Include="NUnit" />
<PackageReference Include ="Microsoft.Extensions.Logging" />
</ItemGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Extensions.Logging;
using NUnit.Framework;

namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit;

internal class NUnitLogger : ILogger
{
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
{
return;
}
if (formatter == null)
{
throw new ArgumentNullException(nameof(formatter));
}
string message = formatter(state, exception);
if (exception != null)
{
message += $"\nException: {exception}";
}
Log(logLevel, message);
}

public bool IsEnabled(LogLevel logLevel)
{
return true;
}

IDisposable? ILogger.BeginScope<TState>(TState state)
{
return NullScope.Instance;
}

private static void Log(LogLevel level, string message)
{
System.IO.TextWriter writer = (level == LogLevel.Error || level == LogLevel.Warning || level == LogLevel.Critical) ? Console.Error : Console.Out;
writer.WriteLine($"{DateTime.Now} [{level}]: {message}");

if (level == LogLevel.Debug)
{
TestContext.WriteLine($"[MPT-NUnit]: {message}");
}
else if (level == LogLevel.Error || level == LogLevel.Critical)
{
TestContext.Error.WriteLine($"[MPT-NUnit]: {message}");
}
else
{
TestContext.Progress.WriteLine($"[MPT-NUnit]: {message}");
}
}
};

internal class NullScope : IDisposable
{
public static readonly NullScope Instance = new();

private NullScope() { }

public void Dispose()
{
// No operation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Runtime.InteropServices;
using System;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface;
using Microsoft.Extensions.Logging;

namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit;

Expand All @@ -17,28 +17,32 @@ namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit;
[SetUpFixture]
public class PlaywrightServiceNUnit : PlaywrightService
{
private static NUnitFrameworkLogger nunitFrameworkLogger { get; } = new();
private static NUnitLogger nunitLogger { get; } = new();
private static readonly string? s_useCloudHostedBrowsers = TestContext.Parameters.Get(RunSettingKey.UseCloudHostedBrowsers.ToString());
private static readonly string? s_serviceAuthType = TestContext.Parameters.Get(RunSettingKey.ServiceAuthType.ToString());
/// <summary>
/// Initializes a new instance of the <see cref="PlaywrightServiceNUnit"/> class.
/// </summary>
/// <param name="credential">The azure token credential to use for authentication.</param>
public PlaywrightServiceNUnit(TokenCredential? credential = null)
: base(playwrightServiceOptions, credential: credential, frameworkLogger: nunitFrameworkLogger)
: base(credential, options)
{
}

/// <summary>
/// Creates a new instance of <see cref="PlaywrightServiceOptions"/> based on the runsettings file.
/// </summary>
public static PlaywrightServiceOptions playwrightServiceOptions { get; } = new(
os: GetOsPlatform(TestContext.Parameters.Get(RunSettingKey.Os)),
runId: TestContext.Parameters.Get(RunSettingKey.RunId),
exposeNetwork: TestContext.Parameters.Get(RunSettingKey.ExposeNetwork),
serviceAuth: TestContext.Parameters.Get(RunSettingKey.ServiceAuthType),
useCloudHostedBrowsers: TestContext.Parameters.Get(RunSettingKey.UseCloudHostedBrowsers),
azureTokenCredentialType: TestContext.Parameters.Get(RunSettingKey.AzureTokenCredentialType),
managedIdentityClientId: TestContext.Parameters.Get(RunSettingKey.ManagedIdentityClientId)
);
public static PlaywrightServiceOptions options { get; } = new()
{
OS = GetOsPlatform(TestContext.Parameters.Get(RunSettingKey.OS.ToString())),
RunId = TestContext.Parameters.Get(RunSettingKey.RunId.ToString()),
ExposeNetwork = TestContext.Parameters.Get(RunSettingKey.ExposeNetwork.ToString()),
ServiceAuth = string.IsNullOrEmpty(s_serviceAuthType) ? default : new ServiceAuthType(s_serviceAuthType!),
UseCloudHostedBrowsers = !string.IsNullOrEmpty(s_useCloudHostedBrowsers) && bool.Parse(s_useCloudHostedBrowsers),
TokenCredentialType = TestContext.Parameters.Get(RunSettingKey.AzureTokenCredentialType.ToString()),
ManagedIdentityClientId = TestContext.Parameters.Get(RunSettingKey.ManagedIdentityClientId.ToString()),
Logger = nunitLogger
};

/// <summary>
/// Setup the resources utilized by Playwright service.
Expand All @@ -49,7 +53,7 @@ public async Task SetupAsync()
{
if (!UseCloudHostedBrowsers)
return;
nunitFrameworkLogger.Info("\nRunning tests using Microsoft Playwright Testing service.\n");
nunitLogger.LogInformation("\nRunning tests using Microsoft Playwright Testing service.\n");

await InitializeAsync().ConfigureAwait(false);
}
Expand Down
Loading
Loading