diff --git a/SurrealDb.Net.LiveQuery.Tests/KillTests.cs b/SurrealDb.Net.LiveQuery.Tests/KillTests.cs index 21aafb55..b8e7faac 100644 --- a/SurrealDb.Net.LiveQuery.Tests/KillTests.cs +++ b/SurrealDb.Net.LiveQuery.Tests/KillTests.cs @@ -1,4 +1,5 @@ -using SurrealDb.Net.Exceptions; +using System.Linq.Expressions; +using SurrealDb.Net.Exceptions; using SurrealDb.Net.Models.Response; namespace SurrealDb.Net.LiveQuery.Tests; @@ -72,16 +73,16 @@ public async Task ShouldFailToKillInexistantLiveQueryOnWsProtocol(string connect await client.Kill(liveQueryUuid); }; - string errorMessage = version switch - { - { Major: 1 } => - "There was a problem with the database: Can not execute KILL statement using id 'KILL statement uuid did not exist'", - { Major: 2, Minor: 0 } => - "There was a problem with the database: Can not execute KILL statement using id '$id'", - _ => - $"There was a problem with the database: Can not execute KILL statement using id 'u'{liveQueryUuid}''", - }; - - await func.Should().ThrowAsync().WithMessage(errorMessage); + Expression> validErrorMessage = ex => + ex.Message.Contains( + "There was a problem with the database: Can not execute KILL statement using id" + ) + && ( + ex.Message.Contains(liveQueryUuid.ToString()) // >= 2.1 + || ex.Message.Contains("KILL statement uuid did not exist") // 1.x + || ex.Message.Contains("Can not execute KILL statement using id '$id'") // 2.0.x + ); + + await func.Should().ThrowAsync().Where(validErrorMessage); } } diff --git a/SurrealDb.Net.LiveQuery.Tests/LiveQueryTests.Kill.cs b/SurrealDb.Net.LiveQuery.Tests/LiveQueryTests.Kill.cs index 33d890f9..ee7ed29e 100644 --- a/SurrealDb.Net.LiveQuery.Tests/LiveQueryTests.Kill.cs +++ b/SurrealDb.Net.LiveQuery.Tests/LiveQueryTests.Kill.cs @@ -1,4 +1,5 @@ -using SurrealDb.Net.Exceptions; +using System.Linq.Expressions; +using SurrealDb.Net.Exceptions; using SurrealDb.Net.Models.LiveQuery; using SurrealDb.Net.Models.Response; @@ -10,8 +11,6 @@ public class KillLiveQueryTests [Arguments("Endpoint=ws://127.0.0.1:8000/rpc;User=root;Pass=root")] public async Task ShouldAutomaticallyKillLiveQueryWhenDisposed(string connectionString) { - var version = await SurrealDbClientGenerator.GetSurrealTestVersion(connectionString); - await using var surrealDbClientGenerator = new SurrealDbClientGenerator(); var dbInfo = surrealDbClientGenerator.GenerateDatabaseInfo(); @@ -44,28 +43,26 @@ public async Task ShouldAutomaticallyKillLiveQueryWhenDisposed(string connection liveQueryUuid.Should().NotBeEmpty(); - string errorMessage = version switch - { - { Major: 1 } => - "There was a problem with the database: Can not execute KILL statement using id 'KILL statement uuid did not exist'", - { Major: 2, Minor: 0 } => - "There was a problem with the database: Can not execute KILL statement using id '$id'", - _ => - $"There was a problem with the database: Can not execute KILL statement using id 'u'{liveQueryUuid}''", - }; + Expression> validErrorMessage = ex => + ex.Message.Contains( + "There was a problem with the database: Can not execute KILL statement using id" + ) + && ( + ex.Message.Contains(liveQueryUuid.ToString()) // >= 2.1 + || ex.Message.Contains("KILL statement uuid did not exist") // 1.x + || ex.Message.Contains("Can not execute KILL statement using id '$id'") // 2.0.x + ); await liveQueryAlreadyKilledFunc .Should() .ThrowAsync() - .WithMessage(errorMessage); + .Where(validErrorMessage); } [Test] [Arguments("Endpoint=ws://127.0.0.1:8000/rpc;User=root;Pass=root")] public async Task ShouldManuallyKillLiveQuery(string connectionString) { - var version = await SurrealDbClientGenerator.GetSurrealTestVersion(connectionString); - await using var surrealDbClientGenerator = new SurrealDbClientGenerator(); var dbInfo = surrealDbClientGenerator.GenerateDatabaseInfo(); @@ -102,19 +99,19 @@ public async Task ShouldManuallyKillLiveQuery(string connectionString) await manuallyKillLiveQueryFunc.Should().NotThrowAsync(); - string errorMessage = version switch - { - { Major: 1 } => - "There was a problem with the database: Can not execute KILL statement using id 'KILL statement uuid did not exist'", - { Major: 2, Minor: 0 } => - "There was a problem with the database: Can not execute KILL statement using id '$id'", - _ => - $"There was a problem with the database: Can not execute KILL statement using id 'u'{liveQueryUuid}''", - }; + Expression> validErrorMessage = ex => + ex.Message.Contains( + "There was a problem with the database: Can not execute KILL statement using id" + ) + && ( + ex.Message.Contains(liveQueryUuid.ToString()) // >= 2.1 + || ex.Message.Contains("KILL statement uuid did not exist") // 1.x + || ex.Message.Contains("Can not execute KILL statement using id '$id'") // 2.0.x + ); await liveQueryAlreadyKilledFunc .Should() .ThrowAsync() - .WithMessage(errorMessage); + .Where(validErrorMessage); } }