From f30bc103ed9242e41ffabe5936251b350ae43b3d Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 21 Jun 2016 09:01:48 +0100 Subject: [PATCH] revert branch to 664dae2 --- PlexRequests.UI.Tests/IssuesModuleTests.cs | 149 ------------------ .../PlexRequests.UI.Tests.csproj | 1 - PlexRequests.UI/Bootstrapper.cs | 51 +++--- PlexRequests.UI/Helpers/ContainerHelper.cs | 48 ------ PlexRequests.UI/Modules/IssuesModule.cs | 2 - PlexRequests.UI/PlexRequests.UI.csproj | 1 - 6 files changed, 25 insertions(+), 227 deletions(-) delete mode 100644 PlexRequests.UI.Tests/IssuesModuleTests.cs delete mode 100644 PlexRequests.UI/Helpers/ContainerHelper.cs diff --git a/PlexRequests.UI.Tests/IssuesModuleTests.cs b/PlexRequests.UI.Tests/IssuesModuleTests.cs deleted file mode 100644 index 411cebbf2..000000000 --- a/PlexRequests.UI.Tests/IssuesModuleTests.cs +++ /dev/null @@ -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(); - PlexRequestMock = new Mock>(); - PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings()); - PlexRequestMock.Setup(x => x.GetSettingsAsync()).Returns(Task.FromResult(new PlexRequestSettings())); - IssueServiceMock = new Mock(); - RequestServiceMock = new Mock(); - NotificationServiceMock = new Mock(); - IssueServiceMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(ModelList)); - - Bootstrapper = new ConfigurableBootstrapper( - with => - { - with.Module(); - with.Dependency(PlexRequestMock.Object); - with.Dependency(IssueServiceMock.Object); - with.Dependency(RequestServiceMock.Object); - with.Dependency(NotificationServiceMock.Object); - with.RootPathProvider(); - }); - - Bootstrapper.WithSession(new Dictionary { { SessionKeys.UsernameKey, "abc" } }); - } - - private Mock> PlexRequestMock { get; set; } - private Mock IssueServiceMock { get; set; } - private Mock RequestServiceMock { get; set; } - private Mock NotificationServiceMock { get; set; } - private ConfigurableBootstrapper Bootstrapper { get; set; } - private IEnumerable ModelList { get; set; } - - private IEnumerable 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>(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(); - with.Dependency(PlexRequestMock.Object); - with.Dependency(IssueServiceMock.Object); - with.Dependency(RequestServiceMock.Object); - with.Dependency(NotificationServiceMock.Object); - with.RootPathProvider(); - with.RequestStartup( - (container, pipelines, context) => - { - context.CurrentUser = new UserIdentity() { Claims = new[] { UserClaims.Admin } }; - }); - }); - - Bootstrapper.WithSession(new Dictionary { { 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>(result.Body.AsString()); - Assert.That(body.Count, Is.EqualTo(NonResolvedModel.Count())); - Assert.That(body[0].Title, Is.Not.Empty); - } - } -} \ No newline at end of file diff --git a/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj b/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj index 95ac4be3a..5ec37a74a 100644 --- a/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj +++ b/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj @@ -105,7 +105,6 @@ - diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index a43f4c8f6..176404b02 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -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(), slackService)); } } - + protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { //CORS Enable @@ -167,33 +168,31 @@ namespace PlexRequests.UI container.Register, UserRepository>(); container.Register(); container.Register(); - - // Settings - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - container.RegisterSetting(); - - // Repository - container.RegisterRepo(); - container.RegisterRepo(); - container.RegisterRepo(); - container.RegisterRepo(); - + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); // Notification Service container.Register().AsSingleton(); - + // Settings + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); + + // Repo's + container.Register, GenericRepository>(); + container.Register, GenericRepository>(); + container.Register, GenericRepository>(); + container.Register, GenericRepository>(); container.Register(); container.Register(); container.Register(); @@ -210,7 +209,7 @@ namespace PlexRequests.UI container.Register(); container.Register(); - + // Api container.Register(); container.Register(); diff --git a/PlexRequests.UI/Helpers/ContainerHelper.cs b/PlexRequests.UI/Helpers/ContainerHelper.cs deleted file mode 100644 index 85c4f7f92..000000000 --- a/PlexRequests.UI/Helpers/ContainerHelper.cs +++ /dev/null @@ -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(this TinyIoCContainer container) where T : Settings, new() - { - container.Register, SettingsServiceV2>(); - } - - public static void RegisterRepo(this TinyIoCContainer container) where T : Entity, new() - { - container.Register, GenericRepository>(); - } - } -} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/IssuesModule.cs b/PlexRequests.UI/Modules/IssuesModule.cs index 9e10ac156..82cb1d2f0 100644 --- a/PlexRequests.UI/Modules/IssuesModule.cs +++ b/PlexRequests.UI/Modules/IssuesModule.cs @@ -317,8 +317,6 @@ namespace PlexRequests.UI.Modules /// Filters the issues. Checks to see if we have set UsersCanViewOnlyOwnIssues in the database and filters upon the user logged in and that setting. /// /// The issues. - /// if set to true [show resolved]. - /// private async Task> FilterIssuesAsync(IEnumerable issues, bool showResolved = false) { var settings = await PlexRequestSettings.GetSettingsAsync(); diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 75290e3d1..99b5f8641 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -159,7 +159,6 @@ -