Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwoctopusdeploy committed Dec 5, 2023
1 parent c25a315 commit 5d8c68d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand,
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ScriptExecutionCancelled, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.CancelScript).Build();

actualException.Should().NotBeNull();
actualException!.ShouldMatchExceptionContract(expectedException);

var allLogs = logs.JoinLogs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public async Task WhenRpcRetriesTimeOut_DuringGetCapabilities_TheRpcCallIsCancel
Func<Task> action = async () => await executeScriptTask;

await action.Should().ThrowAsync<HalibutClientException>();

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.GetCapabilities).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

duration.Stop();

capabilitiesMethodUsages.For(nameof(IAsyncClientCapabilitiesServiceV2.GetCapabilitiesAsync)).Started.Should().BeGreaterOrEqualTo(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using FluentAssertions.Specialized;
using Halibut;

Expand Down Expand Up @@ -44,9 +46,19 @@ public static void ShouldMatchExceptionContract(
params object[] becauseArgs)
{
exception.Should().NotBeNull(because, becauseArgs);
exception.Should().Match(x => expected.ExceptionTypes.Contains(x.GetType()), because, becauseArgs);
exception.ShouldBeOfType(expected.ExceptionTypes, because, becauseArgs);
exception.Message.Should().ContainAny(expected.ExceptionMessageShouldContainAny, because, becauseArgs);
}

public static void ShouldBeOfType(this Exception subject, Type[] values, string because = "", params object[] becauseArgs)
{
subject.Should().NotBeNull(because, becauseArgs);

Execute.Assertion
.ForCondition(values.Any(v => v == subject.GetType()))
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context} to be {0}{reason}, but found {1}.", values, subject.GetType());
}
}

public class ExceptionContractAssertionBuilder
Expand Down

0 comments on commit 5d8c68d

Please sign in to comment.