Unit tests working; added logger adapter.
This commit is contained in:
7
src/ApplicationCore/Interfaces/IAppLogger.cs
Normal file
7
src/ApplicationCore/Interfaces/IAppLogger.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ApplicationCore.Interfaces
|
||||
{
|
||||
public interface IAppLogger<T>
|
||||
{
|
||||
void LogWarning(string message, params object[] args);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,7 @@
|
||||
using ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ApplicationCore.Interfaces
|
||||
namespace ApplicationCore.Interfaces
|
||||
{
|
||||
|
||||
public interface IImageService
|
||||
{
|
||||
byte[] GetImageBytesById(int id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
18
src/Infrastructure/Logging/LoggerAdapter.cs
Normal file
18
src/Infrastructure/Logging/LoggerAdapter.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using ApplicationCore.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Infrastructure.Logging
|
||||
{
|
||||
public class LoggerAdapter<T> : IAppLogger<T>
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
public LoggerAdapter(ILoggerFactory loggerFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<T>();
|
||||
}
|
||||
public void LogWarning(string message, params object[] args)
|
||||
{
|
||||
_logger.LogWarning(message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,12 @@ namespace Microsoft.eShopWeb.Controllers
|
||||
private readonly IHostingEnvironment _env;
|
||||
private readonly ICatalogService _catalogService;
|
||||
private readonly IImageService _imageService;
|
||||
private readonly ILogger<CatalogController> _logger;
|
||||
private readonly IAppLogger<CatalogController> _logger;
|
||||
|
||||
public CatalogController(IHostingEnvironment env,
|
||||
ICatalogService catalogService,
|
||||
IImageService imageService,
|
||||
ILogger<CatalogController> logger)
|
||||
IAppLogger<CatalogController> logger)
|
||||
{
|
||||
_env = env;
|
||||
_catalogService = catalogService;
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Text;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using ApplicationCore.Interfaces;
|
||||
using Infrastructure.FileSystem;
|
||||
using Infrastructure.Logging;
|
||||
|
||||
namespace Microsoft.eShopWeb
|
||||
{
|
||||
@@ -68,6 +69,7 @@ namespace Microsoft.eShopWeb
|
||||
services.AddScoped<CatalogService>();
|
||||
services.Configure<CatalogSettings>(Configuration);
|
||||
services.AddSingleton<IImageService, LocalFileImageService>();
|
||||
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
|
||||
services.AddMvc();
|
||||
|
||||
_services = services;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace UnitTests
|
||||
public class CatalogControllerGetImage
|
||||
{
|
||||
private Mock<IImageService> _mockImageService = new Mock<IImageService>();
|
||||
private Mock<ILogger<CatalogController>> _mockLogger = new Mock<ILogger<CatalogController>>();
|
||||
private Mock<IAppLogger<CatalogController>> _mockLogger = new Mock<IAppLogger<CatalogController>>();
|
||||
private CatalogController _controller;
|
||||
private int _testImageId = 123;
|
||||
private byte[] _testBytes = { 0x01, 0x02, 0x03 };
|
||||
|
||||
Reference in New Issue
Block a user