|
|
@ -1,441 +1,441 @@
|
|
|
|
#region Copyright
|
|
|
|
//#region Copyright
|
|
|
|
// /************************************************************************
|
|
|
|
//// /************************************************************************
|
|
|
|
// Copyright (c) 2016 Jamie Rees
|
|
|
|
//// Copyright (c) 2016 Jamie Rees
|
|
|
|
// File: UserLoginModuleTests.cs
|
|
|
|
//// File: UserLoginModuleTests.cs
|
|
|
|
// Created By: Jamie Rees
|
|
|
|
//// Created By: Jamie Rees
|
|
|
|
//
|
|
|
|
////
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
//// Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
// a copy of this software and associated documentation files (the
|
|
|
|
//// a copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
//// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
//// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
//// distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
//// permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
// the following conditions:
|
|
|
|
//// the following conditions:
|
|
|
|
//
|
|
|
|
////
|
|
|
|
// The above copyright notice and this permission notice shall be
|
|
|
|
//// The above copyright notice and this permission notice shall be
|
|
|
|
// included in all copies or substantial portions of the Software.
|
|
|
|
//// included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
////
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
//// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
//// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
//// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
//// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
//// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
//// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// ************************************************************************/
|
|
|
|
//// ************************************************************************/
|
|
|
|
#endregion
|
|
|
|
//#endregion
|
|
|
|
using System.Collections.Generic;
|
|
|
|
//using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
//using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
using Moq;
|
|
|
|
//using Moq;
|
|
|
|
|
|
|
|
|
|
|
|
using Nancy;
|
|
|
|
//using Nancy;
|
|
|
|
using Nancy.Testing;
|
|
|
|
//using Nancy.Testing;
|
|
|
|
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
//using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
//using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
|
|
using PlexRequests.Api.Interfaces;
|
|
|
|
//using PlexRequests.Api.Interfaces;
|
|
|
|
using PlexRequests.Api.Models.Plex;
|
|
|
|
//using PlexRequests.Api.Models.Plex;
|
|
|
|
using PlexRequests.Core;
|
|
|
|
//using PlexRequests.Core;
|
|
|
|
using PlexRequests.Core.SettingModels;
|
|
|
|
//using PlexRequests.Core.SettingModels;
|
|
|
|
using PlexRequests.Helpers.Analytics;
|
|
|
|
//using PlexRequests.Helpers.Analytics;
|
|
|
|
using PlexRequests.UI.Models;
|
|
|
|
//using PlexRequests.UI.Models;
|
|
|
|
using PlexRequests.UI.Modules;
|
|
|
|
//using PlexRequests.UI.Modules;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PlexRequests.UI.Tests
|
|
|
|
//namespace PlexRequests.UI.Tests
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
[TestFixture]
|
|
|
|
// [TestFixture]
|
|
|
|
public class UserLoginModuleTests
|
|
|
|
// public class UserLoginModuleTests
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
|
|
|
|
// private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
|
|
|
|
private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
|
|
|
|
// private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
|
|
|
|
private Mock<ISettingsService<LandingPageSettings>> LandingPageMock { get; set; }
|
|
|
|
// private Mock<ISettingsService<LandingPageSettings>> LandingPageMock { get; set; }
|
|
|
|
private ConfigurableBootstrapper Bootstrapper { get; set; }
|
|
|
|
// private ConfigurableBootstrapper Bootstrapper { get; set; }
|
|
|
|
private Mock<IPlexApi> PlexMock { get; set; }
|
|
|
|
// private Mock<IPlexApi> PlexMock { get; set; }
|
|
|
|
private Mock<IAnalytics> IAnalytics { get; set; }
|
|
|
|
// private Mock<IAnalytics> IAnalytics { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
// [SetUp]
|
|
|
|
public void Setup()
|
|
|
|
// public void Setup()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
AuthMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
// AuthMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
PlexMock = new Mock<IPlexApi>();
|
|
|
|
// PlexMock = new Mock<IPlexApi>();
|
|
|
|
LandingPageMock = new Mock<ISettingsService<LandingPageSettings>>();
|
|
|
|
// LandingPageMock = new Mock<ISettingsService<LandingPageSettings>>();
|
|
|
|
PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
|
|
|
// PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
|
|
|
PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
|
|
|
|
// PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
|
|
|
|
PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings()));
|
|
|
|
// PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings()));
|
|
|
|
LandingPageMock.Setup(x => x.GetSettings()).Returns(new LandingPageSettings());
|
|
|
|
// LandingPageMock.Setup(x => x.GetSettings()).Returns(new LandingPageSettings());
|
|
|
|
IAnalytics = new Mock<IAnalytics>();
|
|
|
|
// IAnalytics = new Mock<IAnalytics>();
|
|
|
|
Bootstrapper = new ConfigurableBootstrapper(with =>
|
|
|
|
// Bootstrapper = new ConfigurableBootstrapper(with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.Module<UserLoginModule>();
|
|
|
|
// with.Module<UserLoginModule>();
|
|
|
|
with.Dependency(PlexRequestMock.Object);
|
|
|
|
// with.Dependency(PlexRequestMock.Object);
|
|
|
|
with.Dependency(AuthMock.Object);
|
|
|
|
// with.Dependency(AuthMock.Object);
|
|
|
|
with.Dependency(PlexMock.Object);
|
|
|
|
// with.Dependency(PlexMock.Object);
|
|
|
|
with.Dependency(LandingPageMock.Object);
|
|
|
|
// with.Dependency(LandingPageMock.Object);
|
|
|
|
with.Dependency(IAnalytics.Object);
|
|
|
|
// with.Dependency(IAnalytics.Object);
|
|
|
|
with.RootPathProvider<TestRootPathProvider>();
|
|
|
|
// with.RootPathProvider<TestRootPathProvider>();
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithoutAuthentication()
|
|
|
|
// public void LoginWithoutAuthentication()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" };
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "abc");
|
|
|
|
// with.FormValue("Username", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithoutAuthenticationWithEmptyUsername()
|
|
|
|
// public void LoginWithoutAuthenticationWithEmptyUsername()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" };
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", string.Empty);
|
|
|
|
// with.FormValue("Username", string.Empty);
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Never);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithUsernameSuccessfully()
|
|
|
|
// public void LoginWithUsernameSuccessfully()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
|
|
|
var plexFriends = new PlexFriends
|
|
|
|
// var plexFriends = new PlexFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
User = new[]
|
|
|
|
// User = new[]
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
new UserFriends
|
|
|
|
// new UserFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
Title = "abc",
|
|
|
|
// Title = "abc",
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
|
|
|
|
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "abc");
|
|
|
|
// with.FormValue("Username", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithUsernameUnSuccessfully()
|
|
|
|
// public void LoginWithUsernameUnSuccessfully()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
|
|
|
var plexFriends = new PlexFriends
|
|
|
|
// var plexFriends = new PlexFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
User = new[]
|
|
|
|
// User = new[]
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
new UserFriends
|
|
|
|
// new UserFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
Username = "aaaa",
|
|
|
|
// Username = "aaaa",
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
|
|
|
|
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
|
|
|
|
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "abc");
|
|
|
|
// with.FormValue("Username", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
Assert.That(body.Message, Is.Not.Empty);
|
|
|
|
// Assert.That(body.Message, Is.Not.Empty);
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithUsernameAndPasswordSuccessfully()
|
|
|
|
// public void LoginWithUsernameAndPasswordSuccessfully()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
|
|
|
var plexFriends = new PlexFriends
|
|
|
|
// var plexFriends = new PlexFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
User = new[]
|
|
|
|
// User = new[]
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
new UserFriends
|
|
|
|
// new UserFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
Title = "abc",
|
|
|
|
// Title = "abc",
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
var plexAuth = new PlexAuthentication
|
|
|
|
// var plexAuth = new PlexAuthentication
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
user = new User
|
|
|
|
// user = new User
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
authentication_token = "abc"
|
|
|
|
// authentication_token = "abc"
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
|
|
|
// PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
|
|
|
PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
|
|
|
|
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "abc");
|
|
|
|
// with.FormValue("Username", "abc");
|
|
|
|
with.FormValue("Password", "abc");
|
|
|
|
// with.FormValue("Password", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), 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);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithUsernameAndPasswordUnSuccessfully()
|
|
|
|
// public void LoginWithUsernameAndPasswordUnSuccessfully()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
|
|
|
var plexFriends = new PlexFriends
|
|
|
|
// var plexFriends = new PlexFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
User = new[]
|
|
|
|
// User = new[]
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
new UserFriends
|
|
|
|
// new UserFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
Username = "abc",
|
|
|
|
// Username = "abc",
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
var plexAuth = new PlexAuthentication
|
|
|
|
// var plexAuth = new PlexAuthentication
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
user = null
|
|
|
|
// user = null
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
|
|
|
// PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "abc");
|
|
|
|
// with.FormValue("Username", "abc");
|
|
|
|
with.FormValue("Password", "abc");
|
|
|
|
// with.FormValue("Password", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
Assert.That(body.Message, Is.Not.Empty);
|
|
|
|
// Assert.That(body.Message, Is.Not.Empty);
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), 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);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void AttemptToLoginAsDeniedUser()
|
|
|
|
// public void AttemptToLoginAsDeniedUser()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = false, DeniedUsers = "abc", PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = false, DeniedUsers = "abc", PlexAuthToken = "abc" };
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "abc");
|
|
|
|
// with.FormValue("Username", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(false));
|
|
|
|
Assert.That(body.Message, Is.Not.Empty);
|
|
|
|
// Assert.That(body.Message, Is.Not.Empty);
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void Logout()
|
|
|
|
// public void Logout()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } });
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } });
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Get("/userlogin/logout", with =>
|
|
|
|
// var result = browser.Get("/userlogin/logout", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithOwnerUsernameSuccessfully()
|
|
|
|
// public void LoginWithOwnerUsernameSuccessfully()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" };
|
|
|
|
var plexFriends = new PlexFriends
|
|
|
|
// var plexFriends = new PlexFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
User = new[]
|
|
|
|
// User = new[]
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
new UserFriends()
|
|
|
|
// new UserFriends()
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
var account = new PlexAccount { Username = "Jamie" };
|
|
|
|
// var account = new PlexAccount { Username = "Jamie" };
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
|
|
|
|
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
|
|
|
|
PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(new PlexAuthentication { user = new User { username = "Jamie" } });
|
|
|
|
// PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(new PlexAuthentication { user = new User { username = "Jamie" } });
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "Jamie");
|
|
|
|
// with.FormValue("Username", "Jamie");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("Jamie"));
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("Jamie"));
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
|
|
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
// [Test]
|
|
|
|
public void LoginWithOwnerUsernameAndPasswordSuccessfully()
|
|
|
|
// public void LoginWithOwnerUsernameAndPasswordSuccessfully()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
|
|
|
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
|
|
|
|
var plexFriends = new PlexFriends
|
|
|
|
// var plexFriends = new PlexFriends
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
User = new[]
|
|
|
|
// User = new[]
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
new UserFriends()
|
|
|
|
// new UserFriends()
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
var plexAuth = new PlexAuthentication
|
|
|
|
// var plexAuth = new PlexAuthentication
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
user = new User
|
|
|
|
// user = new User
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
authentication_token = "abc",
|
|
|
|
// authentication_token = "abc",
|
|
|
|
username = "Jamie"
|
|
|
|
// username = "Jamie"
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
var account = new PlexAccount { Username = "Jamie" };
|
|
|
|
// var account = new PlexAccount { Username = "Jamie" };
|
|
|
|
|
|
|
|
|
|
|
|
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
|
|
|
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
|
|
|
PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
|
|
|
// PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
|
|
|
PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
|
|
|
|
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
|
|
|
|
|
|
|
|
|
|
|
|
Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
// Bootstrapper.WithSession(new Dictionary<string, object>());
|
|
|
|
|
|
|
|
|
|
|
|
var browser = new Browser(Bootstrapper);
|
|
|
|
// var browser = new Browser(Bootstrapper);
|
|
|
|
var result = browser.Post("/userlogin", with =>
|
|
|
|
// var result = browser.Post("/userlogin", with =>
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
with.HttpRequest();
|
|
|
|
// with.HttpRequest();
|
|
|
|
with.Header("Accept", "application/json");
|
|
|
|
// with.Header("Accept", "application/json");
|
|
|
|
with.FormValue("Username", "jamie");
|
|
|
|
// with.FormValue("Username", "jamie");
|
|
|
|
with.FormValue("Password", "abc");
|
|
|
|
// with.FormValue("Password", "abc");
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
|
|
|
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("jamie"));
|
|
|
|
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("jamie"));
|
|
|
|
|
|
|
|
|
|
|
|
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
|
|
|
Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
// Assert.That(body.Result, Is.EqualTo(true));
|
|
|
|
AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
// AuthMock.Verify(x => x.GetSettings(), Times.Once);
|
|
|
|
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), 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);
|
|
|
|
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//}
|