More test changes

pull/13/head
tidusjar 9 years ago
parent 92e8fa7c4d
commit 6c03e3f0ad

@ -37,7 +37,6 @@ using NUnit.Framework;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models;
using PlexRequests.Api.Models.Tv;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.UI.Models;
@ -75,21 +74,21 @@ namespace PlexRequests.UI.Tests
bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(bootstrapper);
// When
var result = browser.Post("/userlogin", with =>
{
with.HttpRequest();
with.Header("Accept", "application/json");
with.FormValue("Username", "abc");
});
// Then
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
Assert.That(body.Result, Is.EqualTo(true));
AuthMock.Verify(x => x.GetSettings(), Times.Once);
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
}
[Test]
@ -121,7 +120,6 @@ namespace PlexRequests.UI.Tests
bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(bootstrapper);
// When
var result = browser.Post("/userlogin", with =>
{
with.HttpRequest();
@ -129,13 +127,14 @@ namespace PlexRequests.UI.Tests
with.FormValue("Username", "abc");
});
// Then
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
Assert.That(body.Result, Is.EqualTo(true));
AuthMock.Verify(x => x.GetSettings(), Times.Once);
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
}
[Test]
@ -182,6 +181,9 @@ namespace PlexRequests.UI.Tests
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
Assert.That(body.Result, Is.EqualTo(false));
Assert.That(body.Message, Is.Not.Empty);
AuthMock.Verify(x => x.GetSettings(), Times.Once);
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
}
[Test]
@ -221,7 +223,6 @@ namespace PlexRequests.UI.Tests
bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(bootstrapper);
// When
var result = browser.Post("/userlogin", with =>
{
with.HttpRequest();
@ -230,13 +231,15 @@ namespace PlexRequests.UI.Tests
with.FormValue("Password", "abc");
});
// Then
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
Assert.That(body.Result, Is.EqualTo(true));
AuthMock.Verify(x => x.GetSettings(), Times.Once);
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
}
[Test]
@ -273,7 +276,6 @@ namespace PlexRequests.UI.Tests
bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(bootstrapper);
// When
var result = browser.Post("/userlogin", with =>
{
with.HttpRequest();
@ -282,14 +284,16 @@ namespace PlexRequests.UI.Tests
with.FormValue("Password", "abc");
});
// Then
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
Assert.That(body.Result, Is.EqualTo(false));
Assert.That(body.Message, Is.Not.Empty);
AuthMock.Verify(x => x.GetSettings(), Times.Once);
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
}
}
}

@ -48,8 +48,8 @@ namespace PlexRequests.UI.Modules
Post["/"] = x => LoginUser();
}
private ISettingsService<AuthenticationSettings> AuthService { get; set; }
private IPlexApi Api { get; set; }
private ISettingsService<AuthenticationSettings> AuthService { get; }
private IPlexApi Api { get; }
public Negotiator Index()
{

Loading…
Cancel
Save