65 lines
2.7 KiB
C#
65 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
|
|
namespace Crm.Core.Test
|
|
{
|
|
[TestClass]
|
|
public class UnitTest1
|
|
{
|
|
private readonly IServiceProvider _service;
|
|
|
|
public UnitTest1()
|
|
{
|
|
const string OUTPUT_TEMPLATE = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} <{ThreadId}> [{Level:u3}] {Message:lj}{NewLine}{Exception}";
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Debug()
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
|
|
.Enrich.WithThreadId()
|
|
.Enrich.FromLogContext()
|
|
.WriteTo.Console(outputTemplate: OUTPUT_TEMPLATE)
|
|
.WriteTo.File("logs/log.log"
|
|
, rollingInterval: RollingInterval.Day
|
|
, outputTemplate: OUTPUT_TEMPLATE)
|
|
.CreateLogger();
|
|
var config = new ConfigurationBuilder()
|
|
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
|
|
.Build();
|
|
|
|
var builder = WebApplication.CreateBuilder();
|
|
IServiceCollection services = new ServiceCollection();
|
|
builder.Services.AddLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.AddSerilog();
|
|
});
|
|
builder.Services.AddSingleton(config);
|
|
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
builder.Services.AddRedis(builder.Configuration);
|
|
builder.Services.AddDGHttpClient();
|
|
builder.Services.AddSingleton<NotificationHub>();
|
|
builder.Services
|
|
.AddAutoIoc(typeof(IScopedDependency), LifeCycle.Scoped)
|
|
.AddAutoIoc(typeof(ISingletonDependency), LifeCycle.Singleton)
|
|
.AddAutoIoc(typeof(ITransientDependency), LifeCycle.Transient)
|
|
.AddMapper();
|
|
builder.Services.AddDGEntityFrameworkOracle<CrmDbContext>("appid");
|
|
_service = builder.Services.BuildServiceProvider();
|
|
|
|
var app = builder.Build();
|
|
app.UseDGEntityFrameworkOracle("crm_tg_dng8");
|
|
|
|
//app.Run();
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task TestMethod1()
|
|
{
|
|
using var sco = _service.CreateScope();
|
|
var domain = sco.ServiceProvider.GetRequiredService<INotificationDomain>();
|
|
await domain.WeworkSend("wwd4cd11d60db47118", "221017-142226-84", 4028, "test");
|
|
}
|
|
}
|
|
} |