-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api)!: adjust environment-specific settings and test mocks
- Loading branch information
1 parent
ae9e11c
commit 471dc0e
Showing
9 changed files
with
86 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 12 additions & 11 deletions
23
Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerMocks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,44 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Routing; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
|
||
namespace Dotnet.Samples.AspNetCore.WebApi.Tests | ||
{ | ||
public static class PlayerMocks | ||
{ | ||
public static ILogger<T> LoggerMock<T>() | ||
public static Mock<ILogger<T>> LoggerMock<T>() | ||
where T : class | ||
{ | ||
var mock = new Mock<ILogger<T>>(); | ||
|
||
return mock.Object; | ||
return new Mock<ILogger<T>>(); | ||
} | ||
|
||
public static IMemoryCache MemoryCacheMock(object? value) | ||
public static Mock<IMemoryCache> MemoryCacheMock(object? value) | ||
{ | ||
var fromCache = false; | ||
var mock = new Mock<IMemoryCache>(); | ||
mock.Setup(x => x.TryGetValue(It.IsAny<object>(), out value)) | ||
mock.Setup(cache => cache.TryGetValue(It.IsAny<object>(), out value)) | ||
.Returns(() => | ||
{ | ||
bool hasValue = fromCache; | ||
fromCache = true; // Subsequent invocations will return true | ||
return hasValue; | ||
}); | ||
mock.Setup(x => x.CreateEntry(It.IsAny<object>())).Returns(Mock.Of<ICacheEntry>); | ||
mock.Setup(cache => cache.CreateEntry(It.IsAny<object>())) | ||
.Returns(Mock.Of<ICacheEntry>); | ||
mock.Setup(cache => cache.Remove(It.IsAny<object>())); | ||
|
||
return mock.Object; | ||
return mock; | ||
} | ||
|
||
public static IUrlHelper UrlHelperMock() | ||
public static Mock<IUrlHelper> UrlHelperMock() | ||
{ | ||
var mock = new Mock<IUrlHelper>(); | ||
mock.Setup(u => u.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>()); | ||
mock.Setup(url => url.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>()); | ||
|
||
return mock.Object; | ||
return mock; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.