Use new Auth API
This commit is contained in:
parent
38e76d3539
commit
79c17f75cd
16 changed files with 94 additions and 150 deletions
55
Website.Tests/Data/AuthenticationProviderTests.cs
Normal file
55
Website.Tests/Data/AuthenticationProviderTests.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Website.Data;
|
||||
using Website.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace Website.Tests.Data {
|
||||
public class AuthenticationProviderTests {
|
||||
[Fact]
|
||||
public async Task Authenticate_WithSuccessfulLoginRequest_ReturnsUser() {
|
||||
const string json = @"{""username"":""username"",""password"":""password""}";
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Post)
|
||||
.WithUrl("/authenticate")
|
||||
.WithPostBody(@"{""Username"":""username"",""Password"":""password"",""ReturnUrl"":null}")
|
||||
.WithResponse(json)
|
||||
.Build();
|
||||
|
||||
var request = new LoginRequest {
|
||||
Username = "username",
|
||||
Password = "password"
|
||||
};
|
||||
|
||||
var expectedUser = new User {
|
||||
Username = "username",
|
||||
Password = "password"
|
||||
};
|
||||
|
||||
var provider = new AuthenticationProvider(httpClient);
|
||||
(await provider.Authenticate(request)).Should().BeEquivalentTo(expectedUser);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Authenticate_WithFailedLoginRequest_ReturnsNull() {
|
||||
const string json = @"{""username"":""username"",""password"":""password""}";
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Post)
|
||||
.WithUrl("/authenticate")
|
||||
.WithPostBody(@"{""Username"":""username"",""Password"":""password"",""ReturnUrl"":null}")
|
||||
.WithErrorStatus(HttpStatusCode.Unauthorized)
|
||||
.WithResponse(json)
|
||||
.Build();
|
||||
|
||||
var request = new LoginRequest {
|
||||
Username = "username",
|
||||
Password = "wrong"
|
||||
};
|
||||
|
||||
var provider = new AuthenticationProvider(httpClient);
|
||||
(await provider.Authenticate(request)).Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue