|
@@ -13,18 +13,31 @@ using Microsoft.AspNetCore.Mvc.Controllers;
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
using MTWorkHR.API.Swagger;
|
|
|
using Azure.Storage.Blobs;
|
|
|
+using Moq;
|
|
|
+
|
|
|
+
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
+
|
|
|
+if (OperatingSystem.IsLinux())
|
|
|
+{
|
|
|
+ builder.Configuration.AddJsonFile("appsettings.Linux.json", optional: true, reloadOnChange: true);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var config = new AppSettingsConfiguration();
|
|
|
// Add services to the container.
|
|
|
builder.Services.AddDbContext<HRDataContext>(options =>
|
|
|
{
|
|
|
options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
|
|
|
- // options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
|
|
|
+ // options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
|
|
|
});
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
builder.Configuration.Bind(config);
|
|
|
builder.Services.AddApplicationServices(config);
|
|
|
builder.Services.AddInfrastructureIdentityServices(config);
|
|
@@ -32,7 +45,28 @@ builder.Services.AddInfrastructureIdentityServices(config);
|
|
|
//builder.Services.AddIdentityServices(config);
|
|
|
builder.Services.AddHostedService<DbMigrationService>();
|
|
|
|
|
|
-builder.Services.AddSingleton(x => new BlobServiceClient(config.ConnectionStrings.BlobConnectionString));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if (builder.Environment.IsDevelopment())
|
|
|
+{
|
|
|
+ var mockBlobServiceClient = new Mock<BlobServiceClient>();
|
|
|
+
|
|
|
+ // Mock BlobContainerClient since this is what BlobServiceClient interacts with.
|
|
|
+ var mockBlobContainerClient = new Mock<BlobContainerClient>();
|
|
|
+
|
|
|
+ // Set up the mock to return a mock BlobContainerClient when requested.
|
|
|
+ mockBlobServiceClient
|
|
|
+ .Setup(x => x.GetBlobContainerClient(It.IsAny<string>()))
|
|
|
+ .Returns(mockBlobContainerClient.Object);
|
|
|
+
|
|
|
+ builder.Services.AddSingleton(mockBlobServiceClient.Object);
|
|
|
+}
|
|
|
+else
|
|
|
+{
|
|
|
+ // Use the actual connection string for production or other environments.
|
|
|
+ builder.Services.AddSingleton(x => new BlobServiceClient(config.ConnectionStrings.BlobConnectionString));
|
|
|
+}
|
|
|
|
|
|
//builder.Services.AddControllers();
|
|
|
builder.Services.AddControllers(options =>
|
|
@@ -112,7 +146,7 @@ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MTWorkHR.AP
|
|
|
app.UseCors(x => x
|
|
|
.AllowAnyMethod()
|
|
|
.AllowAnyHeader()
|
|
|
- .SetIsOriginAllowed(origin =>
|
|
|
+ .SetIsOriginAllowed(origin =>
|
|
|
true) // allow any origin
|
|
|
.AllowCredentials()); // allow credentials
|
|
|
app.UseHttpsRedirection();
|