Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Commit

Permalink
Updated test class to use correct disposable pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dscpinheiro committed Dec 5, 2019
1 parent ebb4048 commit e5f3ee9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Messages.Tests/Validation/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ namespace Messages.Tests.Validation
public class ValidationTests : IClassFixture<WebApplicationFactory<Startup>>, IDisposable
{
private readonly WebApplicationFactory<Startup> _factory;
private bool _isDisposed;

public ValidationTests(WebApplicationFactory<Startup> factory)
{
_factory = factory;
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "CI");
}

public void Dispose() => Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null);
~ValidationTests()
{
Dispose(false);
}

[Theory, ClassData(typeof(InvalidWriteRequestData))]
public async Task Validation_InvalidRequest_ReturnsBadRequest(string message)
Expand All @@ -43,5 +47,26 @@ public async Task Validation_ValidRequest_ReturnsCreated(string message)
Assert.True(response.IsSuccessStatusCode);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool isDisposing)
{
if (_isDisposed)
{
return;
}

if (isDisposing)
{
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null);
}

_isDisposed = true;
}
}
}

0 comments on commit e5f3ee9

Please sign in to comment.