Skip to content

Commit

Permalink
CODE RUB: Resolve Reiew Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
glhays committed Mar 3, 2024
1 parent f2c1982 commit bbee625
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 61 deletions.
15 changes: 0 additions & 15 deletions RESTFulSense.Tests.Acceptance/DeleteMe.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task ShouldDeleteContentReturnsExpectedContentDeserializeAsync()
.WithBodyAsJson(randomContent));

// when
var result =
TEntity result =
await this.restfulApiClient.DeleteContentAsync<TEntity>(
relativeUrl,
deserializationFunction: DeserializationContentFunction);
Expand All @@ -98,7 +98,7 @@ public async Task ShouldDeleteContentReturnsExpectedContentCancellationTokenAsyn
.WithBodyAsJson(randomContent));

// when
var result =
TEntity result =
await this.restfulApiClient.DeleteContentAsync<TEntity>(
relativeUrl,
cancellationToken: cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -53,7 +54,7 @@ private async Task ShouldCancelGetContentDeserializationIfCancellationInvokedAsy
.WithBodyAsJson(someContent));

// when
var actualCanceledTask =
TaskCanceledException actualCanceledTask =
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
await this.restfulApiClient.GetContentAsync<TEntity>(
relativeUrl,
Expand All @@ -77,7 +78,7 @@ private async Task ShouldReturnStringOnGetContentStringAsync()
.WithBody(stringContent));

// when
var actualContentResponse =
string actualContentResponse =
await this.restfulApiClient.GetContentStringAsync(relativeUrl);

// then
Expand All @@ -97,10 +98,10 @@ private async Task ShouldReturnStreamOnGetContentStreamAsync()
.WithBody(stringContent));

// when
var expectedContentStream =
Stream expectedContentStream =
await this.restfulApiClient.GetContentStreamAsync(relativeUrl);

var actualReadStream = await ReadStreamToEndAsync(expectedContentStream);
string actualReadStream = await ReadStreamToEndAsync(expectedContentStream);

// then
actualReadStream.Should().BeEquivalentTo(stringContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ----------------------------------------------------------------------------------

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -62,7 +63,7 @@ private async Task ShouldCancelPostContentWithNoResponseAndDeserializationWhenCa
// when
var taskCanceledToken = new CancellationToken(canceled: true);

var actualPostContentCanceledTask =
TaskCanceledException actualPostContentCanceledTask =
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
await this.restfulApiClient.PostContentWithNoResponseAsync<TEntity>(
relativeUrl,
Expand Down Expand Up @@ -96,7 +97,7 @@ public async Task ShouldPostContentReturnsContentWithCustomSerializationAndDeser
.WithBodyAsJson(expectedTEntity));

// when
var result =
TEntity result =
await this.restfulApiClient.PostContentAsync<TEntity>(
relativeUrl,
content: expectedTEntity,
Expand Down Expand Up @@ -130,7 +131,7 @@ private async Task ShouldCancelPostContentWhenCancellationIsInvokedAsync()
// when
var taskCanceledToken = new CancellationToken(canceled: true);

var actualCanceledTaskResult =
TaskCanceledException actualCanceledTaskResult =
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
await this.restfulApiClient.PostContentAsync<TEntity>(
relativeUrl,
Expand Down Expand Up @@ -164,7 +165,7 @@ private async Task ShouldPostContentWithStreamResponseAsync()
.WithBody(randomContent));

// when
var result =
Stream result =
await this.restfulApiClient.PostContentWithStreamResponseAsync(
relativeUrl,
content: randomContent,
Expand Down Expand Up @@ -198,7 +199,7 @@ private async Task ShouldPostContentWithTContentReturnsTResultAsync()
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PostContentAsync<TEntity, TEntity>(
relativeUrl,
content: randomTEntity,
Expand Down Expand Up @@ -233,7 +234,7 @@ private async Task ShouldPostContentWithTContentReturnsTResultCancellationTokenA
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PostContentAsync<TEntity, TEntity>(
relativeUrl,
content: randomTEntity,
Expand Down Expand Up @@ -266,7 +267,7 @@ private async Task ShouldPostFormWithTContentReturnsTResultAsync()
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PostFormAsync(
relativeUrl,
content: randomTEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private async Task ShouldPutContentWithTContentReturnsTResultAsync()
JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PutContentAsync<TEntity, TEntity>(
relativeUrl,
content: randomTEntity,
Expand Down Expand Up @@ -105,7 +105,7 @@ private async Task ShouldPutContentWithTContentReturnsTResultWithCancellationTok
JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PutContentAsync<TEntity, TEntity>(
relativeUrl,
content: randomTEntity,
Expand Down Expand Up @@ -137,7 +137,7 @@ private async Task ShouldPutContentReturnsContentWithDeserializationAsync()
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PutContentAsync<TEntity>(
relativeUrl,
deserializationFunction: DeserializationContentFunction);
Expand Down Expand Up @@ -165,7 +165,7 @@ private async Task ShouldPutContentReturnsContentWithCancellationTokenDeserializ
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.restfulApiClient.PutContentAsync<TEntity>(
relativeUrl,
cancellationToken: cancellationToken,
Expand Down
25 changes: 16 additions & 9 deletions RESTFulSense.Tests.Acceptance/Tests/RestfulApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using RESTFulSense.Clients;
using RESTFulSense.Tests.Acceptance.Models;
using Tynamix.ObjectFiller;
using WireMock.Logging;
using WireMock.Server;

namespace RESTFulSense.Tests.Acceptance.Tests
Expand All @@ -18,32 +20,34 @@ public partial class RestfulApiClientTests : IDisposable
{
private readonly WireMockServer wiremockServer;
private const string relativeUrl = "/tests";
private readonly IRESTFulApiClient restfulApiClient;
private readonly RESTFulApiClient restfulApiClient;

public RestfulApiClientTests()
{
this.wiremockServer = WireMockServer.Start();
this.restfulApiClient = new RESTFulApiClient();

this.restfulApiClient =
new RESTFulApiClient
{ BaseAddress = new Uri(this.wiremockServer.Urls[0]) };
this.restfulApiClient.BaseAddress = new Uri(
this.wiremockServer.Urls[0]);
}

private async Task<string> ReadStreamToEndAsync(Stream result)
{
var reader = new StreamReader(result, leaveOpen: false);

return await reader.ReadToEndAsync();
}

private bool GetDeleteContentVerification()
{
var requestLogs = this.wiremockServer.LogEntries;
IEnumerable<ILogEntry> requestLogs = this.wiremockServer.LogEntries;

var deleteContentResult =
ILogEntry deleteContentResult =
requestLogs.FirstOrDefault(
request => request.RequestMessage.Path == relativeUrl);
request => request.RequestMessage.Path == relativeUrl &&
request.RequestMessage.Method == "DELETE");

return deleteContentResult != null;
return deleteContentResult is not null;
}

private static ValueTask<string> SerializationContentFunction<TEntity>(TEntity entityContent)
Expand All @@ -55,7 +59,10 @@ private static ValueTask<string> SerializationContentFunction<TEntity>(TEntity e

private static string CreateRandomContent()
{
var randomContent = new Lipsum(LipsumFlavor.LoremIpsum, minWords: 3, maxWords: 10);
var randomContent = new Lipsum(
LipsumFlavor.LoremIpsum,
minWords: 3,
maxWords: 10);

return randomContent.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task ShouldDeleteContentReturnsExpectedContentDeserializeAsync()
.WithBodyAsJson(randomContent));

// when
var result =
TEntity result =
await this.factoryClient.DeleteContentAsync<TEntity>(
relativeUrl,
deserializationFunction: DeserializationContentFunction);
Expand All @@ -98,7 +98,7 @@ public async Task ShouldDeleteContentReturnsExpectedContentCancellationTokenAsyn
.WithBodyAsJson(randomContent));

// when
var result =
TEntity result =
await this.factoryClient.DeleteContentAsync<TEntity>(
relativeUrl,
cancellationToken: cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -53,7 +54,7 @@ private async Task ShouldCancelGetContentDeserializationIfCancellationInvokedAsy
.WithBodyAsJson(someContent));

// when
var actualCanceledTask =
TaskCanceledException actualCanceledTask =
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
await this.factoryClient.GetContentAsync<TEntity>(
relativeUrl,
Expand Down Expand Up @@ -97,7 +98,7 @@ private async Task ShouldReturnStreamOnGetContentStreamAsync()
.WithBody(stringContent));

// when
var expectedContentStream =
Stream expectedContentStream =
await this.factoryClient.GetContentStreamAsync(relativeUrl);

var actualReadStream = await ReadStreamToEndAsync(expectedContentStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ----------------------------------------------------------------------------------

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -33,7 +34,7 @@ private async Task ShouldCancelPostContentWithNoResponseAndDeserializationWhenCa
// when
var taskCanceledToken = new CancellationToken(canceled: true);

var actualPostContentCanceledTask =
TaskCanceledException actualPostContentCanceledTask =
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
await this.factoryClient.PostContentWithNoResponseAsync<TEntity>(
relativeUrl,
Expand Down Expand Up @@ -95,7 +96,7 @@ public async Task ShouldPostContentReturnsContentWithCustomSerializationAndDeser
.WithBodyAsJson(expectedTEntity));

// when
var result =
TEntity result =
await this.factoryClient.PostContentAsync<TEntity>(
relativeUrl,
content: expectedTEntity,
Expand Down Expand Up @@ -131,7 +132,7 @@ private async Task ShouldCancelPostContentWhenCancellationIsInvokedAsync()
// when
var taskCanceledToken = new CancellationToken(canceled: true);

var actualCanceledTaskResult =
TaskCanceledException actualCanceledTaskResult =
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
await this.factoryClient.PostContentAsync<TEntity>(
relativeUrl,
Expand Down Expand Up @@ -165,7 +166,7 @@ private async Task ShouldPostContentWithStreamResponseAsync()
.WithBody(randomContent));

// when
var result =
Stream result =
await this.factoryClient.PostContentWithStreamResponseAsync(
relativeUrl,
content: randomContent,
Expand Down Expand Up @@ -199,7 +200,7 @@ private async Task ShouldPostContentWithTContentReturnsTResultAsync()
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.factoryClient.PostContentAsync<TEntity, TEntity>(
relativeUrl,
content: randomTEntity,
Expand Down Expand Up @@ -231,7 +232,7 @@ private async Task ShouldPostFormWithTContentReturnsTResultAsync()
.WithBody(JsonConvert.SerializeObject(randomTEntity)));

// when
var result =
TEntity result =
await this.factoryClient.PostFormAsync(
relativeUrl,
content: randomTEntity,
Expand Down
Loading

0 comments on commit bbee625

Please sign in to comment.