diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-04 21:35:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-04 21:35:04 +0800 |
commit | 52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24 (patch) | |
tree | d1c9c7b51353b67b47bb4cd89aa82754ef0a1234 /Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs | |
parent | c07297373df08bd605f5bec96020192bb6dec151 (diff) | |
parent | d1ebb882e8484c80eca86cac80602fb4c1401834 (diff) | |
download | timeline-52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24.tar.gz timeline-52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24.tar.bz2 timeline-52f5d2724d74ddb37141d8dfcc8384c0c8ce0e24.zip |
Merge pull request #34 from crupest/token-time
Set token expired time and write unit tests.
Diffstat (limited to 'Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs')
-rw-r--r-- | Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs b/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs deleted file mode 100644 index a7616b41..00000000 --- a/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Timeline.Models; -using Xunit.Abstractions; - -namespace Timeline.Tests.Helpers -{ - public static class WebApplicationFactoryExtensions - { - public static WebApplicationFactory<TEntry> WithTestConfig<TEntry>(this WebApplicationFactory<TEntry> factory, ITestOutputHelper outputHelper) where TEntry : class - { - return factory.WithWebHostBuilder(builder => - { - builder - .ConfigureLogging(logging => - { - logging.AddXunit(outputHelper); - }) - .ConfigureServices(services => - { - var serviceProvider = new ServiceCollection() - .AddEntityFrameworkInMemoryDatabase() - .BuildServiceProvider(); - - services.AddDbContext<DatabaseContext>(options => - { - options.UseInMemoryDatabase("timeline"); - options.UseInternalServiceProvider(serviceProvider); - }); - - var sp = services.BuildServiceProvider(); - - // Create a scope to obtain a reference to the database - // context (ApplicationDbContext). - using (var scope = sp.CreateScope()) - { - var scopedServices = scope.ServiceProvider; - var db = scopedServices.GetRequiredService<DatabaseContext>(); - - // Ensure the database is created. - db.Database.EnsureCreated(); - - db.Users.AddRange(TestMockUsers.MockUsers); - db.SaveChanges(); - } - }); - }); - } - } -} |