More unit tests around the login and also the core Plex Checker

pull/470/head
tidusjar 9 years ago
parent 4eff175424
commit 13324cac14

@ -35,20 +35,14 @@ namespace PlexRequests.Core
public const string PlexLibaries = nameof(PlexLibaries); public const string PlexLibaries = nameof(PlexLibaries);
public const string PlexEpisodes = nameof(PlexEpisodes); public const string PlexEpisodes = nameof(PlexEpisodes);
public const string TvDbToken = nameof(TvDbToken); public const string TvDbToken = nameof(TvDbToken);
public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles); public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles);
public const string SonarrQueued = nameof(SonarrQueued); public const string SonarrQueued = nameof(SonarrQueued);
public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles); public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles);
public const string SickRageQueued = nameof(SickRageQueued); public const string SickRageQueued = nameof(SickRageQueued);
public const string CouchPotatoQualityProfiles = nameof(CouchPotatoQualityProfiles); public const string CouchPotatoQualityProfiles = nameof(CouchPotatoQualityProfiles);
public const string CouchPotatoQueued = nameof(CouchPotatoQueued); public const string CouchPotatoQueued = nameof(CouchPotatoQueued);
public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings); public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings);
public const string LastestProductVersion = nameof(LastestProductVersion); public const string LastestProductVersion = nameof(LastestProductVersion);
} }
} }

@ -25,26 +25,35 @@
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Plex;
using PlexRequests.Core; using PlexRequests.Core;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Services.Interfaces; using PlexRequests.Services.Interfaces;
using PlexRequests.Helpers; using PlexRequests.Helpers;
using PlexRequests.Services.Jobs; using PlexRequests.Services.Jobs;
using PlexRequests.Services.Models;
using PlexRequests.Store.Models; using PlexRequests.Store.Models;
using PlexRequests.Store.Repository; using PlexRequests.Store.Repository;
using Ploeh.AutoFixture;
namespace PlexRequests.Services.Tests namespace PlexRequests.Services.Tests
{ {
[TestFixture] [TestFixture]
public class PlexAvailabilityCheckerTests public class PlexAvailabilityCheckerTests
{ {
public IAvailabilityChecker Checker { get; set; } public IAvailabilityChecker Checker { get; set; }
private Fixture F { get; set; } = new Fixture();
private Mock<ISettingsService<PlexSettings>> SettingsMock { get; set; } private Mock<ISettingsService<PlexSettings>> SettingsMock { get; set; }
private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; } private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
private Mock<IRequestService> RequestMock { get; set; } private Mock<IRequestService> RequestMock { get; set; }
@ -82,27 +91,190 @@ namespace PlexRequests.Services.Tests
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never); PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
} }
//[Test] [TestCaseSource(nameof(IsMovieAvailableTestData))]
//public void IsAvailableTest() public bool IsMovieAvailableTest(string title, string year)
//{ {
// var settingsMock = new Mock<ISettingsService<PlexSettings>>(); var movies = new List<PlexMovie>
// var authMock = new Mock<ISettingsService<AuthenticationSettings>>(); {
// var requestMock = new Mock<IRequestService>(); new PlexMovie {Title = title, ProviderId = null, ReleaseYear = year}
// var plexMock = new Mock<IPlexApi>(); };
// var cacheMock = new Mock<ICacheProvider>(); var result = Checker.IsMovieAvailable(movies.ToArray(), "title", "2011");
// var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "title", Year = "2011" } } }; return result;
}
// settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" }); private static IEnumerable<TestCaseData> IsMovieAvailableTestData
// authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" }); {
// plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(searchResult); get
{
yield return new TestCaseData("title", "2011").Returns(true).SetName("IsMovieAvailable True");
yield return new TestCaseData("title2", "2011").Returns(false).SetName("IsMovieAvailable False different title");
yield return new TestCaseData("title", "2001").Returns(false).SetName("IsMovieAvailable False different year");
}
}
// Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object, cacheMock.Object);
// var result = Checker.IsAvailable("title", "2011", null, PlexType.Movie); [TestCaseSource(nameof(IsMovieAvailableAdvancedTestData))]
public bool IsMovieAvailableAdvancedTest(string title, string year, string providerId)
{
var movies = new List<PlexMovie>
{
new PlexMovie {Title = title, ProviderId = providerId, ReleaseYear = year }
};
var result = Checker.IsMovieAvailable(movies.ToArray(), "title", "2011", 9999.ToString());
return result;
}
private static IEnumerable<TestCaseData> IsMovieAvailableAdvancedTestData
{
get
{
yield return new TestCaseData("title", "2011", "9999").Returns(true).SetName("Advanced IsMovieAvailable True");
yield return new TestCaseData("title2", "2011", "99929").Returns(false).SetName("Advanced IsMovieAvailable False different title");
yield return new TestCaseData("title", "2001", "99939").Returns(false).SetName("Advanced IsMovieAvailable False different year");
yield return new TestCaseData("title", "2001", "44445").Returns(false).SetName("Advanced IsMovieAvailable False different providerID");
}
}
[TestCaseSource(nameof(IsTvAvailableTestData))]
public bool IsTvAvailableTest(string title, string year)
{
var tv = new List<PlexTvShow>
{
new PlexTvShow {Title = title, ProviderId = null, ReleaseYear = year}
};
var result = Checker.IsTvShowAvailable(tv.ToArray(), "title", "2011");
return result;
}
private static IEnumerable<TestCaseData> IsTvAvailableTestData
{
get
{
yield return new TestCaseData("title", "2011").Returns(true).SetName("IsTvAvailable True");
yield return new TestCaseData("title2", "2011").Returns(false).SetName("IsTvAvailable False different title");
yield return new TestCaseData("title", "2001").Returns(false).SetName("IsTvAvailable False different year");
}
}
[TestCaseSource(nameof(IsTvAvailableAdvancedTestData))]
public bool IsTvAvailableAdvancedTest(string title, string year, string providerId)
{
var movies = new List<PlexTvShow>
{
new PlexTvShow {Title = title, ProviderId = providerId, ReleaseYear = year }
};
var result = Checker.IsTvShowAvailable(movies.ToArray(), "title", "2011", 9999.ToString());
return result;
}
private static IEnumerable<TestCaseData> IsTvAvailableAdvancedTestData
{
get
{
yield return new TestCaseData("title", "2011", "9999").Returns(true).SetName("Advanced IsTvAvailable True");
yield return new TestCaseData("title2", "2011", "99929").Returns(false).SetName("Advanced IsTvAvailable False different title");
yield return new TestCaseData("title", "2001", "99939").Returns(false).SetName("Advanced IsTvAvailable False different year");
yield return new TestCaseData("title", "2001", "44445").Returns(false).SetName("Advanced IsTvAvailable False different providerID");
}
}
[TestCaseSource(nameof(IsTvAvailableAdvancedSeasonsTestData))]
public bool IsTvAvailableAdvancedSeasonsTest(string title, string year, string providerId, int[] seasons)
{
var movies = new List<PlexTvShow>
{
new PlexTvShow {Title = title, ProviderId = providerId, ReleaseYear = year , Seasons = seasons}
};
var result = Checker.IsTvShowAvailable(movies.ToArray(), "title", "2011", 9999.ToString(), new[] { 1, 2, 3 });
return result;
}
private static IEnumerable<TestCaseData> IsTvAvailableAdvancedSeasonsTestData
{
get
{
yield return new TestCaseData("title", "2011", "9999", new[] { 1, 2, 3 }).Returns(true).SetName("Advanced IsTvSeasonsAvailable True");
yield return new TestCaseData("title2", "2011", "99929", new[] { 5, 6 }).Returns(false).SetName("Advanced IsTvSeasonsAvailable False no seasons");
yield return new TestCaseData("title2", "2011", "99929", new[] { 1, 6 }).Returns(true).SetName("Advanced IsTvSeasonsAvailable true one season");
}
}
[TestCaseSource(nameof(IsEpisodeAvailableTestData))]
public bool IsEpisodeAvailableTest(string providerId, int season, int episode)
{
var expected = new List<PlexEpisodes>
{
new PlexEpisodes {EpisodeNumber = 1, ShowTitle = "The Flash",ProviderId = 23.ToString(), SeasonNumber = 1, EpisodeTitle = "Pilot"}
};
PlexEpisodes.Setup(x => x.Custom(It.IsAny<Func<IDbConnection, IEnumerable<PlexEpisodes>>>())).Returns(expected);
Checker = new PlexAvailabilityChecker(SettingsMock.Object, RequestMock.Object, PlexMock.Object, CacheMock.Object, NotificationMock.Object, JobRec.Object, NotifyUsers.Object, PlexEpisodes.Object);
var result = Checker.IsEpisodeAvailable(providerId, season, episode);
return result;
}
private static IEnumerable<TestCaseData> IsEpisodeAvailableTestData
{
get
{
yield return new TestCaseData("23", 1, 1).Returns(true).SetName("IsEpisodeAvailable True S01E01");
yield return new TestCaseData("23", 1, 2).Returns(false).SetName("IsEpisodeAvailable False S01E02");
yield return new TestCaseData("23", 99, 99).Returns(false).SetName("IsEpisodeAvailable False S99E99");
yield return new TestCaseData("230", 99, 99).Returns(false).SetName("IsEpisodeAvailable False Incorrect ProviderId");
}
}
[Test]
public void GetPlexMoviesTests()
{
var cachedMovies = F.Build<PlexSearch>().Without(x => x.Directory).CreateMany().ToList();
cachedMovies.Add(new PlexSearch
{
Video = new List<Video>
{
new Video {Type = "movie", Title = "title1", Year = "2016", ProviderId = "1212"}
}
});
CacheMock.Setup(x => x.Get<List<PlexSearch>>(CacheKeys.PlexLibaries)).Returns(cachedMovies);
var movies = Checker.GetPlexMovies();
Assert.That(movies.Any(x => x.ProviderId == "1212"));
}
[Test]
public void GetPlexTvShowsTests()
{
var cachedTv = F.Build<PlexSearch>().Without(x => x.Directory).CreateMany().ToList();
cachedTv.Add(new PlexSearch
{
Directory = new List<Directory1>
{
new Directory1 {Type = "show", Title = "title1", Year = "2016", ProviderId = "1212", Seasons = new List<Directory1>()}
}
});
CacheMock.Setup(x => x.Get<List<PlexSearch>>(CacheKeys.PlexLibaries)).Returns(cachedTv);
var movies = Checker.GetPlexTvShows();
Assert.That(movies.Any(x => x.ProviderId == "1212"));
}
[Test]
public async Task GetAllPlexEpisodes()
{
PlexEpisodes.Setup(x => x.GetAllAsync()).ReturnsAsync(F.CreateMany<PlexEpisodes>().ToList());
Checker = new PlexAvailabilityChecker(SettingsMock.Object, RequestMock.Object, PlexMock.Object, CacheMock.Object, NotificationMock.Object, JobRec.Object, NotifyUsers.Object, PlexEpisodes.Object);
var episodes = await Checker.GetEpisodes();
Assert.That(episodes.Count(), Is.GreaterThan(0));
}
// Assert.That(result, Is.True);
//}
//[Test] //[Test]
//public void IsAvailableMusicDirectoryTitleTest() //public void IsAvailableMusicDirectoryTitleTest()

@ -61,6 +61,7 @@
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" />
</ItemGroup> </ItemGroup>
<Choose> <Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">

@ -48,8 +48,6 @@ using PlexRequests.Store.Repository;
using Quartz; using Quartz;
using Action = PlexRequests.Helpers.Analytics.Action;
namespace PlexRequests.Services.Jobs namespace PlexRequests.Services.Jobs
{ {
public class PlexAvailabilityChecker : IJob, IAvailabilityChecker public class PlexAvailabilityChecker : IJob, IAvailabilityChecker
@ -202,7 +200,8 @@ namespace PlexRequests.Services.Jobs
var libs = Cache.Get<List<PlexSearch>>(CacheKeys.PlexLibaries); var libs = Cache.Get<List<PlexSearch>>(CacheKeys.PlexLibaries);
if (libs != null) if (libs != null)
{ {
var tvLibs = libs.Where(x => var withDir = libs.Where(x => x.Directory != null);
var tvLibs = withDir.Where(x =>
x.Directory.Any(y => x.Directory.Any(y =>
y.Type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase) y.Type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)
) )
@ -215,7 +214,7 @@ namespace PlexRequests.Services.Jobs
Title = x.Title, Title = x.Title,
ReleaseYear = x.Year, ReleaseYear = x.Year,
ProviderId = x.ProviderId, ProviderId = x.ProviderId,
Seasons = x.Seasons.Select(d => PlexHelper.GetSeasonNumberFromTitle(d.Title)).ToArray() Seasons = x.Seasons?.Select(d => PlexHelper.GetSeasonNumberFromTitle(d.Title)).ToArray()
})); }));
} }
} }

@ -1,441 +1,496 @@
//#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;
//using System.Threading.Tasks; using System.Collections.Generic;
using System.Threading.Tasks;
//using Moq;
using Moq;
//using Nancy;
//using Nancy.Testing; using Nancy;
using Nancy.Linker;
//using Newtonsoft.Json; using Nancy.Testing;
//using NUnit.Framework; using Newtonsoft.Json;
//using PlexRequests.Api.Interfaces; using NUnit.Framework;
//using PlexRequests.Api.Models.Plex;
//using PlexRequests.Core; using PlexRequests.Api.Interfaces;
//using PlexRequests.Core.SettingModels; using PlexRequests.Api.Models.Plex;
//using PlexRequests.Helpers.Analytics; using PlexRequests.Core;
//using PlexRequests.UI.Models; using PlexRequests.Core.SettingModels;
//using PlexRequests.UI.Modules; using PlexRequests.Helpers.Analytics;
using PlexRequests.UI.Models;
//namespace PlexRequests.UI.Tests using PlexRequests.UI.Modules;
//{
// [TestFixture] namespace PlexRequests.UI.Tests
// public class UserLoginModuleTests {
// { [TestFixture]
// private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; } public class UserLoginModuleTests
// private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; } {
// private Mock<ISettingsService<LandingPageSettings>> LandingPageMock { get; set; } private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
// private ConfigurableBootstrapper Bootstrapper { get; set; } private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
// private Mock<IPlexApi> PlexMock { get; set; } private Mock<ISettingsService<LandingPageSettings>> LandingPageMock { get; set; }
// private Mock<IAnalytics> IAnalytics { get; set; } private Mock<ISettingsService<PlexSettings>> PlexSettingsMock { get; set; }
private ConfigurableBootstrapper Bootstrapper { get; set; }
// [SetUp] private Mock<IPlexApi> PlexMock { get; set; }
// public void Setup() private Mock<IAnalytics> IAnalytics { get; set; }
// { private Mock<IResourceLinker> Linker { get; set; }
// AuthMock = new Mock<ISettingsService<AuthenticationSettings>>();
// PlexMock = new Mock<IPlexApi>(); [SetUp]
// LandingPageMock = new Mock<ISettingsService<LandingPageSettings>>(); public void Setup()
// PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>(); {
// PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings()); AuthMock = new Mock<ISettingsService<AuthenticationSettings>>();
// PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings())); PlexMock = new Mock<IPlexApi>();
// LandingPageMock.Setup(x => x.GetSettings()).Returns(new LandingPageSettings()); LandingPageMock = new Mock<ISettingsService<LandingPageSettings>>();
// IAnalytics = new Mock<IAnalytics>(); PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
// Bootstrapper = new ConfigurableBootstrapper(with => PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
// { PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings()));
// with.Module<UserLoginModule>(); LandingPageMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new LandingPageSettings());
// with.Dependency(PlexRequestMock.Object); IAnalytics = new Mock<IAnalytics>();
// with.Dependency(AuthMock.Object); Linker = new Mock<IResourceLinker>();
// with.Dependency(PlexMock.Object); Linker.Setup(x => x.BuildAbsoluteUri(It.IsAny<NancyContext>(), "SearchIndex", null)).Returns(new Uri("http://www.searchindex.com"));
// with.Dependency(LandingPageMock.Object); Linker.Setup(x => x.BuildAbsoluteUri(It.IsAny<NancyContext>(), "LandingPageIndex", null)).Returns(new Uri("http://www.landingpage.com"));
// with.Dependency(IAnalytics.Object); Linker.Setup(x => x.BuildAbsoluteUri(It.IsAny<NancyContext>(), "UserLoginIndex", null)).Returns(new Uri("http://www.userloginindex.com"));
// with.RootPathProvider<TestRootPathProvider>(); PlexSettingsMock = new Mock<ISettingsService<PlexSettings>>();
// }); PlexSettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings() {PlexAuthToken = "abc"});
// } Bootstrapper = new ConfigurableBootstrapper(with =>
{
// [Test] with.Module<UserLoginModule>();
// public void LoginWithoutAuthentication() with.Dependency(PlexRequestMock.Object);
// { with.Dependency(AuthMock.Object);
// var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" }; with.Dependency(PlexMock.Object);
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); with.Dependency(LandingPageMock.Object);
with.Dependency(IAnalytics.Object);
// Bootstrapper.WithSession(new Dictionary<string, object>()); with.Dependency(Linker.Object);
with.Dependency(PlexSettingsMock.Object);
// var browser = new Browser(Bootstrapper); with.RootPathProvider<TestRootPathProvider>();
// var result = browser.Post("/userlogin", with => });
// { }
// with.HttpRequest();
// with.Header("Accept", "application/json"); [Test]
// with.FormValue("Username", "abc"); public void LoginWithoutAuthentication()
// }); {
var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
Bootstrapper.WithSession(new Dictionary<string, object>());
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
// Assert.That(body.Result, Is.EqualTo(true)); var browser = new Browser(Bootstrapper);
// AuthMock.Verify(x => x.GetSettings(), Times.Once); var result = browser.Post("/userlogin", with =>
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never); {
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never); with.HttpRequest();
// } with.Header("Accept", "application/json");
with.FormValue("Username", "abc");
// [Test] });
// public void LoginWithoutAuthenticationWithEmptyUsername()
// { Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// var expectedSettings = new AuthenticationSettings { UserAuthentication = false, PlexAuthToken = "abc" }; Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
// Bootstrapper.WithSession(new Dictionary<string, object>()); AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
// var browser = new Browser(Bootstrapper); PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
// var result = browser.Post("/userlogin", with => }
// {
// with.HttpRequest(); [Test]
// with.Header("Accept", "application/json"); public void LoginWithoutAuthenticationWithEmptyUsername()
// with.FormValue("Username", string.Empty); {
// }); var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); Bootstrapper.WithSession(new Dictionary<string, object>());
// Assert.That(body.Result, Is.EqualTo(false));
// AuthMock.Verify(x => x.GetSettings(), Times.Never); var browser = new Browser(Bootstrapper);
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never); var result = browser.Post("/userlogin", with =>
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never); {
// } with.HttpRequest();
with.Header("Accept", "application/json");
// [Test] with.FormValue("Username", string.Empty);
// public void LoginWithUsernameSuccessfully() });
// {
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" }; Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// var plexFriends = new PlexFriends
// {
// User = new[] Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
// { AuthMock.Verify(x => x.GetSettingsAsync(), Times.Never);
// new UserFriends PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
// { PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
// Title = "abc", }
// },
// } [Test]
// }; public void LoginWithUsernameSuccessfully()
{
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); var expectedSettings = new AuthenticationSettings { UserAuthentication = true };
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends); var plexFriends = new PlexFriends
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount()); {
User = new[]
// Bootstrapper.WithSession(new Dictionary<string, object>()); {
new UserFriends
// var browser = new Browser(Bootstrapper); {
// var result = browser.Post("/userlogin", with => Title = "abc",
// { },
// with.HttpRequest(); }
// with.Header("Accept", "application/json"); };
// with.FormValue("Username", "abc");
// }); AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
Bootstrapper.WithSession(new Dictionary<string, object>());
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
// Assert.That(body.Result, Is.EqualTo(true)); var browser = new Browser(Bootstrapper);
// AuthMock.Verify(x => x.GetSettings(), Times.Once); var result = browser.Post("/userlogin", with =>
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never); {
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once); with.HttpRequest();
// } with.Header("Accept", "application/json");
with.FormValue("Username", "abc");
// [Test] });
// public void LoginWithUsernameUnSuccessfully()
// { Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" }; Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
// var plexFriends = new PlexFriends
// {
// User = new[]
// { Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
// new UserFriends AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
// { PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
// Username = "aaaa", PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
// }, }
// }
// }; [Test]
public void LoginWithUsernameUnSuccessfully()
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); {
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends); var expectedSettings = new AuthenticationSettings { UserAuthentication = true };
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount()); var plexFriends = new PlexFriends
{
// Bootstrapper.WithSession(new Dictionary<string, object>()); User = new[]
{
// var browser = new Browser(Bootstrapper); new UserFriends
{
// var result = browser.Post("/userlogin", with => Username = "aaaa",
// { },
// with.HttpRequest(); }
// with.Header("Accept", "application/json"); };
// with.FormValue("Username", "abc");
// }); AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null); Bootstrapper.WithSession(new Dictionary<string, object>());
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); var browser = new Browser(Bootstrapper);
// Assert.That(body.Result, Is.EqualTo(false));
// Assert.That(body.Message, Is.Not.Empty); var result = browser.Post("/userlogin", with =>
// AuthMock.Verify(x => x.GetSettings(), Times.Once); {
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never); with.HttpRequest();
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once); with.Header("Accept", "application/json");
// } with.FormValue("Username", "abc");
});
// [Test]
// public void LoginWithUsernameAndPasswordSuccessfully()
// { Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" }; Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
// var plexFriends = new PlexFriends
// { Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
// User = new[] AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
// { PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
// new UserFriends PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
// { }
// Title = "abc",
// } [Test]
// } public void LoginWithUsernameAndPasswordSuccessfully()
// }; {
// var plexAuth = new PlexAuthentication var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true };
// { var plexFriends = new PlexFriends
// user = new User {
// { User = new[]
// authentication_token = "abc" {
// } new UserFriends
// }; {
Title = "abc",
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); }
// 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.GetAccount(It.IsAny<string>())).Returns(new PlexAccount()); var plexAuth = new PlexAuthentication
{
// Bootstrapper.WithSession(new Dictionary<string, object>()); user = new User
{
// var browser = new Browser(Bootstrapper); authentication_token = "abc"
// var result = browser.Post("/userlogin", with => }
// { };
// with.HttpRequest();
// with.Header("Accept", "application/json"); AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
// with.FormValue("Username", "abc"); PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
// with.FormValue("Password", "abc"); PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
// }); PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(new PlexAccount());
Bootstrapper.WithSession(new Dictionary<string, object>());
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc")); var browser = new Browser(Bootstrapper);
var result = browser.Post("/userlogin", with =>
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); {
// Assert.That(body.Result, Is.EqualTo(true)); with.HttpRequest();
// AuthMock.Verify(x => x.GetSettings(), Times.Once); with.Header("Accept", "application/json");
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Once); with.FormValue("Username", "abc");
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once); with.FormValue("Password", "abc");
// } });
// [Test] Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// public void LoginWithUsernameAndPasswordUnSuccessfully() Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
// {
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" }; Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
// var plexFriends = new PlexFriends AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
// { PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
// User = new[] PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
// { }
// new UserFriends
// { [Test]
// Username = "abc", public void LoginWithUsernameAndPasswordUnSuccessfully()
// }, {
// } var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true };
// }; var plexFriends = new PlexFriends
// var plexAuth = new PlexAuthentication {
// { User = new[]
// user = null {
// }; new UserFriends
{
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); Username = "abc",
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends); },
// PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth); }
};
var plexAuth = new PlexAuthentication
// Bootstrapper.WithSession(new Dictionary<string, object>()); {
user = null
// var browser = new Browser(Bootstrapper); };
// var result = browser.Post("/userlogin", with =>
// { AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
// with.HttpRequest(); PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
// with.Header("Accept", "application/json"); PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
// with.FormValue("Username", "abc");
// with.FormValue("Password", "abc");
// }); Bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(Bootstrapper);
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); var result = browser.Post("/userlogin", with =>
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null); {
with.HttpRequest();
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); with.Header("Accept", "application/json");
// Assert.That(body.Result, Is.EqualTo(false)); with.FormValue("Username", "abc");
// Assert.That(body.Message, Is.Not.Empty); with.FormValue("Password", "abc");
// 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);
// } Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
// [Test]
// public void AttemptToLoginAsDeniedUser() Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
// { AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
// var expectedSettings = new AuthenticationSettings { UserAuthentication = false, DeniedUsers = "abc", PlexAuthToken = "abc" }; PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
}
// Bootstrapper.WithSession(new Dictionary<string, object>());
[Test]
// var browser = new Browser(Bootstrapper); public void AttemptToLoginAsDeniedUser()
// var result = browser.Post("/userlogin", with => {
// { var expectedSettings = new AuthenticationSettings { UserAuthentication = false, DeniedUsers = "abc" };
// with.HttpRequest(); AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
// with.Header("Accept", "application/json");
// with.FormValue("Username", "abc"); Bootstrapper.WithSession(new Dictionary<string, object>());
// });
var browser = new Browser(Bootstrapper);
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); var result = browser.Post("/userlogin", with =>
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null); {
with.HttpRequest();
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); with.Header("Accept", "application/json");
// Assert.That(body.Result, Is.EqualTo(false)); with.FormValue("Username", "abc");
// 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); Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never); Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
// }
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
// [Test] AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
// public void Logout() PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
// { PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
// Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } }); }
// var browser = new Browser(Bootstrapper); [Test]
// var result = browser.Get("/userlogin/logout", with => public void Logout()
// { {
// with.HttpRequest(); Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } });
// with.Header("Accept", "application/json");
// }); var browser = new Browser(Bootstrapper);
var result = browser.Get("/userlogin/logout", with =>
// Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode)); {
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null); with.HttpRequest();
// } with.Header("Accept", "application/json");
});
// [Test]
// public void LoginWithOwnerUsernameSuccessfully() Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// { Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, PlexAuthToken = "abc" }; }
// var plexFriends = new PlexFriends
// { [Test]
// User = new[] public void LoginWithOwnerUsernameSuccessfully()
// { {
// new UserFriends() var expectedSettings = new AuthenticationSettings { UserAuthentication = true };
// } var plexFriends = new PlexFriends
// }; {
User = new[]
// var account = new PlexAccount { Username = "Jamie" }; {
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); new UserFriends()
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends); }
// 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" } });
var account = new PlexAccount { Username = "Jamie" };
// Bootstrapper.WithSession(new Dictionary<string, object>()); AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
// var browser = new Browser(Bootstrapper); PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
// var result = browser.Post("/userlogin", with => PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(new PlexAuthentication { user = new User { username = "Jamie" } });
// {
// with.HttpRequest(); Bootstrapper.WithSession(new Dictionary<string, object>());
// with.Header("Accept", "application/json");
// with.FormValue("Username", "Jamie"); var browser = new Browser(Bootstrapper);
// }); var result = browser.Post("/userlogin", with =>
{
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); with.HttpRequest();
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("Jamie")); with.Header("Accept", "application/json");
with.FormValue("Username", "Jamie");
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); });
// Assert.That(body.Result, Is.EqualTo(true));
// AuthMock.Verify(x => x.GetSettings(), Times.Once); Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never); Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("Jamie"));
// PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once); Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
// }
AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
// [Test] PlexMock.Verify(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
// public void LoginWithOwnerUsernameAndPasswordSuccessfully() PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
// { }
// var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc" };
// var plexFriends = new PlexFriends [Test]
// { public void LoginWithOwnerUsernameAndPasswordSuccessfully()
// User = new[] {
// { var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true };
// new UserFriends() var plexFriends = new PlexFriends
// } {
// }; User = new[]
// var plexAuth = new PlexAuthentication {
// { new UserFriends()
// user = new User }
// { };
// authentication_token = "abc", var plexAuth = new PlexAuthentication
// username = "Jamie" {
// } user = new User
// }; {
authentication_token = "abc",
// var account = new PlexAccount { Username = "Jamie" }; username = "Jamie"
}
// AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings); };
// PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
// PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth); var account = new PlexAccount { Username = "Jamie" };
// PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
// Bootstrapper.WithSession(new Dictionary<string, object>()); PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
// var browser = new Browser(Bootstrapper); PlexMock.Setup(x => x.GetAccount(It.IsAny<string>())).Returns(account);
// var result = browser.Post("/userlogin", with =>
// { Bootstrapper.WithSession(new Dictionary<string, object>());
// with.HttpRequest();
// with.Header("Accept", "application/json"); var browser = new Browser(Bootstrapper);
// with.FormValue("Username", "jamie"); var result = browser.Post("/userlogin", with =>
// with.FormValue("Password", "abc"); {
// }); with.HttpRequest();
with.Header("Accept", "application/json");
with.FormValue("Username", "jamie");
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); with.FormValue("Password", "abc");
// Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("jamie")); });
// var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString()); Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
// Assert.That(body.Result, Is.EqualTo(true)); Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
// AuthMock.Verify(x => x.GetSettings(), Times.Once); AuthMock.Verify(x => x.GetSettingsAsync(), 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]
[Description("We should go to the landing page as it is enabled after we log in")]
public void LoginWithLandingPageAfterLogin()
{
var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
LandingPageMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new LandingPageSettings { BeforeLogin = false, Enabled = true });
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
Bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(Bootstrapper);
var result = browser.Post("/userlogin", with =>
{
with.HttpRequest();
with.Header("Accept", "application/json");
with.FormValue("Username", "abc");
});
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.landingpage.com/"))); // Redirect header
AuthMock.Verify(x => x.GetSettingsAsync(), 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]
[Description("We shouldn't go to the landing page as we have already been there!")]
public void LoginWithLandingPageBefore()
{
var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
LandingPageMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new LandingPageSettings { BeforeLogin = true, Enabled = true });
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
Bootstrapper.WithSession(new Dictionary<string, object>());
var browser = new Browser(Bootstrapper);
var result = browser.Post("/userlogin", with =>
{
with.HttpRequest();
with.Header("Accept", "application/json");
with.FormValue("Username", "abc");
});
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
AuthMock.Verify(x => x.GetSettingsAsync(), 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);
}
}
}

@ -673,6 +673,7 @@ namespace PlexRequests.UI.Modules
} }
} }
//TODO this is not working correctly.
var episodes = await GetEpisodes(showId); var episodes = await GetEpisodes(showId);
var availableEpisodes = episodes.Where(x => x.Requested).ToList(); var availableEpisodes = episodes.Where(x => x.Requested).ToList();
var availble = availableEpisodes.Select(a => new EpisodesModel { EpisodeNumber = a.EpisodeNumber, SeasonNumber = a.SeasonNumber }).ToList(); var availble = availableEpisodes.Select(a => new EpisodesModel { EpisodeNumber = a.EpisodeNumber, SeasonNumber = a.SeasonNumber }).ToList();

@ -166,7 +166,7 @@ namespace PlexRequests.UI.Modules
return Response.AsRedirect(uri.ToString()); // TODO Check this return Response.AsRedirect(uri.ToString()); // TODO Check this
} }
var landingSettings = LandingPageSettings.GetSettings(); var landingSettings = await LandingPageSettings.GetSettingsAsync();
if (landingSettings.Enabled) if (landingSettings.Enabled)
{ {

Loading…
Cancel
Save