Skip to content

Commit

Permalink
[C#] chore: fixing check annotations (#1701)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #1290

## Details

- async/await on non-implemented method
- null literal assignment
- missing XML comment
- general catch
- sealed classes

## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes
  • Loading branch information
lilyydu authored Jun 4, 2024
1 parent dc138c3 commit 781e823
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Test_ChatCompletionsToolCall_InvalidToolType()
Assert.Equal($"Invalid ChatCompletionsToolCall type: {nameof(InvalidToolCall)}", ex.Message);
}

private class InvalidToolCall : Azure.AI.OpenAI.ChatCompletionsToolCall
private sealed class InvalidToolCall : Azure.AI.OpenAI.ChatCompletionsToolCall
{
public InvalidToolCall() : base("test-id")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void Test_ChatCompletionsToolCall_InvalidToolType()
Assert.Equal("Invalid tool type: invalidToolType", ex.Message);
}

private class InvalidToolCall : AI.Models.ChatCompletionsToolCall
private sealed class InvalidToolCall : AI.Models.ChatCompletionsToolCall
{
public InvalidToolCall() : base("invalidToolType", "test-id")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Test_SequentialDelayStrategy()
}
}

internal class TestSequentialDelayStrategy : SequentialDelayStrategy
internal sealed class TestSequentialDelayStrategy : SequentialDelayStrategy
{
public TestSequentialDelayStrategy(List<TimeSpan> delays) : base(delays)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.Teams.AI.Tests.Application.Authentication
{
internal class AppConfig : IAppConfig
internal sealed class AppConfig : IAppConfig
{
#pragma warning disable CS8618 // This class is for test purpose only
public AppConfig(string clientId, string tenantId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.Teams.AI.Tests.Application.Authentication.Bot
{
internal class TestOAuthBotAuthentication : OAuthBotAuthentication<TurnState>
internal sealed class TestOAuthBotAuthentication : OAuthBotAuthentication<TurnState>
{
public TestOAuthBotAuthentication(Application<TurnState> app, OAuthSettings oauthSettings, string settingName, IStorage? storage = null) : base(app, oauthSettings, settingName, storage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Teams.AI.Tests.Application.Authentication.Bot
{
public class TeamsSsoBotAuthenticationTests
{
internal class MockTeamsSsoBotAuthentication<TState> : TeamsSsoBotAuthentication<TState>
internal sealed class MockTeamsSsoBotAuthentication<TState> : TeamsSsoBotAuthentication<TState>
where TState : TurnState, new()
{
public MockTeamsSsoBotAuthentication(Application<TState> app, string name, TeamsSsoSettings settings, TeamsSsoPrompt? mockPrompt = null) : base(app, name, settings, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TeamsSsoPromptTests
private const string AuthStartPage = "https://localhost/auth-start.html";
private const string AccessToken = "test token";

private class TeamsSsoPromptMock : TeamsSsoPrompt
private sealed class TeamsSsoPromptMock : TeamsSsoPrompt
{
public TeamsSsoPromptMock(string dialogId, string name, TeamsSsoSettings settings, IConfidentialClientApplicationAdapter msalAdapterMock) : base(dialogId, name, settings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TeamsSsoMessageExtensionsAuthenticationTests
private const string AuthStartPage = "https://localhost/auth-start.html";
private const string AccessToken = "test token";

private class TeamsSsoMessageExtensionsAuthenticationMock : TeamsSsoMessageExtensionsAuthentication
private sealed class TeamsSsoMessageExtensionsAuthenticationMock : TeamsSsoMessageExtensionsAuthentication
{
public TeamsSsoMessageExtensionsAuthenticationMock(TeamsSsoSettings settings, IConfidentialClientApplicationAdapter msalAdapterMock) : base(settings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TeamsSsoAuthenticationTests
private const string AuthStartPage = "https://localhost/auth-start.html";
private const string AccessToken = "test token";

private class TeamsSsoAuthenticationMock<TState> : TeamsSsoAuthentication<TState>
private sealed class TeamsSsoAuthenticationMock<TState> : TeamsSsoAuthentication<TState>
where TState : TurnState, new()
{
public TeamsSsoAuthenticationMock(Application<TState> app, string name, TeamsSsoSettings settings, IConfidentialClientApplicationAdapter msalAdapterMock) : base(app, name, settings, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.Teams.AI.Tests.Application.Authentication
{
internal class TestAuthenticationManager : AuthenticationManager<TurnState>
internal sealed class TestAuthenticationManager : AuthenticationManager<TurnState>
{
public TestAuthenticationManager(AuthenticationOptions<TurnState> options, Application<TurnState> app, IStorage? storage = null) : base(app, options, storage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ public async void Test_SaveState_Existing_Loading_Operation()
{
await state.SaveStateAsync(turnContext, null);
}
#pragma warning disable CA1031
catch (Exception)
{
#pragma warning restore CA1031
// Ignore the exception, this is the expected behavior is state is not loaded.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public PredictedSayCommand(ChatMessage response)
Response = response;
}

/// <summary>
/// Creates a new instance of the <see cref="PredictedSayCommand"/> class.
/// </summary>
/// <param name="response">The response that the AI system should say.</param>
public PredictedSayCommand(string response)
{
Response = new ChatMessage(ChatRole.Assistant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public Application<TState> OnHandoff(HandoffHandler<TState> handler)
);
RouteHandler<TState> routeHandler = async (turnContext, turnState, cancellationToken) =>
{
string token = turnContext.Activity.Value.GetType().GetProperty("Continuation").GetValue(turnContext.Activity.Value) as string;
string token = turnContext.Activity.Value.GetType().GetProperty("Continuation").GetValue(turnContext.Activity.Value) as string ?? "";
await handler(turnContext, turnState, token, cancellationToken);

// Check to see if an invoke response has already been added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ internal abstract class AdaptiveCardsAuthenticationBase
/// </summary>
/// <param name="context">The turn context</param>
/// <returns>The sign in response</returns>
#pragma warning disable 1998 // Await call for non-implemented method
public async Task<SignInResponse> AuthenticateAsync(ITurnContext context)
{
throw new NotImplementedException();
}
#pragma warning restore 1998

/// <summary>
/// Whether the current activity is a valid activity that supports authentication
Expand Down

0 comments on commit 781e823

Please sign in to comment.