Skip to content

Commit 5cdc9e5

Browse files
committed
refactor: simplify PlayerServiceTests and make environment configurable
Remove unnecessary IDisposable pattern from PlayerServiceTests since there's no cleanup needed after removing environment variable dependency. Add optional environmentName parameter to PlayerMocks.InitServiceMocks() to enable testing environment-specific behavior. Changes: - Remove IDisposable implementation from PlayerServiceTests - Add environmentName parameter to InitServiceMocks (defaults to Development)
1 parent a8a6dd0 commit 5cdc9e5

2 files changed

Lines changed: 3 additions & 19 deletions

File tree

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerServiceTests.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
namespace Dotnet.Samples.AspNetCore.WebApi.Tests.Unit;
99

10-
public class PlayerServiceTests : IDisposable
10+
public class PlayerServiceTests
1111
{
12-
private bool _disposed;
13-
1412
/* -------------------------------------------------------------------------
1513
* Create
1614
* ---------------------------------------------------------------------- */
@@ -331,18 +329,4 @@ private static async Task<long> ExecutionTimeAsync(Func<Task> awaitable)
331329

332330
return stopwatch.ElapsedMilliseconds;
333331
}
334-
335-
protected virtual void Dispose(bool disposing)
336-
{
337-
if (!_disposed)
338-
{
339-
_disposed = true;
340-
}
341-
}
342-
343-
public void Dispose()
344-
{
345-
Dispose(true);
346-
GC.SuppressFinalize(this);
347-
}
348332
}

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerMocks.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public static (
4949
Mock<IMemoryCache> memoryCache,
5050
Mock<IMapper> mapper,
5151
Mock<IHostEnvironment> environment
52-
) InitServiceMocks(object? cacheValue = null)
52+
) InitServiceMocks(object? cacheValue = null, string environmentName = "Development")
5353
{
5454
var repository = new Mock<IPlayerRepository>();
5555
var logger = new Mock<ILogger<PlayerService>>();
5656
var memoryCache = SetupMemoryCacheMock(cacheValue ?? It.IsAny<object>());
5757
var mapper = new Mock<IMapper>();
5858
var environment = new Mock<IHostEnvironment>();
59-
environment.Setup(env => env.EnvironmentName).Returns("Development");
59+
environment.Setup(env => env.EnvironmentName).Returns(environmentName);
6060
return (repository, logger, memoryCache, mapper, environment);
6161
}
6262

0 commit comments

Comments
 (0)