mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 10:36:54 -07:00
All Sln changes
This commit is contained in:
parent
b5855f2644
commit
796f0fc188
615 changed files with 68 additions and 747 deletions
361
Ombi.UI.Tests/AdminModuleTests.cs
Normal file
361
Ombi.UI.Tests/AdminModuleTests.cs
Normal file
|
@ -0,0 +1,361 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: UserLoginModuleTests.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Nancy;
|
||||
using Nancy.Testing;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Plex;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Helpers.Analytics;
|
||||
using Ombi.Services.Interfaces;
|
||||
using Ombi.Services.Jobs;
|
||||
using Ombi.Store.Models;
|
||||
using Ombi.Store.Repository;
|
||||
using Ombi.UI.Models;
|
||||
using Ombi.UI.Modules.Admin;
|
||||
|
||||
namespace Ombi.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class AdminModuleTests
|
||||
{
|
||||
private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
|
||||
private Mock<ISettingsService<CouchPotatoSettings>> CpMock { get; set; }
|
||||
private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
|
||||
private Mock<ISettingsService<PlexSettings>> PlexSettingsMock { get; set; }
|
||||
private Mock<ISettingsService<SonarrSettings>> SonarrSettingsMock { get; set; }
|
||||
private Mock<ISettingsService<SickRageSettings>> SickRageSettingsMock { get; set; }
|
||||
private Mock<ISettingsService<ScheduledJobsSettings>> ScheduledJobsSettingsMock { get; set; }
|
||||
private Mock<ISettingsService<EmailNotificationSettings>> EmailMock { get; set; }
|
||||
private Mock<ISettingsService<PushbulletNotificationSettings>> PushbulletSettings { get; set; }
|
||||
private Mock<ISettingsService<PushoverNotificationSettings>> PushoverSettings { get; set; }
|
||||
private Mock<ISettingsService<HeadphonesSettings>> HeadphonesSettings { get; set; }
|
||||
private Mock<IPlexApi> PlexMock { get; set; }
|
||||
private Mock<ISonarrApi> SonarrApiMock { get; set; }
|
||||
private Mock<IPushbulletApi> PushbulletApi { get; set; }
|
||||
private Mock<IPushoverApi> PushoverApi { get; set; }
|
||||
private Mock<ICouchPotatoApi> CpApi { get; set; }
|
||||
private Mock<IJobRecord> RecorderMock { get; set; }
|
||||
private Mock<IRepository<LogEntity>> LogRepo { get; set; }
|
||||
private Mock<INotificationService> NotificationService { get; set; }
|
||||
private Mock<ICacheProvider> Cache { get; set; }
|
||||
private Mock<ISettingsService<LogSettings>> Log { get; set; }
|
||||
private Mock<ISettingsService<SlackNotificationSettings>> SlackSettings { get; set; }
|
||||
private Mock<ISettingsService<LandingPageSettings>> LandingPageSettings { get; set; }
|
||||
private Mock<ISlackApi> SlackApi { get; set; }
|
||||
private Mock<IAnalytics> Analytics { get; set; }
|
||||
private Mock<ISettingsService<NotificationSettingsV2>> NotifyV2 { get; set; }
|
||||
private Mock<IRecentlyAdded> RecentlyAdded { get; set; }
|
||||
|
||||
private ConfigurableBootstrapper Bootstrapper { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
AuthMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
|
||||
AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
|
||||
PlexSettingsMock = new Mock<ISettingsService<PlexSettings>>();
|
||||
PlexSettingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings {PlexAuthToken = "abc"});
|
||||
|
||||
PlexMock = new Mock<IPlexApi>();
|
||||
PlexMock.Setup(x => x.SignIn("Username1", "Password1"))
|
||||
.Returns(new PlexAuthentication { user = new User { authentication_token = "abc", title = "Username1" } });
|
||||
|
||||
PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
||||
PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings() );
|
||||
CpMock = new Mock<ISettingsService<CouchPotatoSettings>>();
|
||||
|
||||
SonarrApiMock = new Mock<ISonarrApi>();
|
||||
SonarrSettingsMock = new Mock<ISettingsService<SonarrSettings>>();
|
||||
EmailMock = new Mock<ISettingsService<EmailNotificationSettings>>();
|
||||
PushbulletApi = new Mock<IPushbulletApi>();
|
||||
PushbulletSettings = new Mock<ISettingsService<PushbulletNotificationSettings>>();
|
||||
CpApi = new Mock<ICouchPotatoApi>();
|
||||
SickRageSettingsMock = new Mock<ISettingsService<SickRageSettings>>();
|
||||
LogRepo = new Mock<IRepository<LogEntity>>();
|
||||
PushoverSettings = new Mock<ISettingsService<PushoverNotificationSettings>>();
|
||||
PushoverApi = new Mock<IPushoverApi>();
|
||||
NotificationService = new Mock<INotificationService>();
|
||||
HeadphonesSettings = new Mock<ISettingsService<HeadphonesSettings>>();
|
||||
Cache = new Mock<ICacheProvider>();
|
||||
Log = new Mock<ISettingsService<LogSettings>>();
|
||||
SlackApi = new Mock<ISlackApi>();
|
||||
SlackSettings = new Mock<ISettingsService<SlackNotificationSettings>>();
|
||||
LandingPageSettings = new Mock<ISettingsService<LandingPageSettings>>();
|
||||
ScheduledJobsSettingsMock = new Mock<ISettingsService<ScheduledJobsSettings>>();
|
||||
RecorderMock = new Mock<IJobRecord>();
|
||||
Analytics = new Mock<IAnalytics>();
|
||||
NotifyV2= new Mock<ISettingsService<NotificationSettingsV2>>();
|
||||
RecentlyAdded = new Mock<IRecentlyAdded>();
|
||||
|
||||
|
||||
Bootstrapper = new ConfigurableBootstrapper(with =>
|
||||
{
|
||||
with.Module<AdminModule>();
|
||||
with.Dependency(AuthMock.Object);
|
||||
with.Dependency(PlexRequestMock.Object);
|
||||
with.Dependency(CpMock.Object);
|
||||
with.Dependency(PlexSettingsMock.Object);
|
||||
with.Dependency(SonarrApiMock.Object);
|
||||
with.Dependency(SonarrSettingsMock.Object);
|
||||
with.Dependency(PlexMock.Object);
|
||||
with.Dependency(EmailMock.Object);
|
||||
with.Dependency(PushbulletApi.Object);
|
||||
with.Dependency(PushbulletSettings.Object);
|
||||
with.Dependency(CpApi.Object);
|
||||
with.Dependency(SickRageSettingsMock.Object);
|
||||
with.Dependency(LogRepo.Object);
|
||||
with.Dependency(PushoverSettings.Object);
|
||||
with.Dependency(PushoverApi.Object);
|
||||
with.Dependency(NotifyV2.Object);
|
||||
with.Dependency(NotificationService.Object);
|
||||
with.Dependency(Analytics.Object);
|
||||
with.Dependency(HeadphonesSettings.Object);
|
||||
with.Dependency(Cache.Object);
|
||||
with.Dependency(Log.Object);
|
||||
with.Dependency(SlackApi.Object);
|
||||
with.Dependency(LandingPageSettings.Object);
|
||||
with.Dependency(SlackSettings.Object);
|
||||
with.Dependency(ScheduledJobsSettingsMock.Object);
|
||||
with.Dependency(RecorderMock.Object);
|
||||
with.Dependency(RecentlyAdded.Object);
|
||||
with.RootPathProvider<TestRootPathProvider>();
|
||||
with.RequestStartup((container, pipelines, context) =>
|
||||
{
|
||||
context.CurrentUser = new UserIdentity { UserName = "user", Claims = new List<string> { "Admin" } };
|
||||
});
|
||||
});
|
||||
|
||||
Bootstrapper.WithSession(new Dictionary<string, object>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RequestAuthTokenTestNewSettings()
|
||||
{
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Post("/admin/requestauth", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Username1");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||
Assert.That(body.Result, Is.EqualTo(true));
|
||||
PlexMock.Verify(x => x.SignIn("Username1", "Password1"), Times.Once);
|
||||
PlexSettingsMock.Verify(x => x.SaveSettings(It.IsAny<PlexSettings>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RequestAuthTokenTestEmptyCredentials()
|
||||
{
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Post("/admin/requestauth", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", string.Empty);
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||
Assert.That(body.Result, Is.EqualTo(false));
|
||||
Assert.That(body.Message, Is.Not.Empty);
|
||||
|
||||
PlexMock.Verify(x => x.SignIn("Username1", "Password1"), Times.Never);
|
||||
AuthMock.Verify(x => x.GetSettings(), Times.Never);
|
||||
AuthMock.Verify(x => x.SaveSettings(It.IsAny<AuthenticationSettings>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RequestAuthTokenTesPlexSignInFail()
|
||||
{
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Post("/admin/requestauth", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Badusername");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||
Assert.That(body.Result, Is.EqualTo(false));
|
||||
Assert.That(body.Message, Is.Not.Empty);
|
||||
|
||||
PlexMock.Verify(x => x.SignIn("Badusername", "Password1"), Times.Once);
|
||||
AuthMock.Verify(x => x.GetSettings(), Times.Never);
|
||||
AuthMock.Verify(x => x.SaveSettings(It.IsAny<AuthenticationSettings>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RequestAuthTokenTestExistingSettings()
|
||||
{
|
||||
AuthMock.Setup(x => x.GetSettings()).Returns(() => null);
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Post("/admin/requestauth", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Username1");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<JsonResponseModel>(result.Body.AsString());
|
||||
Assert.That(body.Result, Is.EqualTo(true));
|
||||
|
||||
PlexMock.Verify(x => x.SignIn("Username1", "Password1"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUsersSuccessfully()
|
||||
{
|
||||
var users = new PlexFriends { User = new[] { new UserFriends { Title = "abc2" }, } };
|
||||
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(users);
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Get("/admin/getusers", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Username1");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
|
||||
var body = JsonConvert.DeserializeObject<JObject>(result.Body.AsString());
|
||||
var user = body["users"];
|
||||
Assert.That(body, Is.Not.Null);
|
||||
Assert.That(user.ToString().Contains("abc"), Is.True);
|
||||
|
||||
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUsersReturnsNoUsers()
|
||||
{
|
||||
var users = new PlexFriends();
|
||||
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(users);
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Get("/admin/getusers", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Username1");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<string>(result.Body.AsString());
|
||||
Assert.That(body, Is.Not.Null);
|
||||
Assert.That(string.IsNullOrWhiteSpace(body), Is.True);
|
||||
|
||||
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUsersReturnsNull()
|
||||
{
|
||||
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(() => null);
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Get("/admin/getusers", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Username1");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<string>(result.Body.AsString());
|
||||
Assert.That(body, Is.Not.Null);
|
||||
Assert.That(string.IsNullOrWhiteSpace(body), Is.True);
|
||||
|
||||
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUsersTokenIsNull()
|
||||
{
|
||||
PlexSettingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings());
|
||||
var browser = new Browser(Bootstrapper);
|
||||
|
||||
var result = browser.Get("/admin/getusers", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("username", "Username1");
|
||||
with.FormValue("password", "Password1");
|
||||
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
var body = JsonConvert.DeserializeObject<JObject>(result.Body.AsString());
|
||||
var user = (string)body["users"];
|
||||
Assert.That(body, Is.Not.Null);
|
||||
Assert.That(string.IsNullOrWhiteSpace(user), Is.True);
|
||||
|
||||
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
778
Ombi.UI.Tests/ApiModuleTests.cs
Normal file
778
Ombi.UI.Tests/ApiModuleTests.cs
Normal file
|
@ -0,0 +1,778 @@
|
|||
//#region Copyright
|
||||
//// /************************************************************************
|
||||
//// Copyright (c) 2016 Jamie Rees
|
||||
//// File: ApiModuleTests.cs
|
||||
//// Created By: Jamie Rees
|
||||
////
|
||||
//// Permission is hereby granted, free of charge, to any person obtaining
|
||||
//// a copy of this software and associated documentation files (the
|
||||
//// "Software"), to deal in the Software without restriction, including
|
||||
//// without limitation the rights to use, copy, modify, merge, publish,
|
||||
//// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
//// permit persons to whom the Software is furnished to do so, subject to
|
||||
//// the following conditions:
|
||||
////
|
||||
//// The above copyright notice and this permission notice shall be
|
||||
//// included in all copies or substantial portions of the Software.
|
||||
////
|
||||
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
//// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
//// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
//// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
//// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
//// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
//// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//// ************************************************************************/
|
||||
//#endregion
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
|
||||
//using FluentValidation;
|
||||
|
||||
//using Moq;
|
||||
|
||||
//using Nancy;
|
||||
//using Nancy.Testing;
|
||||
//using Nancy.Validation;
|
||||
//using Nancy.Validation.FluentValidation;
|
||||
|
||||
//using Newtonsoft.Json;
|
||||
|
||||
//using NUnit.Framework;
|
||||
//using NUnit.Framework.Constraints;
|
||||
//using PlexRequests.Core;
|
||||
//using PlexRequests.Core.SettingModels;
|
||||
//using PlexRequests.Store;
|
||||
//using PlexRequests.Store.Repository;
|
||||
//using PlexRequests.UI.Models;
|
||||
//using PlexRequests.UI.Modules;
|
||||
//using PlexRequests.UI.Validators;
|
||||
|
||||
//using Ploeh.AutoFixture;
|
||||
|
||||
//namespace PlexRequests.UI.Tests
|
||||
//{
|
||||
// [TestFixture]
|
||||
// public class ApiModuleTests
|
||||
// {
|
||||
// private ConfigurableBootstrapper Bootstrapper { get; set; }
|
||||
|
||||
// [SetUp]
|
||||
// public void Setup()
|
||||
// {
|
||||
// var fixture = new Fixture();
|
||||
// var requests = fixture.CreateMany<RequestedModel>();
|
||||
// var requestMock = new Mock<IRequestService>();
|
||||
// var settingsMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
||||
// var userRepoMock = new Mock<IRepository<UsersModel>>();
|
||||
// var mapperMock = new Mock<ICustomUserMapper>();
|
||||
// var authSettingsMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
||||
// var plexSettingsMock = new Mock<ISettingsService<PlexSettings>>();
|
||||
// var cpMock = new Mock<ISettingsService<CouchPotatoSettings>>();
|
||||
// var sonarrMock = new Mock<ISettingsService<SonarrSettings>>();
|
||||
// var sickRageMock = new Mock<ISettingsService<SickRageSettings>>();
|
||||
// var headphonesMock = new Mock<ISettingsService<HeadphonesSettings>>();
|
||||
|
||||
// var userModels = fixture.CreateMany<UsersModel>().ToList();
|
||||
// userModels.Add(new UsersModel
|
||||
// {
|
||||
// UserName = "user1"
|
||||
// });
|
||||
|
||||
// settingsMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings { ApiKey = "api" });
|
||||
// requestMock.Setup(x => x.GetAll()).Returns(requests);
|
||||
// requestMock.Setup(x => x.Get(1)).Returns(requests.FirstOrDefault());
|
||||
// requestMock.Setup(x => x.Get(99)).Returns(new RequestedModel());
|
||||
// requestMock.Setup(x => x.DeleteRequest(It.IsAny<RequestedModel>()));
|
||||
|
||||
// userRepoMock.Setup(x => x.GetAll()).Returns(userModels);
|
||||
// userRepoMock.Setup(x => x.Update(It.IsAny<UsersModel>())).Returns(true);
|
||||
|
||||
// mapperMock.Setup(x => x.ValidateUser("user1", It.IsAny<string>())).Returns(Guid.NewGuid());
|
||||
// mapperMock.Setup(x => x.UpdatePassword("user1", "password", "newpassword")).Returns(true);
|
||||
|
||||
// authSettingsMock.Setup(x => x.SaveSettings(It.Is<AuthenticationSettings>(c => c.PlexAuthToken.Equals("abc")))).Returns(true);
|
||||
|
||||
// plexSettingsMock.Setup(x => x.GetSettings()).Returns(fixture.Create<PlexSettings>());
|
||||
// plexSettingsMock.Setup(x => x.SaveSettings(It.Is<PlexSettings>(c => c.Ip.Equals("192")))).Returns(true);
|
||||
|
||||
// cpMock.Setup(x => x.GetSettings()).Returns(fixture.Create<CouchPotatoSettings>());
|
||||
// cpMock.Setup(x => x.SaveSettings(It.Is<CouchPotatoSettings>(c => c.Ip.Equals("192")))).Returns(true);
|
||||
|
||||
// sonarrMock.Setup(x => x.GetSettings()).Returns(fixture.Create<SonarrSettings>());
|
||||
// sonarrMock.Setup(x => x.SaveSettings(It.Is<SonarrSettings>(c => c.Ip.Equals("192")))).Returns(true);
|
||||
|
||||
// sickRageMock.Setup(x => x.GetSettings()).Returns(fixture.Create<SickRageSettings>());
|
||||
// sickRageMock.Setup(x => x.SaveSettings(It.Is<SickRageSettings>(c => c.Ip.Equals("192")))).Returns(true);
|
||||
|
||||
// headphonesMock.Setup(x => x.GetSettings()).Returns(fixture.Create<HeadphonesSettings>());
|
||||
// headphonesMock.Setup(x => x.SaveSettings(It.Is<HeadphonesSettings>(c => c.Ip.Equals("192")))).Returns(true);
|
||||
|
||||
// Bootstrapper = new ConfigurableBootstrapper(with =>
|
||||
// {
|
||||
// with.Module<ApiRequestModule>();
|
||||
// with.Module<ApiUserModule>();
|
||||
// with.Module<ApiSettingsModule>();
|
||||
|
||||
// with.Dependency(requestMock.Object);
|
||||
// with.Dependency(settingsMock.Object);
|
||||
// with.Dependency(userRepoMock.Object);
|
||||
// with.Dependency(mapperMock.Object);
|
||||
// with.Dependency(headphonesMock.Object);
|
||||
// with.Dependency(authSettingsMock.Object);
|
||||
// with.Dependency(plexSettingsMock.Object);
|
||||
// with.Dependency(cpMock.Object);
|
||||
// with.Dependency(sonarrMock.Object);
|
||||
// with.Dependency(sickRageMock.Object);
|
||||
|
||||
|
||||
// with.RootPathProvider<TestRootPathProvider>();
|
||||
// with.ModelValidatorLocator(
|
||||
// new DefaultValidatorLocator(
|
||||
// new List<IModelValidatorFactory>
|
||||
// {
|
||||
// new FluentValidationValidatorFactory(
|
||||
// new DefaultFluentAdapterFactory(new List<IFluentAdapter>()),
|
||||
// new List<IValidator> { new RequestedModelValidator(), new UserViewModelValidator(), new PlexValidator() })
|
||||
// }));
|
||||
// });
|
||||
// }
|
||||
|
||||
// private Action<BrowserContext> GetBrowser()
|
||||
// {
|
||||
// return with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// };
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void InvalidApiKey()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
|
||||
// var result = browser.Get("/api/requests", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "a");
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<List<RequestedModel>>>(result.Body.AsString());
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetAllRequests()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
|
||||
// var result = browser.Get("/api/requests", GetBrowser());
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<List<RequestedModel>>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Data.Count, Is.GreaterThan(0));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetSingleRequest()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
|
||||
// var result = browser.Get("/api/requests/1", GetBrowser());
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<List<RequestedModel>>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Data.Count, Is.EqualTo(1));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetSingleRequestThatDoesntExist()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
|
||||
// var result = browser.Get("/api/requests/99", GetBrowser());
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<List<RequestedModel>>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Data.Count, Is.EqualTo(0));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void DeleteARequest()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
|
||||
// var result = browser.Delete("/api/requests/1", GetBrowser());
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.True);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void DeleteARequestThatDoesNotExist()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
|
||||
// var result = browser.Delete("/api/requests/99", GetBrowser());
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.False);
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
|
||||
// [Test]
|
||||
// public void UpdateUsersPassword()
|
||||
// {
|
||||
// var model = new UserUpdateViewModel
|
||||
// {
|
||||
// CurrentPassword = "password",
|
||||
// NewPassword = "newpassword"
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Put("/api/credentials/user1", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Not.Null.Or.Empty);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void UpdateInvalidUsersPassword()
|
||||
// {
|
||||
// var model = new UserUpdateViewModel
|
||||
// {
|
||||
// CurrentPassword = "password",
|
||||
// NewPassword = "newpassword"
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Put("/api/credentials/user99", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Null.Or.Empty);
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void UpdateUsersInvalidPassword()
|
||||
// {
|
||||
// var model = new UserUpdateViewModel
|
||||
// {
|
||||
// CurrentPassword = "password",
|
||||
// NewPassword = "password2"
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Put("/api/credentials/user1", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Null.Or.Empty);
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void UpdateUsersWithBadModel()
|
||||
// {
|
||||
// var model = new UserUpdateViewModel
|
||||
// {
|
||||
// CurrentPassword = null,
|
||||
// NewPassword = "password2"
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Put("/api/credentials/user1", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string[]>>(result.Body.AsString());
|
||||
// Assert.That(body.Data.Length, Is.GreaterThan(0));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetApiKey()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/apikey", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.Query("username", "user1");
|
||||
// with.Query("password", "password");
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Not.Null.Or.Empty);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetApiKeyWithBadCredentials()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/apikey", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.Query("username", "user");
|
||||
// with.Query("password", "password");
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Null.Or.Empty);
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.Not.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
|
||||
// [Test]
|
||||
// public void SaveNewAuthSettings()
|
||||
// {
|
||||
// var model = new AuthenticationSettings
|
||||
// {
|
||||
// Id = 1,
|
||||
// PlexAuthToken = "abc",
|
||||
// DeniedUsers = "abc",
|
||||
// UsePassword = false,
|
||||
// UserAuthentication = true
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("api/settings/authentication", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<string>>(result.Body.AsString());
|
||||
// Assert.That(body.Data, Is.Not.Null.Or.Empty);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null.Or.Empty);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetPlexSettings()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/settings/plex", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<PlexSettings>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void SavePlexSettings()
|
||||
// {
|
||||
// var model = new PlexSettings()
|
||||
// {
|
||||
// Port = 231,
|
||||
// Ip = "192",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/plex", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(true));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
// [Test]
|
||||
// public void SaveBadPlexSettings()
|
||||
// {
|
||||
// var model = new PlexSettings
|
||||
// {
|
||||
// Ip = "q",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/plex", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(false));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings"));
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetCpSettings()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/settings/couchpotato", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<CouchPotatoSettings>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void SaveCpSettings()
|
||||
// {
|
||||
// var model = new CouchPotatoSettings
|
||||
// {
|
||||
// Port = 231,
|
||||
// Ip = "192",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/couchpotato", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(true));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
// [Test]
|
||||
// public void SaveBadCpSettings()
|
||||
// {
|
||||
// var model = new CouchPotatoSettings
|
||||
// {
|
||||
// Ip = "q",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/couchpotato", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(false));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings"));
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetSonarrSettings()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/settings/sonarr", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<SonarrSettings>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void SaveSonarrSettings()
|
||||
// {
|
||||
// var model = new SonarrSettings
|
||||
// {
|
||||
// Port = 231,
|
||||
// Ip = "192",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/sonarr", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(true));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
// [Test]
|
||||
// public void SaveBadSonarrSettings()
|
||||
// {
|
||||
// var model = new SonarrSettings
|
||||
// {
|
||||
// Ip = "q",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/sonarr", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(false));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings"));
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetSickRageSettings()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/settings/sickrage", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<SickRageSettings>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void SaveSickRageSettings()
|
||||
// {
|
||||
// var model = new SickRageSettings
|
||||
// {
|
||||
// Port = 231,
|
||||
// Ip = "192",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/sickrage", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(true));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
// [Test]
|
||||
// public void SaveBadSickRageSettings()
|
||||
// {
|
||||
// var model = new SickRageSettings
|
||||
// {
|
||||
// Ip = "q",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/sickrage", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(false));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings"));
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void GetHeadphonesSettings()
|
||||
// {
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Get("/api/settings/headphones", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<HeadphonesSettings>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.Not.Null);
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
|
||||
// [Test]
|
||||
// public void SaveHeadphonesSettings()
|
||||
// {
|
||||
// var model = new HeadphonesSettings
|
||||
// {
|
||||
// Port = 231,
|
||||
// Ip = "192",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/headphones", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(true));
|
||||
// Assert.That(body.Error, Is.False);
|
||||
// Assert.That(body.ErrorMessage, Is.Null);
|
||||
// }
|
||||
// [Test]
|
||||
// public void SaveBadHeadphonesSettings()
|
||||
// {
|
||||
// var model = new HeadphonesSettings
|
||||
// {
|
||||
// Ip = "q",
|
||||
// Ssl = true,
|
||||
// };
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("/api/settings/headphones", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// Assert.That(body.Data, Is.EqualTo(false));
|
||||
// Assert.That(body.Error, Is.True);
|
||||
// Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings"));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// [TestCaseSource(nameof(AuthSettingsData))]
|
||||
// public object SaveNewAuthSettings(object model)
|
||||
// {
|
||||
|
||||
// var browser = new Browser(Bootstrapper);
|
||||
// var result = browser.Post("api/settings/authentication", with =>
|
||||
// {
|
||||
// with.HttpRequest();
|
||||
// with.Header("Accept", "application/json");
|
||||
// with.Query("apikey", "api");
|
||||
// with.JsonBody(model);
|
||||
// });
|
||||
|
||||
// Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
|
||||
// var body = JsonConvert.DeserializeObject<ApiModel<bool>>(result.Body.AsString());
|
||||
|
||||
// var retVal = new List<string> { body.ErrorMessage, body.Error.ToString(), body.Data.ToString() };
|
||||
// return retVal;
|
||||
// }
|
||||
|
||||
// private static IEnumerable<TestCaseData> AuthSettingsData
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// yield return
|
||||
// new TestCaseData(new AuthenticationSettings { Id = 1, PlexAuthToken = "abc", DeniedUsers = "abc", UsePassword = false, UserAuthentication = true })
|
||||
// .Returns(new List<string> { null, false.ToString(), true.ToString() });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
45
Ombi.UI.Tests/BootstrapperExtensions.cs
Normal file
45
Ombi.UI.Tests/BootstrapperExtensions.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: BootstrapperExtensions.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Session;
|
||||
|
||||
namespace Ombi.UI.Tests
|
||||
{
|
||||
public static class BootstrapperExtensions
|
||||
{
|
||||
public static void WithSession(this IPipelines pipeline, IDictionary<string, object> session)
|
||||
{
|
||||
pipeline.BeforeRequest.AddItemToEndOfPipeline(ctx =>
|
||||
{
|
||||
ctx.Request.Session = new Session(session);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
56
Ombi.UI.Tests/LandingPageTests.cs
Normal file
56
Ombi.UI.Tests/LandingPageTests.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: LandingPageTests.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Ombi.UI.Models;
|
||||
|
||||
namespace Ombi.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class LandingPageTests
|
||||
{
|
||||
[TestCaseSource(nameof(NoticeEnabledData))]
|
||||
public bool TestNoticeEnabled(DateTime start, DateTime end)
|
||||
{
|
||||
return new LandingPageViewModel { NoticeEnd = end, NoticeStart = start }.NoticeActive;
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> NoticeEnabledData
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData(DateTime.Now, DateTime.Now.AddDays(1)).Returns(true);
|
||||
yield return new TestCaseData(DateTime.Now, DateTime.Now.AddDays(99)).Returns(true);
|
||||
yield return new TestCaseData(DateTime.Now.AddDays(2), DateTime.Now).Returns(false); // End in past
|
||||
yield return new TestCaseData(DateTime.Now.AddDays(2), DateTime.Now.AddDays(3)).Returns(false); // Not started yet
|
||||
yield return new TestCaseData(DateTime.Now.AddDays(-5), DateTime.Now.AddDays(-1)).Returns(false); // Finished yesterday
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
184
Ombi.UI.Tests/Ombi.UI.Tests.csproj
Normal file
184
Ombi.UI.Tests/Ombi.UI.Tests.csproj
Normal file
|
@ -0,0 +1,184 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A930E2CF-79E2-45F9-B06A-9A719A254CE4}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Ombi.UI.Tests</RootNamespace>
|
||||
<AssemblyName>Ombi.UI.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CsQuery, Version=1.3.3.5, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\CsQuery.1.3.3\lib\net40\CsQuery.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FluentValidation, Version=6.2.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentValidation.6.2.1.0\lib\Net45\FluentValidation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Nancy, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.1.4.3\lib\net40\Nancy.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Linker, Version=0.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.Linker.0.3.1\lib\net40-Client\Nancy.Linker.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Testing, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.Testing.1.4.1\lib\net40\Nancy.Testing.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Validation.FluentValidation, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.Validation.FluentValidation.1.4.1\lib\net40\Nancy.Validation.FluentValidation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.ViewEngines.Razor, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.Viewengines.Razor.1.4.3\lib\net40\Nancy.ViewEngines.Razor.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Ploeh.AutoFixture, Version=3.49.1.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AutoFixture.3.49.1\lib\net40\Ploeh.AutoFixture.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise />
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApiModuleTests.cs" />
|
||||
<Compile Include="BootstrapperExtensions.cs" />
|
||||
<Compile Include="LandingPageTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SearchModuleTests.cs" />
|
||||
<Compile Include="TestRootPathProvider.cs" />
|
||||
<Compile Include="TvSenderTests.cs" />
|
||||
<Compile Include="UserLoginModuleTests.cs" />
|
||||
<Compile Include="AdminModuleTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api.Interfaces\Ombi.Api.Interfaces.csproj">
|
||||
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
|
||||
<Name>Ombi.Api.Interfaces</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Api.Models\Ombi.Api.Models.csproj">
|
||||
<Project>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</Project>
|
||||
<Name>Ombi.Api.Models</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj">
|
||||
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
||||
<Name>Ombi.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Helpers\Ombi.Helpers.csproj">
|
||||
<Project>{1252336d-42a3-482a-804c-836e60173dfa}</Project>
|
||||
<Name>Ombi.Helpers</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Services\Ombi.Services.csproj">
|
||||
<Project>{566EFA49-68F8-4716-9693-A6B3F2624DEA}</Project>
|
||||
<Name>Ombi.Services</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Store\Ombi.Store.csproj">
|
||||
<Project>{92433867-2B7B-477B-A566-96C382427525}</Project>
|
||||
<Name>Ombi.Store</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.UI\Ombi.UI.csproj">
|
||||
<Project>{68F5F5F3-B8BB-4911-875F-6F00AAE04EA6}</Project>
|
||||
<Name>Ombi.UI</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets" Condition="Exists('..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
36
Ombi.UI.Tests/Properties/AssemblyInfo.cs
Normal file
36
Ombi.UI.Tests/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Ombi.UI.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Ombi.UI.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a930e2cf-79e2-45f9-b06a-9a719a254ce4")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
167
Ombi.UI.Tests/SearchModuleTests.cs
Normal file
167
Ombi.UI.Tests/SearchModuleTests.cs
Normal file
|
@ -0,0 +1,167 @@
|
|||
//#region Copyright
|
||||
//// /************************************************************************
|
||||
//// Copyright (c) 2016 Jamie Rees
|
||||
//// File: SearchModuleTests.cs
|
||||
//// Created By: Jamie Rees
|
||||
////
|
||||
//// Permission is hereby granted, free of charge, to any person obtaining
|
||||
//// a copy of this software and associated documentation files (the
|
||||
//// "Software"), to deal in the Software without restriction, including
|
||||
//// without limitation the rights to use, copy, modify, merge, publish,
|
||||
//// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
//// permit persons to whom the Software is furnished to do so, subject to
|
||||
//// the following conditions:
|
||||
////
|
||||
//// The above copyright notice and this permission notice shall be
|
||||
//// included in all copies or substantial portions of the Software.
|
||||
////
|
||||
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
//// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
//// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
//// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
//// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
//// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
//// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//// ************************************************************************/
|
||||
//#endregion
|
||||
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using Moq;
|
||||
//using NUnit.Framework;
|
||||
//using PlexRequests.Api.Interfaces;
|
||||
//using PlexRequests.Api.Models.Plex;
|
||||
//using PlexRequests.Core;
|
||||
//using PlexRequests.Core.Queue;
|
||||
//using PlexRequests.Core.SettingModels;
|
||||
//using PlexRequests.Helpers;
|
||||
//using PlexRequests.Helpers.Analytics;
|
||||
//using PlexRequests.Services.Interfaces;
|
||||
//using PlexRequests.Services.Jobs;
|
||||
//using PlexRequests.Store;
|
||||
//using PlexRequests.Store.Models;
|
||||
//using PlexRequests.Store.Repository;
|
||||
//using PlexRequests.UI.Modules;
|
||||
//using Ploeh.AutoFixture;
|
||||
|
||||
//namespace PlexRequests.UI.Tests
|
||||
//{
|
||||
// [TestFixture]
|
||||
// public class SearchModuleTests
|
||||
// {
|
||||
// private Mock<ISettingsService<HeadphonesSettings>> _headphonesSettings;
|
||||
// private Mock<INotificationService> _notificationService;
|
||||
// private Mock<ISettingsService<SickRageSettings>> _sickRageSettingsMock;
|
||||
// private Mock<ICouchPotatoApi> _cpApi;
|
||||
// private Mock<ISettingsService<SonarrSettings>> _sonarrSettingsMock;
|
||||
// private Mock<ISonarrApi> _sonarrApiMock;
|
||||
// private Mock<ISettingsService<PlexSettings>> _plexSettingsMock;
|
||||
// private Mock<ISettingsService<CouchPotatoSettings>> _cpMock;
|
||||
// private Mock<ISettingsService<PlexRequestSettings>> _plexRequestMock;
|
||||
// private Mock<ISettingsService<AuthenticationSettings>> _authMock;
|
||||
// private Mock<IAnalytics> _analytics;
|
||||
// private Mock<IAvailabilityChecker> _availabilityMock;
|
||||
// private Mock<IRequestService> _rServiceMock;
|
||||
// private Mock<ISickRageApi> _srApi;
|
||||
// private Mock<IMusicBrainzApi> _music;
|
||||
// private Mock<IHeadphonesApi> _hpAPi;
|
||||
// private Mock<ICouchPotatoCacher> _cpCache;
|
||||
// private Mock<ISonarrCacher> _sonarrCache;
|
||||
// private Mock<ISickRageCacher> _srCache;
|
||||
// private Mock<IPlexApi> _plexApi;
|
||||
// private Mock<IRepository<UsersToNotify>> _userRepo;
|
||||
// private Mock<ISettingsService<EmailNotificationSettings>> _emailSettings;
|
||||
// private Mock<IIssueService> _issueService;
|
||||
// private Mock<ICacheProvider> _cache;
|
||||
// private Mock<ITransientFaultQueue> _faultQueue;
|
||||
// private Mock<IRepository<RequestLimit>> RequestLimitRepo { get; set; }
|
||||
// private SearchModule Search { get; set; }
|
||||
// private readonly Fixture F = new Fixture();
|
||||
|
||||
// [Test]
|
||||
// public void CheckNoRequestLimitTest()
|
||||
// {
|
||||
// var settings = new PlexRequestSettings { AlbumWeeklyRequestLimit = 0, MovieWeeklyRequestLimit = 2, TvWeeklyRequestLimit = 0 };
|
||||
// var result = Search.CheckRequestLimit(settings, RequestType.Movie).Result;
|
||||
|
||||
// Assert.That(result, Is.True);
|
||||
// RequestLimitRepo.Verify(x => x.GetAllAsync(), Times.Once);
|
||||
// }
|
||||
|
||||
// [TestCaseSource(nameof(MovieLimitData))]
|
||||
// public bool CheckMovieLimitTest(int requestCount)
|
||||
// {
|
||||
// var users = F.CreateMany<RequestLimit>().ToList();
|
||||
// users.Add(new RequestLimit { Username = "", RequestCount = requestCount, RequestType = RequestType.Movie});
|
||||
// RequestLimitRepo.Setup(x => x.GetAllAsync()).ReturnsAsync(users);
|
||||
// var settings = new PlexRequestSettings { AlbumWeeklyRequestLimit = 0, MovieWeeklyRequestLimit = 5, TvWeeklyRequestLimit = 0 };
|
||||
// var result = Search.CheckRequestLimit(settings, RequestType.Movie).Result;
|
||||
|
||||
// RequestLimitRepo.Verify(x => x.GetAllAsync(), Times.Once);
|
||||
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// private static IEnumerable<TestCaseData> MovieLimitData
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// yield return new TestCaseData(1).Returns(true).SetName("1 Request of 5");
|
||||
// yield return new TestCaseData(2).Returns(true).SetName("2 Request of 5");
|
||||
// yield return new TestCaseData(3).Returns(true).SetName("3 Request of 5");
|
||||
// yield return new TestCaseData(4).Returns(true).SetName("4 Request of 5");
|
||||
// yield return new TestCaseData(5).Returns(false).SetName("5 Request of 5");
|
||||
// yield return new TestCaseData(6).Returns(false).SetName("6 Request of 5");
|
||||
// yield return new TestCaseData(0).Returns(true).SetName("0 Request of 5");
|
||||
// }
|
||||
// }
|
||||
|
||||
// [SetUp]
|
||||
// public void Setup()
|
||||
// {
|
||||
// _authMock = new Mock<Core.ISettingsService<AuthenticationSettings>>();
|
||||
// _plexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
||||
// _plexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
|
||||
// _cpMock = new Mock<Core.ISettingsService<CouchPotatoSettings>>();
|
||||
// _plexSettingsMock = new Mock<Core.ISettingsService<PlexSettings>>();
|
||||
// _sonarrApiMock = new Mock<ISonarrApi>();
|
||||
// _sonarrSettingsMock = new Mock<Core.ISettingsService<SonarrSettings>>();
|
||||
// _cpApi = new Mock<ICouchPotatoApi>();
|
||||
// _sickRageSettingsMock = new Mock<Core.ISettingsService<SickRageSettings>>();
|
||||
// _notificationService = new Mock<INotificationService>();
|
||||
// _headphonesSettings = new Mock<Core.ISettingsService<HeadphonesSettings>>();
|
||||
// _cache = new Mock<ICacheProvider>();
|
||||
|
||||
// _analytics = new Mock<IAnalytics>();
|
||||
// _availabilityMock = new Mock<IAvailabilityChecker>();
|
||||
// _rServiceMock = new Mock<IRequestService>();
|
||||
// _srApi = new Mock<ISickRageApi>();
|
||||
// _music = new Mock<IMusicBrainzApi>();
|
||||
// _hpAPi = new Mock<IHeadphonesApi>();
|
||||
// _cpCache = new Mock<ICouchPotatoCacher>();
|
||||
// _sonarrCache = new Mock<ISonarrCacher>();
|
||||
// _srCache = new Mock<ISickRageCacher>();
|
||||
// _plexApi = new Mock<IPlexApi>();
|
||||
// _userRepo = new Mock<IRepository<UsersToNotify>>();
|
||||
// RequestLimitRepo = new Mock<IRepository<RequestLimit>>();
|
||||
// _emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
|
||||
// _issueService = new Mock<IIssueService>();
|
||||
// _faultQueue = new Mock<ITransientFaultQueue>();
|
||||
// CreateModule();
|
||||
// }
|
||||
|
||||
// private void CreateModule()
|
||||
// {
|
||||
// Search = new SearchModule(_cache.Object, _cpMock.Object, _plexRequestMock.Object, _availabilityMock.Object,
|
||||
// _rServiceMock.Object, _sonarrApiMock.Object, _sonarrSettingsMock.Object,
|
||||
// _sickRageSettingsMock.Object, _cpApi.Object, _srApi.Object, _notificationService.Object,
|
||||
// _music.Object, _hpAPi.Object, _headphonesSettings.Object, _cpCache.Object, _sonarrCache.Object,
|
||||
// _srCache.Object, _plexApi.Object, _plexSettingsMock.Object, _authMock.Object,
|
||||
// _userRepo.Object, _emailSettings.Object, _issueService.Object, _analytics.Object, RequestLimitRepo.Object, _faultQueue.Object);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// }
|
||||
//}
|
64
Ombi.UI.Tests/TestRootPathProvider.cs
Normal file
64
Ombi.UI.Tests/TestRootPathProvider.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: TestRootPathProvider.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
|
||||
namespace Ombi.UI.Tests
|
||||
{
|
||||
public class TestRootPathProvider : IRootPathProvider
|
||||
{
|
||||
private static string _CachedRootPath;
|
||||
|
||||
public string GetRootPath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_CachedRootPath))
|
||||
return _CachedRootPath;
|
||||
|
||||
var currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
|
||||
|
||||
bool rootPathFound = false;
|
||||
while (!rootPathFound)
|
||||
{
|
||||
var directoriesContainingViewFolder = currentDirectory.GetDirectories(
|
||||
"Views", SearchOption.AllDirectories);
|
||||
if (directoriesContainingViewFolder.Any())
|
||||
{
|
||||
_CachedRootPath = directoriesContainingViewFolder.First().FullName;
|
||||
rootPathFound = true;
|
||||
}
|
||||
|
||||
currentDirectory = currentDirectory.Parent;
|
||||
}
|
||||
|
||||
return _CachedRootPath;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
159
Ombi.UI.Tests/TvSenderTests.cs
Normal file
159
Ombi.UI.Tests/TvSenderTests.cs
Normal file
|
@ -0,0 +1,159 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: TvSenderTests.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Sonarr;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Store;
|
||||
using Ploeh.AutoFixture;
|
||||
|
||||
namespace Ombi.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TvSenderTests
|
||||
{
|
||||
|
||||
private Mock<ISonarrApi> SonarrMock { get; set; }
|
||||
private Mock<ISickRageApi> SickrageMock { get; set; }
|
||||
|
||||
private TvSender Sender { get; set; }
|
||||
private Fixture F { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
F = new Fixture();
|
||||
SonarrMock = new Mock<ISonarrApi>();
|
||||
SickrageMock = new Mock<ISickRageApi>();
|
||||
Sender = new TvSender(SonarrMock.Object, SickrageMock.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Needs work")]
|
||||
public async Task HappyPathSendSeriesToSonarrAllSeason()
|
||||
{
|
||||
var seriesResult = new SonarrAddSeries() { title = "ABC"};
|
||||
SonarrMock.Setup(x => x.GetSeries(It.IsAny<string>(), It.IsAny<Uri>())).Returns(F.Build<Series>().With(x => x.tvdbId, 1).With(x => x.title, "ABC").CreateMany().ToList());
|
||||
|
||||
Sender = new TvSender(SonarrMock.Object, SickrageMock.Object);
|
||||
|
||||
var request = new RequestedModel {SeasonsRequested = "All", ProviderId = 1, Title = "ABC"};
|
||||
|
||||
var result = await Sender.SendToSonarr(GetSonarrSettings(), request);
|
||||
|
||||
Assert.That(result.title, Is.EqualTo("ABC"));
|
||||
SonarrMock.Verify(x => x.AddSeries(It.IsAny<int>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<int[]>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<Uri>(),
|
||||
true, It.IsAny<bool>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Needs rework")]
|
||||
public async Task HappyPathSendEpisodeWithExistingSeriesToSonarr()
|
||||
{
|
||||
var seriesResult = new SonarrAddSeries { monitored = true, title = "TitleReturned" };
|
||||
var selectedSeries = F.Build<Series>().With(x => x.tvdbId, 1).CreateMany();
|
||||
SonarrMock.Setup(x => x.GetSeries(It.IsAny<string>(), It.IsAny<Uri>())).Returns(selectedSeries.ToList());
|
||||
SonarrMock.Setup(x => x.AddSeries(
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<int[]>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<Uri>(),
|
||||
It.IsAny<bool>(), It.IsAny<bool>())).Returns(seriesResult);
|
||||
var sonarrEpisodes = new SonarrEpisodes()
|
||||
{
|
||||
title = "abc",
|
||||
seasonNumber = 2,
|
||||
episodeNumber = 1,
|
||||
monitored = false
|
||||
};
|
||||
var episodesList = F.CreateMany<SonarrEpisodes>().ToList();
|
||||
episodesList.Add(sonarrEpisodes);
|
||||
|
||||
SonarrMock.Setup(x => x.GetEpisodes(It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>())).Returns(F.CreateMany<SonarrEpisodes>());
|
||||
|
||||
Sender = new TvSender(SonarrMock.Object, SickrageMock.Object);
|
||||
var episodes = new List<EpisodesModel>
|
||||
{
|
||||
new EpisodesModel
|
||||
{
|
||||
EpisodeNumber = 1,
|
||||
SeasonNumber = 2
|
||||
}
|
||||
};
|
||||
var model = F.Build<RequestedModel>().With(x => x.ProviderId, 1)
|
||||
.With(x => x.Episodes, episodes).Create();
|
||||
|
||||
var result = await Sender.SendToSonarr(GetSonarrSettings(), model, "2");
|
||||
|
||||
Assert.That(result, Is.EqualTo(seriesResult));
|
||||
SonarrMock.Verify(x => x.AddSeries(It.IsAny<int>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<int[]>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<Uri>(),
|
||||
true, It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
private SonarrSettings GetSonarrSettings()
|
||||
{
|
||||
var sonarrSettings = new SonarrSettings
|
||||
{
|
||||
ApiKey = "abc",
|
||||
Enabled = true,
|
||||
Ip = "192.168.1.1",
|
||||
Port = 8989,
|
||||
};
|
||||
return sonarrSettings;
|
||||
}
|
||||
}
|
||||
}
|
491
Ombi.UI.Tests/UserLoginModuleTests.cs
Normal file
491
Ombi.UI.Tests/UserLoginModuleTests.cs
Normal file
|
@ -0,0 +1,491 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: UserLoginModuleTests.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Nancy;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Testing;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Plex;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Helpers.Analytics;
|
||||
using Ombi.UI.Modules;
|
||||
|
||||
namespace Ombi.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserLoginModuleTests
|
||||
{
|
||||
private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
|
||||
private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
|
||||
private Mock<ISettingsService<LandingPageSettings>> LandingPageMock { get; set; }
|
||||
private Mock<ISettingsService<PlexSettings>> PlexSettingsMock { get; set; }
|
||||
private ConfigurableBootstrapper Bootstrapper { get; set; }
|
||||
private Mock<IPlexApi> PlexMock { get; set; }
|
||||
private Mock<IAnalytics> IAnalytics { get; set; }
|
||||
private Mock<IResourceLinker> Linker { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
AuthMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
||||
PlexMock = new Mock<IPlexApi>();
|
||||
LandingPageMock = new Mock<ISettingsService<LandingPageSettings>>();
|
||||
PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
||||
PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
|
||||
PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings()));
|
||||
LandingPageMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new LandingPageSettings());
|
||||
IAnalytics = new Mock<IAnalytics>();
|
||||
Linker = new Mock<IResourceLinker>();
|
||||
Linker.Setup(x => x.BuildRelativeUri(It.IsAny<NancyContext>(), "SearchIndex", null)).Returns(new Uri("http://www.searchindex.com"));
|
||||
Linker.Setup(x => x.BuildRelativeUri(It.IsAny<NancyContext>(), "LandingPageIndex", null)).Returns(new Uri("http://www.landingpage.com"));
|
||||
Linker.Setup(x => x.BuildRelativeUri(It.IsAny<NancyContext>(), "UserLoginIndex", null)).Returns(new Uri("http://www.userloginindex.com"));
|
||||
PlexSettingsMock = new Mock<ISettingsService<PlexSettings>>();
|
||||
PlexSettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings() {PlexAuthToken = "abc"});
|
||||
Bootstrapper = new ConfigurableBootstrapper(with =>
|
||||
{
|
||||
with.Module<UserLoginModule>();
|
||||
with.Dependency(PlexRequestMock.Object);
|
||||
with.Dependency(AuthMock.Object);
|
||||
with.Dependency(PlexMock.Object);
|
||||
with.Dependency(LandingPageMock.Object);
|
||||
with.Dependency(IAnalytics.Object);
|
||||
with.Dependency(Linker.Object);
|
||||
with.Dependency(PlexSettingsMock.Object);
|
||||
with.RootPathProvider<TestRootPathProvider>();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithoutAuthentication()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithoutAuthenticationWithEmptyUsername()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = false };
|
||||
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", string.Empty);
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
||||
|
||||
|
||||
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
|
||||
AuthMock.Verify(x => x.GetSettingsAsync(), 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithUsernameSuccessfully()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = true };
|
||||
var plexFriends = new PlexFriends
|
||||
{
|
||||
User = new[]
|
||||
{
|
||||
new UserFriends
|
||||
{
|
||||
Title = "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());
|
||||
|
||||
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.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithUsernameUnSuccessfully()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = true };
|
||||
var plexFriends = new PlexFriends
|
||||
{
|
||||
User = new[]
|
||||
{
|
||||
new UserFriends
|
||||
{
|
||||
Username = "aaaa",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
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());
|
||||
|
||||
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.Null);
|
||||
|
||||
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.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.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithUsernameAndPasswordSuccessfully()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true };
|
||||
var plexFriends = new PlexFriends
|
||||
{
|
||||
User = new[]
|
||||
{
|
||||
new UserFriends
|
||||
{
|
||||
Title = "abc",
|
||||
}
|
||||
}
|
||||
};
|
||||
var plexAuth = new PlexAuthentication
|
||||
{
|
||||
user = new User
|
||||
{
|
||||
authentication_token = "abc"
|
||||
}
|
||||
};
|
||||
|
||||
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(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());
|
||||
|
||||
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");
|
||||
with.FormValue("Password", "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.Once);
|
||||
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithUsernameAndPasswordUnSuccessfully()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true };
|
||||
var plexFriends = new PlexFriends
|
||||
{
|
||||
User = new[]
|
||||
{
|
||||
new UserFriends
|
||||
{
|
||||
Username = "abc",
|
||||
},
|
||||
}
|
||||
};
|
||||
var plexAuth = new PlexAuthentication
|
||||
{
|
||||
user = null
|
||||
};
|
||||
|
||||
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
|
||||
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(plexFriends);
|
||||
PlexMock.Setup(x => x.SignIn(It.IsAny<string>(), It.IsAny<string>())).Returns(plexAuth);
|
||||
|
||||
|
||||
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");
|
||||
with.FormValue("Password", "abc");
|
||||
});
|
||||
|
||||
|
||||
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
||||
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
|
||||
AuthMock.Verify(x => x.GetSettingsAsync(), 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AttemptToLoginAsDeniedUser()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = false, DeniedUsers = "abc" };
|
||||
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.Null);
|
||||
|
||||
Assert.That(result.Headers.Contains(new KeyValuePair<string, string>("Location", "http://www.userloginindex.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]
|
||||
public void Logout()
|
||||
{
|
||||
Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } });
|
||||
|
||||
var browser = new Browser(Bootstrapper);
|
||||
var result = browser.Get("/userlogin/logout", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
||||
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithOwnerUsernameSuccessfully()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = true };
|
||||
var plexFriends = new PlexFriends
|
||||
{
|
||||
User = new[]
|
||||
{
|
||||
new UserFriends()
|
||||
}
|
||||
};
|
||||
|
||||
var account = new PlexAccount { Username = "Jamie" };
|
||||
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(account);
|
||||
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>());
|
||||
|
||||
var browser = new Browser(Bootstrapper);
|
||||
var result = browser.Post("/userlogin", with =>
|
||||
{
|
||||
with.HttpRequest();
|
||||
with.Header("Accept", "application/json");
|
||||
with.FormValue("Username", "Jamie");
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
||||
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("Jamie"));
|
||||
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.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoginWithOwnerUsernameAndPasswordSuccessfully()
|
||||
{
|
||||
var expectedSettings = new AuthenticationSettings { UserAuthentication = true, UsePassword = true };
|
||||
var plexFriends = new PlexFriends
|
||||
{
|
||||
User = new[]
|
||||
{
|
||||
new UserFriends()
|
||||
}
|
||||
};
|
||||
var plexAuth = new PlexAuthentication
|
||||
{
|
||||
user = new User
|
||||
{
|
||||
authentication_token = "abc",
|
||||
username = "Jamie"
|
||||
}
|
||||
};
|
||||
|
||||
var account = new PlexAccount { Username = "Jamie" };
|
||||
|
||||
AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(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(account);
|
||||
|
||||
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", "jamie");
|
||||
with.FormValue("Password", "abc");
|
||||
});
|
||||
|
||||
Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
|
||||
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.Once);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
40
Ombi.UI.Tests/app.config
Normal file
40
Ombi.UI.Tests/app.config
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="MiniProfiler" publicKeyToken="b44f9351044011a3" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.10.0" newVersion="3.0.10.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<appSettings>
|
||||
<add key="webPages:Enabled" value="false" />
|
||||
</appSettings><system.web.webPages.razor>
|
||||
<pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">
|
||||
<namespaces>
|
||||
<add namespace="Nancy.ViewEngines.Razor" />
|
||||
</namespaces>
|
||||
</pages>
|
||||
</system.web.webPages.razor></configuration>
|
16
Ombi.UI.Tests/packages.config
Normal file
16
Ombi.UI.Tests/packages.config
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoFixture" version="3.49.1" targetFramework="net46" />
|
||||
<package id="CsQuery" version="1.3.3" targetFramework="net46" />
|
||||
<package id="FluentValidation" version="6.2.1.0" targetFramework="net46" />
|
||||
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net46" />
|
||||
<package id="Moq" version="4.2.1510.2205" targetFramework="net452" />
|
||||
<package id="Nancy" version="1.4.3" targetFramework="net46" />
|
||||
<package id="Nancy.Linker" version="0.3.1" targetFramework="net46" />
|
||||
<package id="Nancy.Testing" version="1.4.1" targetFramework="net46" />
|
||||
<package id="Nancy.Validation.FluentValidation" version="1.4.1" targetFramework="net46" />
|
||||
<package id="Nancy.Viewengines.Razor" version="1.4.3" targetFramework="net46" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
|
||||
<package id="NUnit" version="3.4.1" targetFramework="net46" />
|
||||
<package id="Owin" version="1.0" targetFramework="net46" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue