Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: async result extensions #470

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Vonage.Common.Test/Extensions/FluentAssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public static class FluentAssertionExtensions
public static MaybeAssertionExtensions<T> Should<T>(this Maybe<T> instance) => new(instance);

public static ResultAssertionExtensions<T> Should<T>(this Result<T> instance) => new(instance);

public static ResultAsyncAssertionExtensions<T> Should<T>(this Task<Result<T>> instance) => new(instance);
}
}
37 changes: 37 additions & 0 deletions Vonage.Common.Test/Extensions/ResultAssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,41 @@ private string GetResultFailure() =>

protected override string Identifier => "result";
}

public class
ResultAsyncAssertionExtensions<T> : ReferenceTypeAssertions<Task<Result<T>>, ResultAsyncAssertionExtensions<T>>
{
public ResultAsyncAssertionExtensions(Task<Result<T>> subject) : base(subject)
{
}

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeFailureAsync(Action<IResultFailure> action) =>
(await this.InitializeAssertion()).BeFailure(action);

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeFailureAsync() =>
(await this.InitializeAssertion()).BeFailure();

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeFailureAsync(IResultFailure expected) =>
(await this.InitializeAssertion()).BeFailure(expected);

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeParsingFailureAsync(
params string[] failureMessages) =>
(await this.InitializeAssertion()).BeParsingFailure(failureMessages);

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeResultFailureAsync(string expectedMessage) =>
(await this.InitializeAssertion()).BeResultFailure(expectedMessage);

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeSuccessAsync() =>
(await this.InitializeAssertion()).BeSuccess();

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeSuccessAsync(Action<T> action) =>
(await this.InitializeAssertion()).BeSuccess(action);

public async Task<AndConstraint<ResultAssertionExtensions<T>>> BeSuccessAsync(T expected) =>
(await this.InitializeAssertion()).BeSuccess(expected);

private async Task<ResultAssertionExtensions<T>> InitializeAssertion() => new(await this.Subject);

protected override string Identifier => "resultAsync";
}
}
8 changes: 4 additions & 4 deletions Vonage.Test.Unit/VerifyV2/Cancel/E2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public async Task CancelVerification()
.WithHeader("Authorization", "Bearer *")
.UsingDelete())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
var result =
await this.Helper.VonageClient.VerifyV2Client.CancelAsync(
CancelRequest.Parse(Guid.Parse("68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb")));
result.Should().BeSuccess();
await this.Helper.VonageClient.VerifyV2Client.CancelAsync(
CancelRequest.Parse(Guid.Parse("68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb")))
.Should()
.BeSuccessAsync();
}
}
}
Loading