I have the settings below.
Startup Class: Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AzureStorageConfig>(Configuration.GetSection("AzureStorageConfig"));
services.AddTransient<IAzureService, AzureService>();
}
}
Class: AzureStorageConfig
public class AzureStorageConfig
{
public string AzureURL { get; set; }
public string StorageConnectionString { get; set; }
public string AccountName { get; set; }
}
Interface Class: IAzureService
public interface IAzureService
{
Task<string> UploadFileAsync(AzureStorageConfig _storageConfig, string filename);
Task<string> DeleteFile(AzureStorageConfig _storageConfig, string filename);
}
Azure Class: AzureService that uses the interface above
public class AzureService : IAzureService, IDisposable
{
public Task<string> UploadFileAsync(AzureStorageConfig _storageConfig, string filename)
{
}
Task<string> DeleteFile(AzureStorageConfig _storageConfig, string filename)
{
}
}
Image Controller: ImageController.cs
[Produces("application/json")]
[Route("api/Images")]
public class ImagesController : Controller
{
#region Private properties
private readonly ApiDbContext _context;
private readonly IMapper _mapper;
private AzureStorageConfig _storageConfig;
public readonly IAzureService _azureService;
#endregion
#region Constructor
public ImagesController(ApiDbContext context, IMapper mapper, IOptions<AzureStorageConfig> storageConfig, IAzureService azureService)
{
_context = context;
_mapper = mapper;
_storageConfig = storageConfig.Value;
_azureService = azureService;
}
public async Task<IActionResult> PostImage(Guid Id, [FromForm] ICollection<IFormFile> files)
{
}
}
The main problem in the underlying class (TEST Library) with xunit
Class: ImageControllerTest
[Collection("TestDb")]
public class ImageControllerTest : IClassFixture<InitializeAutoMap>
{
private ImagesController _controller;
private DatabaseFixture _fixture;
private InitializeAutoMap _initialize;
public ImageControllerTest(DatabaseFixture fixture, InitializeAutoMap initialize)
{
this._fixture = fixture;
this._initialize = initialize;
_controller = new ImagesController(_context,
_initialize.InstanceMapper,
,
);
}
}
How to do this can be injected into the Xunit ImageControllerTest constructor.
- storageConfig class object and
- The IAzureService object
in ImageController from the Xunit ImageControllerTest method.?
Share me if you have an idea or solution.