revert branch to 664dae2

pull/332/head
tidusjar 8 years ago
parent 14ca513555
commit f30bc103ed

@ -1,149 +0,0 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IssuesModuleTests.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 System.Linq;
using System.Threading.Tasks;
using Moq;
using Nancy;
using Nancy.Testing;
using Newtonsoft.Json;
using NUnit.Framework;
using PlexRequests.Core;
using PlexRequests.Core.Models;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Services.Interfaces;
using PlexRequests.UI.Models;
using PlexRequests.UI.Modules;
using Ploeh.AutoFixture;
namespace PlexRequests.UI.Tests
{
[TestFixture]
public class IssuesModuleTests
{
[SetUp]
public void Setup()
{
var f = new Fixture();
ModelList = f.CreateMany<IssuesModel>();
PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings()));
IssueServiceMock = new Mock<IIssueService>();
RequestServiceMock = new Mock<IRequestService>();
NotificationServiceMock = new Mock<INotificationService>();
IssueServiceMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(ModelList));
Bootstrapper = new ConfigurableBootstrapper(
with =>
{
with.Module<IssuesModule>();
with.Dependency(PlexRequestMock.Object);
with.Dependency(IssueServiceMock.Object);
with.Dependency(RequestServiceMock.Object);
with.Dependency(NotificationServiceMock.Object);
with.RootPathProvider<TestRootPathProvider>();
});
Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } });
}
private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
private Mock<IIssueService> IssueServiceMock { get; set; }
private Mock<IRequestService> RequestServiceMock { get; set; }
private Mock<INotificationService> NotificationServiceMock { get; set; }
private ConfigurableBootstrapper Bootstrapper { get; set; }
private IEnumerable<IssuesModel> ModelList { get; set; }
private IEnumerable<IssuesModel> NonResolvedModel => ModelList.Where(x => x.IssueStatus != IssueStatus.ResolvedIssue);
[Test]
public void GetIssuesNonAdminButAllCanSee()
{
var browser = new Browser(Bootstrapper);
var result = browser.Get(
"/issues/pending",
with =>
{
with.HttpRequest();
with.Header("Accept", "application/json");
});
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
var body = JsonConvert.DeserializeObject<List<IssuesViewModel>>(result.Body.AsString());
Assert.That(body.Count, Is.EqualTo(NonResolvedModel.Count()));
Assert.That(body[0].Title, Is.Not.Empty);
}
[Test]
public void GetIssuesForAdmin()
{
Bootstrapper = new ConfigurableBootstrapper(
with =>
{
with.Module<IssuesModule>();
with.Dependency(PlexRequestMock.Object);
with.Dependency(IssueServiceMock.Object);
with.Dependency(RequestServiceMock.Object);
with.Dependency(NotificationServiceMock.Object);
with.RootPathProvider<TestRootPathProvider>();
with.RequestStartup(
(container, pipelines, context) =>
{
context.CurrentUser = new UserIdentity() { Claims = new[] { UserClaims.Admin } };
});
});
Bootstrapper.WithSession(new Dictionary<string, object> { { SessionKeys.UsernameKey, "abc" } });
var browser = new Browser(Bootstrapper);
var result = browser.Get(
"/issues/pending",
with =>
{
with.HttpRequest();
with.Header("Accept", "application/json");
});
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));
var body = JsonConvert.DeserializeObject<List<IssuesViewModel>>(result.Body.AsString());
Assert.That(body.Count, Is.EqualTo(NonResolvedModel.Count()));
Assert.That(body[0].Title, Is.Not.Empty);
}
}
}

@ -105,7 +105,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringHelperTests.cs" />
<Compile Include="TestRootPathProvider.cs" />
<Compile Include="IssuesModuleTests.cs" />
<Compile Include="UserLoginModuleTests.cs" />
<Compile Include="AdminModuleTests.cs" />
</ItemGroup>

@ -43,6 +43,7 @@ using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Services;
using PlexRequests.Services.Interfaces;
using PlexRequests.Services.Notification;
using PlexRequests.Store;
@ -146,7 +147,7 @@ namespace PlexRequests.UI
notificationService.Subscribe(new SlackNotification(container.Resolve<ISlackApi>(), slackService));
}
}
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
//CORS Enable
@ -167,33 +168,31 @@ namespace PlexRequests.UI
container.Register<IRepository<UsersModel>, UserRepository<UsersModel>>();
container.Register<IUserMapper, UserMapper>();
container.Register<ICustomUserMapper, UserMapper>();
// Settings
container.RegisterSetting<EmailNotificationSettings>();
container.RegisterSetting<PushbulletNotificationSettings>();
container.RegisterSetting<PushoverNotificationSettings>();
container.RegisterSetting<SlackNotificationSettings>();
container.RegisterSetting<ScheduledJobsSettings>();
container.RegisterSetting<PlexRequestSettings>();
container.RegisterSetting<CouchPotatoSettings>();
container.RegisterSetting<AuthenticationSettings>();
container.RegisterSetting<PlexSettings>();
container.RegisterSetting<SonarrSettings>();
container.RegisterSetting<SickRageSettings>();
container.RegisterSetting<HeadphonesSettings>();
container.RegisterSetting<LogSettings>();
container.RegisterSetting<LandingPageSettings>();
// Repository
container.RegisterRepo<LogEntity>();
container.RegisterRepo<UsersToNotify>();
container.RegisterRepo<ScheduledJobs>();
container.RegisterRepo<IssueBlobs>();
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
container.Register<ISettingsService<PushoverNotificationSettings>, SettingsServiceV2<PushoverNotificationSettings>>();
container.Register<ISettingsService<SlackNotificationSettings>, SettingsServiceV2<SlackNotificationSettings>>();
container.Register<ISettingsService<ScheduledJobsSettings>, SettingsServiceV2<ScheduledJobsSettings>>();
// Notification Service
container.Register<INotificationService, NotificationService>().AsSingleton();
// Settings
container.Register<ISettingsService<PlexRequestSettings>, SettingsServiceV2<PlexRequestSettings>>();
container.Register<ISettingsService<CouchPotatoSettings>, SettingsServiceV2<CouchPotatoSettings>>();
container.Register<ISettingsService<AuthenticationSettings>, SettingsServiceV2<AuthenticationSettings>>();
container.Register<ISettingsService<PlexSettings>, SettingsServiceV2<PlexSettings>>();
container.Register<ISettingsService<SonarrSettings>, SettingsServiceV2<SonarrSettings>>();
container.Register<ISettingsService<SickRageSettings>, SettingsServiceV2<SickRageSettings>>();
container.Register<ISettingsService<HeadphonesSettings>, SettingsServiceV2<HeadphonesSettings>>();
container.Register<ISettingsService<LogSettings>, SettingsServiceV2<LogSettings>>();
container.Register<ISettingsService<LandingPageSettings>, SettingsServiceV2<LandingPageSettings>>();
// Repo's
container.Register<IRepository<LogEntity>, GenericRepository<LogEntity>>();
container.Register<IRepository<UsersToNotify>, GenericRepository<UsersToNotify>>();
container.Register<IRepository<ScheduledJobs>, GenericRepository<ScheduledJobs>>();
container.Register<IRepository<IssueBlobs>, GenericRepository<IssueBlobs>>();
container.Register<IRequestService, JsonRequestModelRequestService>();
container.Register<IIssueService, IssueJsonService>();
container.Register<ISettingsRepository, SettingsJsonRepository>();
@ -210,7 +209,7 @@ namespace PlexRequests.UI
container.Register<ISchedulerFactory, StdSchedulerFactory>();
container.Register<IJobScheduler, Scheduler>();
// Api
container.Register<ICouchPotatoApi, CouchPotatoApi>();
container.Register<IPushbulletApi, PushbulletApi>();

@ -1,48 +0,0 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: ContainerHelper.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 Nancy.TinyIoc;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Store;
using PlexRequests.Store.Repository;
namespace PlexRequests.UI.Helpers
{
public static class ContainerHelper
{
public static void RegisterSetting<T>(this TinyIoCContainer container) where T : Settings, new()
{
container.Register<ISettingsService<T>, SettingsServiceV2<T>>();
}
public static void RegisterRepo<T>(this TinyIoCContainer container) where T : Entity, new()
{
container.Register<IRepository<T>, GenericRepository<T>>();
}
}
}

@ -317,8 +317,6 @@ namespace PlexRequests.UI.Modules
/// Filters the issues. Checks to see if we have set <c>UsersCanViewOnlyOwnIssues</c> in the database and filters upon the user logged in and that setting.
/// </summary>
/// <param name="issues">The issues.</param>
/// <param name="showResolved">if set to <c>true</c> [show resolved].</param>
/// <returns></returns>
private async Task<IEnumerable<IssuesModel>> FilterIssuesAsync(IEnumerable<IssuesModel> issues, bool showResolved = false)
{
var settings = await PlexRequestSettings.GetSettingsAsync();

@ -159,7 +159,6 @@
<ItemGroup>
<Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\BaseUrlHelper.cs" />
<Compile Include="Helpers\ContainerHelper.cs" />
<Compile Include="Helpers\HeadphonesSender.cs" />
<Compile Include="Helpers\EmptyViewBase.cs" />
<Compile Include="Helpers\ServiceLocator.cs" />

Loading…
Cancel
Save