Skip to content

Commit

Permalink
Allow async test setup using IAsyncLifetime (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattherman authored Apr 9, 2024
1 parent fc56902 commit 2772e91
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
20 changes: 11 additions & 9 deletions MbDotNet.Tests/Acceptance/ConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ namespace MbDotNet.Tests.Acceptance
{
[Trait("Category", "Acceptance")]
[Collection("Sequential")]
public class ConfigTests : AcceptanceTestBase
public class ConfigTests : AcceptanceTestBase, IAsyncLifetime
{
/// <summary>
/// It act as test initialize in x unit
/// at https://xunit.net/docs/comparisons
/// </summary>
public ConfigTests()
public async Task InitializeAsync()
{
_client.DeleteAllImpostersAsync().ConfigureAwait(false);
await _client.DeleteAllImpostersAsync();
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}

[Fact]
Expand All @@ -23,8 +24,9 @@ public async Task GetConfig()
var result = await _client.GetConfigAsync();
Assert.NotNull(result);
Assert.NotNull(result.Version);
Assert.True(result.Process.Count > 0);
Assert.True(result.Options.Count > 0);
Assert.True(result.Process.Count > 0);
Assert.True(result.Options.Count > 0);
}
}
}

16 changes: 9 additions & 7 deletions MbDotNet.Tests/Acceptance/DocumentationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ namespace MbDotNet.Tests.Acceptance
/// </summary>
[Trait("Category", "Acceptance")]
[Collection("Sequential")]
public class DocumentationTests : AcceptanceTestBase
public class DocumentationTests : AcceptanceTestBase, IAsyncLifetime
{
/// <summary>
/// It act as test initialize in x unit
/// at https://xunit.net/docs/comparisons
/// </summary>
public DocumentationTests()
public async Task InitializeAsync()
{
await _client.DeleteAllImpostersAsync();
}

public Task DisposeAsync()
{
_client.DeleteAllImpostersAsync().ConfigureAwait(false);
return Task.CompletedTask;
}

/// <summary>
Expand Down Expand Up @@ -518,3 +519,4 @@ public class Customer
public string Email { get; set; }
}
}

25 changes: 15 additions & 10 deletions MbDotNet.Tests/Acceptance/ImposterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ namespace MbDotNet.Tests.Acceptance
{
[Trait("Category", "Acceptance")]
[Collection("Sequential")]
public class ImposterTests : AcceptanceTestBase
public class ImposterTests : AcceptanceTestBase, IAsyncLifetime
{
private readonly HttpClient _httpClient;

/// <summary>
/// It act as test initialize in x unit
/// at https://xunit.net/docs/comparisons
/// </summary>
public ImposterTests()
{
_httpClient = new HttpClient();
}

public async Task InitializeAsync()
{
await _client.DeleteAllImpostersAsync();
}

_client.DeleteAllImpostersAsync().ConfigureAwait(false);
public Task DisposeAsync()
{
return Task.CompletedTask;
}

[Fact]
Expand All @@ -44,8 +48,8 @@ public async Task CanCreateAndGetHttpImposter()
const int port = 6000;
await _client.CreateHttpImposterAsync(port, _ => { });

var retrievedImposter = await _client.GetHttpImposterAsync(port);
Assert.NotNull(retrievedImposter);
var retrievedImposter = await _client.GetHttpImposterAsync(port);
Assert.NotNull(retrievedImposter);
}

[Fact]
Expand Down Expand Up @@ -78,7 +82,7 @@ await _client.CreateHttpImposterAsync(port, imposter =>
.OnMethodEquals(Method.Post)
.ReturnsStatus(HttpStatusCode.Created);

await _client.ReplaceHttpImposterStubsAsync(port, new []{ stub });
await _client.ReplaceHttpImposterStubsAsync(port, new[] { stub });

var imposter = await _client.GetHttpImposterAsync(port);

Expand Down Expand Up @@ -195,7 +199,7 @@ await _client.CreateHttpsImposterAsync(port, imposter =>
.OnMethodEquals(Method.Post)
.ReturnsStatus(HttpStatusCode.Created);

await _client.ReplaceHttpsImposterStubsAsync(port, new []{ stub });
await _client.ReplaceHttpsImposterStubsAsync(port, new[] { stub });

var imposter = await _client.GetHttpsImposterAsync(port);

Expand Down Expand Up @@ -746,3 +750,4 @@ await _client.CreateHttpImposterAsync(port, imposter =>
}
}
}

17 changes: 9 additions & 8 deletions MbDotNet.Tests/Acceptance/ResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ namespace MbDotNet.Tests.Acceptance
{
[Trait("Category", "Acceptance")]
[Collection("Sequential")]
public class ResponseTests : AcceptanceTestBase
public class ResponseTests : AcceptanceTestBase, IAsyncLifetime
{
/// <summary>
/// It act as test initialize in x unit
/// at https://xunit.net/docs/comparisons
/// </summary>
public ResponseTests()
public async Task InitializeAsync()
{
_client.DeleteAllImpostersAsync().ConfigureAwait(false);
await _client.DeleteAllImpostersAsync();
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}

[Fact]
Expand All @@ -32,5 +33,5 @@ public async Task CanGetLogs()
Assert.NotNull(result);
}
}

}

0 comments on commit 2772e91

Please sign in to comment.