From 6978a443df02100f550fdba500e9d743ac1fe344 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 21:58:50 +0100 Subject: [PATCH 1/3] Update to .NET 10 LTS and bump dependencies - net9.0 -> net10.0 (app and tests), Docker images sdk/aspnet 10.0 - MinimalTelegramBot 0.0.40 -> 0.1.0, Scrutor 6.1.0 -> 7.0.0 - TUnit 0.24.0 -> 1.81.10 - CI: .NET 10 SDK, checkout/setup-dotnet v5, run build and tests on pull requests; image publishing stays on pushes to master only Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RYcxAF7nv5jXyZ3ARrbQWA --- .github/workflows/build.yaml | 11 +++++++---- TTSBot.Tests/TTSBot.Tests.csproj | 4 ++-- TTSBot/Dockerfile | 4 ++-- TTSBot/TTSBot.csproj | 6 +++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5ab0882..5560c02 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,6 +3,8 @@ name: Build-Test-Publish Flow on: push: branches: [ "master" ] + pull_request: + branches: [ "master" ] jobs: build_test: @@ -10,11 +12,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore - name: Build @@ -25,6 +27,7 @@ jobs: build_docker_iamge: name: Build and Push Docker Image needs: build_test + if: github.event_name == 'push' runs-on: ubuntu-latest permissions: packages: write @@ -34,7 +37,7 @@ jobs: echo "DOCKER_IMAGE_POSTFIX=$(date +%Y-%m-%d_%s)" >> "$GITHUB_ENV" echo "DOCKER_IMAGE_NAME=ghcr.io/rumkit/telegram-torrserver-bot" >> "$GITHUB_ENV" - name: Checkout the repo - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Log in to the Container registry uses: docker/login-action@v3 diff --git a/TTSBot.Tests/TTSBot.Tests.csproj b/TTSBot.Tests/TTSBot.Tests.csproj index 690b4d4..447fa59 100644 --- a/TTSBot.Tests/TTSBot.Tests.csproj +++ b/TTSBot.Tests/TTSBot.Tests.csproj @@ -4,12 +4,12 @@ enable annotations Exe - net9.0 + net10.0 default - + diff --git a/TTSBot/Dockerfile b/TTSBot/Dockerfile index 4d0a8e3..a32e717 100644 --- a/TTSBot/Dockerfile +++ b/TTSBot/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base USER $APP_UID WORKDIR /app -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["TTSBot/TTSBot.csproj", "TTSBot/"] diff --git a/TTSBot/TTSBot.csproj b/TTSBot/TTSBot.csproj index bddd41e..c352e6e 100644 --- a/TTSBot/TTSBot.csproj +++ b/TTSBot/TTSBot.csproj @@ -2,7 +2,7 @@ Exe - net9.0 + net10.0 enable enable Linux @@ -16,8 +16,8 @@ - - + + From cd07c7418e9c2f4f44dff390c2a19f98fcc2b2b6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:03:33 +0100 Subject: [PATCH 2/3] Port tests to TUnit 1.x and current Telegram.Bot APIs - Replace ValueAssertCondition-based custom assertions with a single Assertion subclass and IAssertionSource extensions - IReplyMarkup is now the ReplyMarkup class - Implement ITelegramBotClient.DownloadFile(TGFile, ...) in the mock - Drop the removed AssertConditions.Throws namespace Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RYcxAF7nv5jXyZ3ARrbQWA --- .../BotRequestContextExtensionsTests.cs | 1 - .../Assertions/AssertionExtensions.cs | 62 ++++++++++++++----- .../MessageResultKindAssertCondition.cs | 22 ------- .../MessageResultTextAssertCondition.cs | 22 ------- .../TestUtils/Assertions/ResultAssertion.cs | 23 +++++++ .../SpecificInternalTypeAssertCondition.cs | 17 ----- TTSBot.Tests/TestUtils/MockTelegramClient.cs | 6 ++ TTSBot.Tests/TestUtils/ResultExtensions.cs | 4 +- 8 files changed, 78 insertions(+), 79 deletions(-) delete mode 100644 TTSBot.Tests/TestUtils/Assertions/MessageResultKindAssertCondition.cs delete mode 100644 TTSBot.Tests/TestUtils/Assertions/MessageResultTextAssertCondition.cs create mode 100644 TTSBot.Tests/TestUtils/Assertions/ResultAssertion.cs delete mode 100644 TTSBot.Tests/TestUtils/Assertions/SpecificInternalTypeAssertCondition.cs diff --git a/TTSBot.Tests/Extensions/BotRequestContextExtensionsTests.cs b/TTSBot.Tests/Extensions/BotRequestContextExtensionsTests.cs index d9f9e4b..e6218c3 100644 --- a/TTSBot.Tests/Extensions/BotRequestContextExtensionsTests.cs +++ b/TTSBot.Tests/Extensions/BotRequestContextExtensionsTests.cs @@ -1,7 +1,6 @@ using Telegram.Bot.Types; using TTSBot.Extensions; using TTSBot.Tests.TestUtils; -using TUnit.Assertions.AssertConditions.Throws; namespace TTSBot.Tests.Extensions; diff --git a/TTSBot.Tests/TestUtils/Assertions/AssertionExtensions.cs b/TTSBot.Tests/TestUtils/Assertions/AssertionExtensions.cs index aa826d2..077f9d9 100644 --- a/TTSBot.Tests/TestUtils/Assertions/AssertionExtensions.cs +++ b/TTSBot.Tests/TestUtils/Assertions/AssertionExtensions.cs @@ -1,28 +1,60 @@ -using MinimalTelegramBot.Results; -using TUnit.Assertions.AssertConditions.Interfaces; -using TUnit.Assertions.AssertionBuilders; +using System.Runtime.CompilerServices; +using MinimalTelegramBot.Results; +using TUnit.Assertions.Core; namespace TTSBot.Tests.TestUtils.Assertions; public static class AssertionExtensions { - public static InvokableValueAssertionBuilder IsMessage(this IValueSource valueSource) + public static ResultAssertion IsMessage(this IAssertionSource source) { - return valueSource.RegisterAssertion(new MessageResultKindAssertCondition(MessageResult.Message), []); + source.Context.ExpressionBuilder.Append(".IsMessage()"); + return new ResultAssertion(source.Context, r => CheckMessageKind(r, MessageResult.Message), + $"to be MessageResult of kind {MessageResult.Message}"); } - - public static InvokableValueAssertionBuilder IsReply(this IValueSource valueSource) + + public static ResultAssertion IsReply(this IAssertionSource source) { - return valueSource.RegisterAssertion(new MessageResultKindAssertCondition(MessageResult.Reply), []); + source.Context.ExpressionBuilder.Append(".IsReply()"); + return new ResultAssertion(source.Context, r => CheckMessageKind(r, MessageResult.Reply), + $"to be MessageResult of kind {MessageResult.Reply}"); } - - public static InvokableValueAssertionBuilder IsEmpty(this IValueSource valueSource) + + public static ResultAssertion IsEmpty(this IAssertionSource source) { - return valueSource.RegisterAssertion(new SpecificInternalTypeAssertCondition("EmptyResult"), []); + source.Context.ExpressionBuilder.Append(".IsEmpty()"); + return new ResultAssertion(source.Context, r => CheckTypeName(r, "EmptyResult"), + "to be of type EmptyResult"); } - - public static InvokableValueAssertionBuilder HasMessage(this IValueSource valueSource, string message) + + public static ResultAssertion HasMessage(this IAssertionSource source, string message, + [CallerArgumentExpression(nameof(message))] string? expression = null) { - return valueSource.RegisterAssertion(new MessageResultTextAssertCondition(message), []); + source.Context.ExpressionBuilder.Append($".HasMessage({expression})"); + return new ResultAssertion(source.Context, r => + { + var typeFailure = CheckTypeName(r, "MessageResult"); + if (typeFailure is not null) + return typeFailure; + + var actualText = r!.GetMessageText(); + return actualText == message ? null : $"MessageResult has text: {actualText}"; + }, $"to have message set to: {message}"); + } + + private static string? CheckTypeName(IResult? result, string expectedTypeName) + { + var actualTypeName = result?.GetType().Name; + return actualTypeName == expectedTypeName ? null : $"Has actual type {actualTypeName}"; + } + + private static string? CheckMessageKind(IResult? result, MessageResult expectedKind) + { + var typeFailure = CheckTypeName(result, "MessageResult"); + if (typeFailure is not null) + return typeFailure; + + var kind = result!.GetMessageKind(); + return kind == expectedKind ? null : $"MessageResult is of kind {kind}"; } -} \ No newline at end of file +} diff --git a/TTSBot.Tests/TestUtils/Assertions/MessageResultKindAssertCondition.cs b/TTSBot.Tests/TestUtils/Assertions/MessageResultKindAssertCondition.cs deleted file mode 100644 index bcdd044..0000000 --- a/TTSBot.Tests/TestUtils/Assertions/MessageResultKindAssertCondition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using MinimalTelegramBot.Results; -using TUnit.Assertions.AssertConditions; - -namespace TTSBot.Tests.TestUtils.Assertions; - -public class MessageResultKindAssertCondition(MessageResult expectedMessageResultKind) : ValueAssertCondition -{ - protected override AssertionResult Passes(IResult? actualValue) - { - var actualTypeName = actualValue?.GetType().Name; - if(actualTypeName != "MessageResult") - return AssertionResult.Fail($"Has actual type {actualTypeName}"); - - var kind = actualValue.GetMessageKind(); - if(kind != expectedMessageResultKind) - return AssertionResult.Fail($"MessageResult is of kind {kind}"); - - return AssertionResult.Passed; - } - - protected override string GetFailureMessage(IResult? actualValue) => $"to be MessageResult of kind {expectedMessageResultKind}"; -} \ No newline at end of file diff --git a/TTSBot.Tests/TestUtils/Assertions/MessageResultTextAssertCondition.cs b/TTSBot.Tests/TestUtils/Assertions/MessageResultTextAssertCondition.cs deleted file mode 100644 index facdffe..0000000 --- a/TTSBot.Tests/TestUtils/Assertions/MessageResultTextAssertCondition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using MinimalTelegramBot.Results; -using TUnit.Assertions.AssertConditions; - -namespace TTSBot.Tests.TestUtils.Assertions; - -public class MessageResultTextAssertCondition(string expectedMessageText) : ValueAssertCondition -{ - protected override AssertionResult Passes(IResult? actualValue) - { - var actualTypeName = actualValue?.GetType().Name; - if(actualTypeName != "MessageResult") - return AssertionResult.Fail($"Has actual type {actualTypeName}"); - - var actualMessageText = actualValue.GetMessageText(); - if(actualMessageText != expectedMessageText) - return AssertionResult.Fail($"MessageResult has text: {actualMessageText}"); - - return AssertionResult.Passed; - } - - protected override string GetFailureMessage(IResult? actualValue) => $"to have message set to: {expectedMessageText}"; -} \ No newline at end of file diff --git a/TTSBot.Tests/TestUtils/Assertions/ResultAssertion.cs b/TTSBot.Tests/TestUtils/Assertions/ResultAssertion.cs new file mode 100644 index 0000000..30b1eff --- /dev/null +++ b/TTSBot.Tests/TestUtils/Assertions/ResultAssertion.cs @@ -0,0 +1,23 @@ +using MinimalTelegramBot.Results; +using TUnit.Assertions.Core; + +namespace TTSBot.Tests.TestUtils.Assertions; + +/// +/// Assertion on a bot . The check returns null when it passes, +/// or the failure description when it doesn't. +/// +public class ResultAssertion(AssertionContext context, Func check, string expectation) + : Assertion(context) +{ + protected override Task CheckAsync(EvaluationMetadata metadata) + { + if (metadata.Exception is not null) + return Task.FromResult(AssertionResult.Failed($"threw {metadata.Exception.GetType().Name}")); + + var failure = check(metadata.Value); + return Task.FromResult(failure is null ? AssertionResult.Passed : AssertionResult.Failed(failure)); + } + + protected override string GetExpectation() => expectation; +} diff --git a/TTSBot.Tests/TestUtils/Assertions/SpecificInternalTypeAssertCondition.cs b/TTSBot.Tests/TestUtils/Assertions/SpecificInternalTypeAssertCondition.cs deleted file mode 100644 index fb7bf31..0000000 --- a/TTSBot.Tests/TestUtils/Assertions/SpecificInternalTypeAssertCondition.cs +++ /dev/null @@ -1,17 +0,0 @@ -using MinimalTelegramBot.Results; -using TUnit.Assertions.AssertConditions; - -namespace TTSBot.Tests.TestUtils.Assertions; - -public class SpecificInternalTypeAssertCondition(string expectedTypeName) : ValueAssertCondition -{ - protected override AssertionResult Passes(IResult? actualValue) - { - var actualTypeName = actualValue?.GetType().Name; - return actualTypeName != expectedTypeName ? - AssertionResult.Fail($"Has actual type {actualTypeName}") : - AssertionResult.Passed; - } - - protected override string GetFailureMessage(IResult? actualValue) => $"to be of type {expectedTypeName}"; -} \ No newline at end of file diff --git a/TTSBot.Tests/TestUtils/MockTelegramClient.cs b/TTSBot.Tests/TestUtils/MockTelegramClient.cs index 03a2d64..cf1015e 100644 --- a/TTSBot.Tests/TestUtils/MockTelegramClient.cs +++ b/TTSBot.Tests/TestUtils/MockTelegramClient.cs @@ -2,6 +2,7 @@ using Telegram.Bot.Args; using Telegram.Bot.Exceptions; using Telegram.Bot.Requests.Abstractions; +using Telegram.Bot.Types; namespace TTSBot.Tests.TestUtils; @@ -34,6 +35,11 @@ public class MockTelegramClient : ITelegramBotClient throw new NotImplementedException(); } + public Task DownloadFile(TGFile file, Stream destination, CancellationToken cancellationToken = new CancellationToken()) + { + throw new NotImplementedException(); + } + public bool LocalBotServer { get; } public long BotId { get; } public TimeSpan Timeout { get; set; } diff --git a/TTSBot.Tests/TestUtils/ResultExtensions.cs b/TTSBot.Tests/TestUtils/ResultExtensions.cs index 7bf1da3..acfe3dc 100644 --- a/TTSBot.Tests/TestUtils/ResultExtensions.cs +++ b/TTSBot.Tests/TestUtils/ResultExtensions.cs @@ -33,14 +33,14 @@ public static MessageResult GetMessageKind(this IResult result) return text?.ToString(); } - public static IReplyMarkup? GetKeyboard(this IResult result) + public static ReplyMarkup? GetKeyboard(this IResult result) { var type = result.GetType(); if (type.Name != "MessageResult") throw new InvalidOperationException("The result is not a MessageResult"); var keyboard = type.GetField("_replyMarkup", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(result); - return keyboard as IReplyMarkup; + return keyboard as ReplyMarkup; } } From 3c442d1172db8a8aa958477aed13936e924f1f52 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:04:31 +0100 Subject: [PATCH 3/3] Run tests on Microsoft.Testing.Platform under .NET 10 SDK The .NET 10 SDK no longer runs TUnit through the VSTest target, so opt dotnet test into the MTP runner via global.json. Also replace the obsolete HasCount(n) assertions with Count().IsEqualTo(n). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RYcxAF7nv5jXyZ3ARrbQWA --- TTSBot.Tests/Commands/GetPlaylistCommandHandlerTests.cs | 2 +- TTSBot.Tests/Commands/GetPlaylistCommandProcessorTests.cs | 6 +++--- TTSBot.Tests/Commands/GetPlaylistRewriteDecoratorTests.cs | 2 +- TTSBot.Tests/Commands/M3uParserTests.cs | 2 +- global.json | 5 +++++ 5 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 global.json diff --git a/TTSBot.Tests/Commands/GetPlaylistCommandHandlerTests.cs b/TTSBot.Tests/Commands/GetPlaylistCommandHandlerTests.cs index bce2038..edba2ad 100644 --- a/TTSBot.Tests/Commands/GetPlaylistCommandHandlerTests.cs +++ b/TTSBot.Tests/Commands/GetPlaylistCommandHandlerTests.cs @@ -46,6 +46,6 @@ public async Task Handle_WhenPlaylistProvided_ShouldReturnSuccess() var result = await handler.TryHandleAsync("hash"); await Assert.That(result.IsSuccess).IsTrue(); - await Assert.That(result.Result).HasCount(3); + await Assert.That(result.Result).Count().IsEqualTo(3); } } \ No newline at end of file diff --git a/TTSBot.Tests/Commands/GetPlaylistCommandProcessorTests.cs b/TTSBot.Tests/Commands/GetPlaylistCommandProcessorTests.cs index 9a4e645..628bfb2 100644 --- a/TTSBot.Tests/Commands/GetPlaylistCommandProcessorTests.cs +++ b/TTSBot.Tests/Commands/GetPlaylistCommandProcessorTests.cs @@ -26,13 +26,13 @@ public async Task Process_WhenSuccess_ShouldReturnMessageResultAndCompleteCallba var keyboard = result.GetKeyboard() as InlineKeyboardMarkup; await Assert.That(keyboard).IsNotNull(); // two buttons in total - await Assert.That(keyboard.InlineKeyboard).HasCount(2); + await Assert.That(keyboard.InlineKeyboard).Count().IsEqualTo(2); // first row has one button - await Assert.That(keyboard.InlineKeyboard.First()).HasCount(1); + await Assert.That(keyboard.InlineKeyboard.First()).Count().IsEqualTo(1); // button has correct url await Assert.That(keyboard.InlineKeyboard.First().Single().Url).IsEqualTo("http://example.com/info1"); // second row has one button - await Assert.That(keyboard.InlineKeyboard.Last()).HasCount(1); + await Assert.That(keyboard.InlineKeyboard.Last()).Count().IsEqualTo(1); // button has correct url await Assert.That(keyboard.InlineKeyboard.Last().Single().Url).IsEqualTo("http://example.com/info2"); diff --git a/TTSBot.Tests/Commands/GetPlaylistRewriteDecoratorTests.cs b/TTSBot.Tests/Commands/GetPlaylistRewriteDecoratorTests.cs index f0938de..b8905aa 100644 --- a/TTSBot.Tests/Commands/GetPlaylistRewriteDecoratorTests.cs +++ b/TTSBot.Tests/Commands/GetPlaylistRewriteDecoratorTests.cs @@ -53,7 +53,7 @@ public async Task Handle_WhenRewriteUrlIsSet_ShouldReturnNewList() await Assert.That(testHandler.Hash).IsEqualTo("hash"); await Assert.That(result.IsSuccess).IsTrue(); - await Assert.That(result.Result).HasCount(3); + await Assert.That(result.Result).Count().IsEqualTo(3); var names = result.Result.Select(x => x.Name).ToArray(); await Assert.That(names).IsEquivalentTo(LocalList); await Assert.That(result.Result.Select(r => r.Length)).All().Satisfy(x => x.IsEqualTo(42)); diff --git a/TTSBot.Tests/Commands/M3uParserTests.cs b/TTSBot.Tests/Commands/M3uParserTests.cs index 670411c..add6c10 100644 --- a/TTSBot.Tests/Commands/M3uParserTests.cs +++ b/TTSBot.Tests/Commands/M3uParserTests.cs @@ -19,7 +19,7 @@ public class M3uParserTests public async Task Parse_WhenStringHasValidFormat_ShouldReturnListOfFiles() { var result = M3uParser.Parse(ValidContent); - await Assert.That(result).IsNotNull().And.HasCount(3); + await Assert.That(result).IsNotNull().And.Count().IsEqualTo(3); await Assert.That(result[0].Name).IsEqualTo("name0"); await Assert.That(result[1].Name).IsEqualTo(string.Empty); await Assert.That(result[2].Name).IsEqualTo("name2"); diff --git a/global.json b/global.json new file mode 100644 index 0000000..3140116 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +}