Remotely/Tests/IoCActivator.cs
2020-04-11 09:52:46 -07:00

67 lines
1.8 KiB
C#

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Remotely.Server.Data;
using Remotely.Server.Services;
using System;
using Microsoft.EntityFrameworkCore;
using Remotely.Shared.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Remotely.Tests
{
[TestClass]
public class IoCActivator
{
public static IServiceProvider ServiceProvider { get; set; }
private static IWebHostBuilder builder;
public static void Activate()
{
if (builder is null)
{
builder = WebHost.CreateDefaultBuilder()
.UseStartup<Startup>()
.CaptureStartupErrors(true);
builder.Build();
}
}
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
Activate();
}
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseInMemoryDatabase("Remotely"));
services.AddIdentity<RemotelyUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
services.AddTransient<DataService>();
services.AddTransient<ApplicationConfig>();
services.AddTransient<IEmailSenderEx, EmailSenderEx>();
IoCActivator.ServiceProvider = services.BuildServiceProvider();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
}
}
}