Browse Source

Unit tests working; added logger adapter.

main
Steve Smith 9 years ago
parent
commit
dfe0106ce3
  1. 7
      src/ApplicationCore/Interfaces/IAppLogger.cs
  2. 11
      src/ApplicationCore/Interfaces/IImageService.cs
  3. 18
      src/Infrastructure/Logging/LoggerAdapter.cs
  4. 4
      src/Web/Controllers/CatalogController.cs
  5. 2
      src/Web/Startup.cs
  6. 2
      tests/UnitTests/Web/Controllers/CatalogControllerGetImage.cs

7
src/ApplicationCore/Interfaces/IAppLogger.cs

@ -0,0 +1,7 @@
namespace ApplicationCore.Interfaces
{
public interface IAppLogger<T>
{
void LogWarning(string message, params object[] args);
}
}

11
src/ApplicationCore/Interfaces/IImageService.cs

@ -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

@ -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);
}
}
}

4
src/Web/Controllers/CatalogController.cs

@ -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;

2
src/Web/Startup.cs

@ -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;

2
tests/UnitTests/Web/Controllers/CatalogControllerGetImage.cs

@ -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 };

Loading…
Cancel
Save