Skip to content

Commit

Permalink
Move TryGetAuthProvider to new IApplicationEnvironmentV2 interface (#365
Browse files Browse the repository at this point in the history
)

* Move TryGetAuthProvider to new IApplicationEnvironmentV2 interface

* Document param

* Add docstring

* Fix tests
  • Loading branch information
mslukebo authored Jul 22, 2024
1 parent 765f36a commit 2e1a1bf
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.Performance.SDK.Runtime
{
/// <inheritdoc cref="IApplicationEnvironment"/>
public class ApplicationEnvironment
: IApplicationEnvironment
: IApplicationEnvironmentV2

Check warning on line 16 in src/Microsoft.Performance.SDK.Runtime/ApplicationEnvironment.cs

View workflow job for this annotation

GitHub Actions / Build and test

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'

Check warning on line 16 in src/Microsoft.Performance.SDK.Runtime/ApplicationEnvironment.cs

View workflow job for this annotation

GitHub Actions / Build

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'
{
private readonly IMessageBox messageBox;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Microsoft.Performance.SDK.Tests.TestClasses
{
public class TestApplicationEnvironment
: IApplicationEnvironment
: IApplicationEnvironmentV2

Check warning on line 13 in src/Microsoft.Performance.SDK.Tests/TestClasses/TestApplicationEnvironment.cs

View workflow job for this annotation

GitHub Actions / Build and test

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'

Check warning on line 13 in src/Microsoft.Performance.SDK.Tests/TestClasses/TestApplicationEnvironment.cs

View workflow job for this annotation

GitHub Actions / Build

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'
{
public string ApplicationName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Globalization;
using Microsoft.Performance.SDK.Auth;

namespace Microsoft.Performance.SDK.Processing
{
Expand Down Expand Up @@ -143,5 +144,40 @@ public static void ShowError(
{
self.DisplayMessage(MessageType.Error, formatProvider, format, args);
}

/// <summary>
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
/// </summary>
/// <param name="self">
/// The <see cref="IApplicationEnvironment"/> instance.
/// </param>
/// <param name="provider">
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
/// <typeparamref name="TAuth"/>.
/// </param>
/// <typeparam name="TAuth">
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
/// </typeparam>
/// <typeparam name="TResult">
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
/// </typeparam>
/// <returns>
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
/// <paramref name="provider"/> will be <c>null</c>.
/// </returns>
public static bool TryGetAuthProvider<TAuth, TResult>(
this IApplicationEnvironment self,
out IAuthProvider<TAuth, TResult> provider)
where TAuth : IAuthMethod<TResult>
{
if (self is IApplicationEnvironmentV2 v2)

Check warning on line 174 in src/Microsoft.Performance.SDK/Processing/ApplicationEnvironmentExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and test

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'

Check warning on line 174 in src/Microsoft.Performance.SDK/Processing/ApplicationEnvironmentExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'
{
return v2.TryGetAuthProvider(out provider);
}

provider = null;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System;
using Microsoft.Performance.SDK.Auth;
using Microsoft.Performance.SDK.Extensibility.DataCooking;
using Microsoft.Performance.SDK.Extensibility.SourceParsing;

Expand Down Expand Up @@ -118,26 +117,5 @@ ButtonResult MessageBox(
string caption,
string format,
params object[] args);

/// <summary>
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
/// </summary>
/// <param name="provider">
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
/// <typeparamref name="TAuth"/>.
/// </param>
/// <typeparam name="TAuth">
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
/// </typeparam>
/// <typeparam name="TResult">
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
/// </typeparam>
/// <returns>
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
/// <paramref name="provider"/> will be <c>null</c>.
/// </returns>
bool TryGetAuthProvider<TAuth, TResult>(out IAuthProvider<TAuth, TResult> provider)
where TAuth : IAuthMethod<TResult>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Microsoft.Performance.SDK.Auth;

namespace Microsoft.Performance.SDK.Processing
{
/// <summary>
/// Extends <see cref="IApplicationEnvironment"/> to provide additional functionality.
/// </summary>
[Obsolete("This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.")]
public interface IApplicationEnvironmentV2
: IApplicationEnvironment
{
/// <summary>
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
/// </summary>
/// <param name="provider">
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
/// <typeparamref name="TAuth"/>.
/// </param>
/// <typeparam name="TAuth">
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
/// </typeparam>
/// <typeparam name="TResult">
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
/// </typeparam>
/// <returns>
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
/// <paramref name="provider"/> will be <c>null</c>.
/// </returns>
bool TryGetAuthProvider<TAuth, TResult>(out IAuthProvider<TAuth, TResult> provider)
where TAuth : IAuthMethod<TResult>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Microsoft.Performance.Testing.SDK
{
public class StubApplicationEnvironment
: IApplicationEnvironment
: IApplicationEnvironmentV2

Check warning on line 13 in src/Microsoft.Performance.Testing.SDK/StubApplicationEnvironment.cs

View workflow job for this annotation

GitHub Actions / Build and test

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'

Check warning on line 13 in src/Microsoft.Performance.Testing.SDK/StubApplicationEnvironment.cs

View workflow job for this annotation

GitHub Actions / Build

'IApplicationEnvironmentV2' is obsolete: 'This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.'
{
public string ApplicationName { get; set; }

Expand Down

0 comments on commit 2e1a1bf

Please sign in to comment.