aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/TestApplication.cs
blob: a624da6b138343f4dd710db5aef88474b097cccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using Timeline.Entities;

namespace Timeline.Tests.Helpers
{
    public class TestApplication : IDisposable
    {
        public TestDatabase Database { get; } = new TestDatabase();
        public WebApplicationFactory<Startup> Factory { get; }

        public TestApplication(WebApplicationFactory<Startup> factory)
        {
            Factory = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureServices(services =>
                {
                    services.AddEntityFrameworkSqlite();
                    services.AddDbContext<DatabaseContext>(options =>
                    {
                        options.UseSqlite(Database.Connection);
                    });
                });
            });
        }

        public void Dispose()
        {
            Database.Dispose();
        }
    }
}