diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 393d187..23d3744 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,11 +3,11 @@ "isRoot": true, "tools": { "csharpier": { - "version": "0.30.6", + "version": "1.1.2", "commands": [ - "dotnet-csharpier" + "csharpier" ], "rollForward": false } } -} \ No newline at end of file +} diff --git a/.github/workflows/azure-webapps-dotnet-core.yml b/.github/workflows/azure-webapps-dotnet-core.yml index 47c3fe4..b225e86 100644 --- a/.github/workflows/azure-webapps-dotnet-core.yml +++ b/.github/workflows/azure-webapps-dotnet-core.yml @@ -59,7 +59,7 @@ jobs: - name: linting / csharpier run: | dotnet tool restore - dotnet csharpier --check . + dotnet csharpier check . - name: Build with dotnet run: dotnet build --configuration Release diff --git a/OpenAIChatGPTBlazor/Components/Pages/EditImage.razor.cs b/OpenAIChatGPTBlazor/Components/Pages/EditImage.razor.cs index 0cb64c7..a2f6eed 100644 --- a/OpenAIChatGPTBlazor/Components/Pages/EditImage.razor.cs +++ b/OpenAIChatGPTBlazor/Components/Pages/EditImage.razor.cs @@ -67,16 +67,19 @@ private async Task OnFileSelected(InputFileChangeEventArgs e) // Read and display the uploaded image (read full stream) using var stream = _uploadedFile.OpenReadStream(maxFileSize); var buffer = new byte[_uploadedFile.Size]; - int totalRead = 0; + var totalRead = 0; while (totalRead < buffer.Length) { - int read = await stream.ReadAsync( + var read = await stream.ReadAsync( buffer, totalRead, buffer.Length - totalRead ); if (read == 0) + { break; + } + totalRead += read; } @@ -114,7 +117,9 @@ private async Task OnPromptKeydown(KeyboardEventArgs e) private async Task RunEdit() { if (_uploadedFile == null || string.IsNullOrWhiteSpace(_prompt)) + { return; + } try { @@ -129,17 +134,20 @@ private async Task RunEdit() const long maxFileSize = 50 * 1024 * 1024; // 50 MB using var stream = _uploadedFile.OpenReadStream(maxFileSize); var buffer = new byte[_uploadedFile.Size]; - int totalRead = 0; + var totalRead = 0; while (totalRead < buffer.Length) { - int read = await stream.ReadAsync( + var read = await stream.ReadAsync( buffer, totalRead, buffer.Length - totalRead, _editCancellationTokenSource.Token ); if (read == 0) + { break; + } + totalRead += read; } var imageStream = new System.IO.MemoryStream(buffer); @@ -210,7 +218,9 @@ private void AbortEdit() private async Task DownloadEditedImage() { if (_editedImageData == null) + { return; + } try { diff --git a/OpenAIChatGPTBlazor/Components/Pages/Index.razor.cs b/OpenAIChatGPTBlazor/Components/Pages/Index.razor.cs index 405936d..8adac77 100644 --- a/OpenAIChatGPTBlazor/Components/Pages/Index.razor.cs +++ b/OpenAIChatGPTBlazor/Components/Pages/Index.razor.cs @@ -66,7 +66,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) await InitiateChat(); _loading = false; - this.StateHasChanged(); + StateHasChanged(); await _nextArea.FocusAsync(); // Register paste handler for images @@ -99,15 +99,9 @@ async ValueTask IAsyncDisposable.DisposeAsync() } } - private async Task OnSearchClick() - { - await RunSearch(); - } + private async Task OnSearchClick() => await RunSearch(); - private void OnAbortClick() - { - AbortSearch(); - } + private void OnAbortClick() => AbortSearch(); private async Task OnNextKeydown(KeyboardEventArgs e) { @@ -151,7 +145,7 @@ private async Task RunSearch() try { _loading = true; - this.StateHasChanged(); + StateHasChanged(); if (_file == null) { @@ -198,12 +192,12 @@ private async Task RunSearch() if (selectedOption.HasStreamingSupport) { var updates = client.CompleteChatStreamingAsync(_chatMessages); - await foreach (StreamingChatCompletionUpdate update in updates) + await foreach (var update in updates) { - foreach (ChatMessageContentPart updatePart in update.ContentUpdate) + foreach (var updatePart in update.ContentUpdate) { _stream += updatePart.Text; - this.StateHasChanged(); + StateHasChanged(); if (_isAutoscrollEnabled && _module is not null) { await _module.InvokeVoidAsync("scrollElementToEnd", _mainArea); @@ -249,12 +243,15 @@ Microsoft.AspNetCore.Components.Forms.InputFileChangeEventArgs e { var buffer = new byte[file.Size]; using var stream = file.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); - int totalRead = 0; + var totalRead = 0; while (totalRead < buffer.Length) { - int read = await stream.ReadAsync(buffer, totalRead, buffer.Length - totalRead); + var read = await stream.ReadAsync(buffer, totalRead, buffer.Length - totalRead); if (read == 0) + { break; + } + totalRead += read; } _file = (file.Name, new BinaryData(buffer), file.ContentType); @@ -282,10 +279,7 @@ private void AbortSearch() } } - private void DeleteMessage(ChatMessage chatMessage) - { - _chatMessages.Remove(chatMessage); - } + private void DeleteMessage(ChatMessage chatMessage) => _chatMessages.Remove(chatMessage); private async void CopyMessageToNext(ChatMessage chatMessage) { @@ -295,7 +289,7 @@ private async void CopyMessageToNext(ChatMessage chatMessage) private async Task DownloadConversation() { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); + var sb = new System.Text.StringBuilder(); sb.AppendLine("# ChatGPT Conversation"); foreach (var message in _chatMessages) { @@ -379,21 +373,17 @@ private async Task InitiateChat() } } - private static string GetChatMessageContent(ChatMessage message) - { - return message.Content.FirstOrDefault()?.Text ?? "[No Text]"; - } + private static string GetChatMessageContent(ChatMessage message) => + message.Content.FirstOrDefault()?.Text ?? "[No Text]"; - private string GetChatMessageRole(ChatMessage message) - { - return message switch + private string GetChatMessageRole(ChatMessage message) => + message switch { SystemChatMessage => ROLE_SYSTEM, UserChatMessage => ROLE_USER, AssistantChatMessage => ROLE_ASSISTANT, _ => "unknown", }; - } private IList JsonToChat(string json) { @@ -414,6 +404,6 @@ private IList JsonToChat(string json) return result; } - record MyChatMessage(string role, string message); + private record MyChatMessage(string role, string message); } } diff --git a/OpenAIChatGPTBlazor/OpenAIChatGPTBlazor.csproj b/OpenAIChatGPTBlazor/OpenAIChatGPTBlazor.csproj index 07c6356..fb1630d 100644 --- a/OpenAIChatGPTBlazor/OpenAIChatGPTBlazor.csproj +++ b/OpenAIChatGPTBlazor/OpenAIChatGPTBlazor.csproj @@ -1,26 +1,26 @@ - - - net9.0 - enable - enable - a9111ff4-d5fb-46b5-9450-c68be5805382 - Linux - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - \ No newline at end of file + + net9.0 + enable + enable + a9111ff4-d5fb-46b5-9450-c68be5805382 + Linux + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/Tests/UiTests/BasicTest.cs b/Tests/UiTests/BasicTest.cs index 2223b34..94b6170 100644 --- a/Tests/UiTests/BasicTest.cs +++ b/Tests/UiTests/BasicTest.cs @@ -1,4 +1,4 @@ -using Microsoft.Playwright; +using Microsoft.Playwright; using Microsoft.Playwright.NUnit; using NUnit.Framework; @@ -12,15 +12,10 @@ public class BasicTest : PageTest Environment.GetEnvironmentVariable("AppUrl") ?? "https://localhost:7128/"; [SetUp] - public async Task SetUp() - { - await Page.GotoAsync(BaseUrl); - } + public async Task SetUp() => await Page.GotoAsync(BaseUrl); [Test] - public async Task SystemMessageShouldBePreset() - { + public async Task SystemMessageShouldBePreset() => await Expect(Page.GetByText("You are the assistant of a software engineer")) .ToBeVisibleAsync(); - } } diff --git a/Tests/UiTests/FocusTests.cs b/Tests/UiTests/FocusTests.cs index e905d11..06cfc1c 100644 --- a/Tests/UiTests/FocusTests.cs +++ b/Tests/UiTests/FocusTests.cs @@ -1,4 +1,4 @@ -using Microsoft.Playwright; +using Microsoft.Playwright; using Microsoft.Playwright.NUnit; using NUnit.Framework; @@ -9,10 +9,7 @@ namespace UiTests; public class FocusTests : PageTest { [SetUp] - public async Task SetUp() - { - await Page.GotoAsync(BasicTest.BaseUrl); - } + public async Task SetUp() => await Page.GotoAsync(BasicTest.BaseUrl); [Test] public async Task NextAreaShouldHaveFocusAfterLoading() diff --git a/Tests/UiTests/GenerateImageTests.cs b/Tests/UiTests/GenerateImageTests.cs index 7e91c59..2972a01 100644 --- a/Tests/UiTests/GenerateImageTests.cs +++ b/Tests/UiTests/GenerateImageTests.cs @@ -1,4 +1,4 @@ -using Microsoft.Playwright; +using Microsoft.Playwright; using Microsoft.Playwright.NUnit; using NUnit.Framework; @@ -9,15 +9,11 @@ namespace UiTests; public class GenerateImageTests : PageTest { [SetUp] - public async Task SetUp() - { + public async Task SetUp() => await Page.GotoAsync(Path.Combine(BasicTest.BaseUrl, "GenerateImage")); - } [Test] - public async Task PageShouldLoadAndShowHeading() - { + public async Task PageShouldLoadAndShowHeading() => await Expect(Page.GetByText("Welcome to my Image Generation using OpenAI")) .ToBeVisibleAsync(); - } } diff --git a/Tests/UiTests/SettingsTests.cs b/Tests/UiTests/SettingsTests.cs index 6bf9d26..28e1e33 100644 --- a/Tests/UiTests/SettingsTests.cs +++ b/Tests/UiTests/SettingsTests.cs @@ -1,4 +1,4 @@ -using Microsoft.Playwright; +using Microsoft.Playwright; using Microsoft.Playwright.NUnit; using NUnit.Framework; @@ -40,7 +40,7 @@ await Page.WaitForFunctionAsync( "() => localStorage.getItem('IsAutoscrollEnabled')" ); Assert.IsTrue( - Boolean.TryParse(storedString, out var storedAfter), + bool.TryParse(storedString, out var storedAfter), $"{storedString} expected to be a valid bool" ); Assert.AreNotEqual(checkedBefore, storedAfter, "expected changed value"); diff --git a/Tests/UiTests/UiTests.csproj b/Tests/UiTests/UiTests.csproj index 6227efc..147b3df 100644 --- a/Tests/UiTests/UiTests.csproj +++ b/Tests/UiTests/UiTests.csproj @@ -1,16 +1,13 @@  - net9.0 enable enable - false true Linux ..\.. - @@ -19,14 +16,14 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + - - + all runtime; build; native; contentfiles; analyzers - - \ No newline at end of file +