aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline.Tests')
-rw-r--r--Timeline.Tests/AuthorizationUnitTest.cs6
-rw-r--r--Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs2
-rw-r--r--Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs50
-rw-r--r--Timeline.Tests/JwtTokenUnitTest.cs4
-rw-r--r--Timeline.Tests/Timeline.Tests-CI.csproj27
-rw-r--r--Timeline.Tests/Timeline.Tests.csproj5
6 files changed, 56 insertions, 38 deletions
diff --git a/Timeline.Tests/AuthorizationUnitTest.cs b/Timeline.Tests/AuthorizationUnitTest.cs
index 2693366c..e450af06 100644
--- a/Timeline.Tests/AuthorizationUnitTest.cs
+++ b/Timeline.Tests/AuthorizationUnitTest.cs
@@ -10,9 +10,9 @@ namespace Timeline.Tests
{
public class AuthorizationUnitTest : IClassFixture<WebApplicationFactory<Startup>>
{
- private const string NeedAuthorizeUrl = "api/test/User/NeedAuthorize";
- private const string BothUserAndAdminUrl = "api/test/User/BothUserAndAdmin";
- private const string OnlyAdminUrl = "api/test/User/OnlyAdmin";
+ private const string NeedAuthorizeUrl = "Test/User/NeedAuthorize";
+ private const string BothUserAndAdminUrl = "Test/User/BothUserAndAdmin";
+ private const string OnlyAdminUrl = "Test/User/OnlyAdmin";
private readonly WebApplicationFactory<Startup> _factory;
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
index ccb2a372..1949df9b 100644
--- a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
+++ b/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
@@ -10,7 +10,7 @@ namespace Timeline.Tests.Helpers.Authentication
{
public static class AuthenticationHttpClientExtensions
{
- private const string CreateTokenUrl = "/api/User/CreateToken";
+ private const string CreateTokenUrl = "/User/CreateToken";
public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, bool assertSuccess = true)
{
diff --git a/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs b/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs
index bb8fc71b..4a7f87fb 100644
--- a/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs
+++ b/Timeline.Tests/Helpers/WebApplicationFactoryExtensions.cs
@@ -1,6 +1,10 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
+using Timeline.Models;
+using Timeline.Services;
using Xunit.Abstractions;
namespace Timeline.Tests.Helpers
@@ -16,6 +20,52 @@ namespace Timeline.Tests.Helpers
.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>();
+
+ var passwordService = new PasswordService(null);
+
+ // Ensure the database is created.
+ db.Database.EnsureCreated();
+
+ db.Users.AddRange(new User[] {
+ new User
+ {
+ Id = 0,
+ Name = "user",
+ EncryptedPassword = passwordService.HashPassword("user"),
+ RoleString = "user"
+ },
+ new User
+ {
+ Id = 0,
+ Name = "admin",
+ EncryptedPassword = passwordService.HashPassword("admin"),
+ RoleString = "user,admin"
+ }
+ });
+
+ db.SaveChanges();
+ }
});
});
}
diff --git a/Timeline.Tests/JwtTokenUnitTest.cs b/Timeline.Tests/JwtTokenUnitTest.cs
index 7e881895..3c03dfc2 100644
--- a/Timeline.Tests/JwtTokenUnitTest.cs
+++ b/Timeline.Tests/JwtTokenUnitTest.cs
@@ -12,8 +12,8 @@ namespace Timeline.Tests
{
public class JwtTokenUnitTest : IClassFixture<WebApplicationFactory<Startup>>
{
- private const string CreateTokenUrl = "/api/User/CreateToken";
- private const string ValidateTokenUrl = "/api/User/ValidateToken";
+ private const string CreateTokenUrl = "User/CreateToken";
+ private const string ValidateTokenUrl = "User/ValidateToken";
private readonly WebApplicationFactory<Startup> _factory;
diff --git a/Timeline.Tests/Timeline.Tests-CI.csproj b/Timeline.Tests/Timeline.Tests-CI.csproj
deleted file mode 100644
index 3639dbf8..00000000
--- a/Timeline.Tests/Timeline.Tests-CI.csproj
+++ /dev/null
@@ -1,27 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
-
- <PropertyGroup>
- <TargetFramework>netcoreapp2.2</TargetFramework>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.App" />
- <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
- <PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="2.2.0-rtm-35646" />
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
- <PackageReference Include="xunit" Version="2.4.1" />
- <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
- <PrivateAssets>all</PrivateAssets>
- <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
- </PackageReference>
- </ItemGroup>
-
- <ItemGroup>
- <ProjectReference Include="..\Timeline\Timeline-CI.csproj" />
- </ItemGroup>
-
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
-
-</Project>
diff --git a/Timeline.Tests/Timeline.Tests.csproj b/Timeline.Tests/Timeline.Tests.csproj
index cbb8ab59..57e04fc0 100644
--- a/Timeline.Tests/Timeline.Tests.csproj
+++ b/Timeline.Tests/Timeline.Tests.csproj
@@ -19,9 +19,4 @@
<ItemGroup>
<ProjectReference Include="..\Timeline\Timeline.csproj" />
</ItemGroup>
-
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
-
</Project>