mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Fixed a bit of a stupid bug in the resetter and added unit tests around it to make sure this never happens again.
This commit is contained in:
parent
3563f166c9
commit
2d0b87b558
6 changed files with 507 additions and 349 deletions
|
@ -1,137 +1,137 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
Copyright (c) 2016 Jamie Rees
|
Copyright (c) 2016 Jamie Rees
|
||||||
File: NotificationServiceTests.cs
|
File: NotificationServiceTests.cs
|
||||||
Created By: Jamie Rees
|
Created By: Jamie Rees
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
"Software"), to deal in the Software without restriction, including
|
"Software"), to deal in the Software without restriction, including
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
the following conditions:
|
the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
The above copyright notice and this permission notice shall be
|
||||||
included in all copies or substantial portions of the Software.
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using PlexRequests.Services.Notification;
|
using PlexRequests.Services.Notification;
|
||||||
|
|
||||||
namespace PlexRequests.Services.Tests
|
namespace PlexRequests.Services.Tests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class NotificationServiceTests
|
public class NotificationServiceTests
|
||||||
{
|
{
|
||||||
public NotificationService NotificationService { get; set; }
|
public NotificationService NotificationService { get; set; }
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
NotificationService = new NotificationService();
|
NotificationService = new NotificationService();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SubscribeNewNotifier()
|
public void SubscribeNewNotifier()
|
||||||
{
|
{
|
||||||
var notificationMock = new Mock<INotification>();
|
var notificationMock = new Mock<INotification>();
|
||||||
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
NotificationService.Subscribe(notificationMock.Object);
|
NotificationService.Subscribe(notificationMock.Object);
|
||||||
|
|
||||||
Assert.That(NotificationService.Observers["Notification1"], Is.Not.Null);
|
Assert.That(NotificationService.Observers["Notification1"], Is.Not.Null);
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SubscribeExistingNotifier()
|
public void SubscribeExistingNotifier()
|
||||||
{
|
{
|
||||||
var notificationMock1 = new Mock<INotification>();
|
var notificationMock1 = new Mock<INotification>();
|
||||||
var notificationMock2 = new Mock<INotification>();
|
var notificationMock2 = new Mock<INotification>();
|
||||||
notificationMock1.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock1.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
notificationMock2.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock2.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
NotificationService.Subscribe(notificationMock1.Object);
|
NotificationService.Subscribe(notificationMock1.Object);
|
||||||
|
|
||||||
Assert.That(NotificationService.Observers["Notification1"], Is.Not.Null);
|
Assert.That(NotificationService.Observers["Notification1"], Is.Not.Null);
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
||||||
|
|
||||||
NotificationService.Subscribe(notificationMock2.Object);
|
NotificationService.Subscribe(notificationMock2.Object);
|
||||||
|
|
||||||
Assert.That(NotificationService.Observers["Notification1"], Is.Not.Null);
|
Assert.That(NotificationService.Observers["Notification1"], Is.Not.Null);
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void UnSubscribeMissingNotifier()
|
public void UnSubscribeMissingNotifier()
|
||||||
{
|
{
|
||||||
var notificationMock = new Mock<INotification>();
|
var notificationMock = new Mock<INotification>();
|
||||||
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
NotificationService.UnSubscribe(notificationMock.Object);
|
NotificationService.UnSubscribe(notificationMock.Object);
|
||||||
|
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(0));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void UnSubscribeNotifier()
|
public void UnSubscribeNotifier()
|
||||||
{
|
{
|
||||||
var notificationMock = new Mock<INotification>();
|
var notificationMock = new Mock<INotification>();
|
||||||
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
NotificationService.Subscribe(notificationMock.Object);
|
NotificationService.Subscribe(notificationMock.Object);
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(1));
|
||||||
|
|
||||||
NotificationService.UnSubscribe(notificationMock.Object);
|
NotificationService.UnSubscribe(notificationMock.Object);
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(0));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void PublishWithNoObservers()
|
public void PublishWithNoObservers()
|
||||||
{
|
{
|
||||||
Assert.DoesNotThrowAsync(
|
Assert.DoesNotThrowAsync(
|
||||||
async() =>
|
async() =>
|
||||||
{ await NotificationService.Publish(new NotificationModel()); });
|
{ await NotificationService.Publish(new NotificationModel()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task PublishAllNotifiers()
|
public async Task PublishAllNotifiers()
|
||||||
{
|
{
|
||||||
var notificationMock1 = new Mock<INotification>();
|
var notificationMock1 = new Mock<INotification>();
|
||||||
var notificationMock2 = new Mock<INotification>();
|
var notificationMock2 = new Mock<INotification>();
|
||||||
notificationMock1.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock1.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
notificationMock2.SetupGet(x => x.NotificationName).Returns("Notification2");
|
notificationMock2.SetupGet(x => x.NotificationName).Returns("Notification2");
|
||||||
NotificationService.Subscribe(notificationMock1.Object);
|
NotificationService.Subscribe(notificationMock1.Object);
|
||||||
NotificationService.Subscribe(notificationMock2.Object);
|
NotificationService.Subscribe(notificationMock2.Object);
|
||||||
|
|
||||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(2));
|
Assert.That(NotificationService.Observers.Count, Is.EqualTo(2));
|
||||||
var model = new NotificationModel { Title = "abc", Body = "test" };
|
var model = new NotificationModel { Title = "abc", Body = "test" };
|
||||||
await NotificationService.Publish(model);
|
await NotificationService.Publish(model);
|
||||||
|
|
||||||
notificationMock1.Verify(x => x.NotifyAsync(model), Times.Once);
|
notificationMock1.Verify(x => x.NotifyAsync(model), Times.Once);
|
||||||
notificationMock2.Verify(x => x.NotifyAsync(model), Times.Once);
|
notificationMock2.Verify(x => x.NotifyAsync(model), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task PublishWithException()
|
public async Task PublishWithException()
|
||||||
{
|
{
|
||||||
var notificationMock = new Mock<INotification>();
|
var notificationMock = new Mock<INotification>();
|
||||||
notificationMock.Setup(x => x.NotifyAsync(It.IsAny<NotificationModel>())).Throws<Exception>();
|
notificationMock.Setup(x => x.NotifyAsync(It.IsAny<NotificationModel>())).Throws<Exception>();
|
||||||
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||||
NotificationService.Subscribe(notificationMock.Object);
|
NotificationService.Subscribe(notificationMock.Object);
|
||||||
await NotificationService.Publish(new NotificationModel());
|
await NotificationService.Publish(new NotificationModel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,136 +1,141 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}</ProjectGuid>
|
<ProjectGuid>{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>PlexRequests.Services.Tests</RootNamespace>
|
<RootNamespace>PlexRequests.Services.Tests</RootNamespace>
|
||||||
<AssemblyName>PlexRequests.Services.Tests</AssemblyName>
|
<AssemblyName>PlexRequests.Services.Tests</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||||
<IsCodedUITest>False</IsCodedUITest>
|
<IsCodedUITest>False</IsCodedUITest>
|
||||||
<TestProjectType>UnitTest</TestProjectType>
|
<TestProjectType>UnitTest</TestProjectType>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
|
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
|
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
|
<Reference Include="Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
|
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
<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>
|
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Quartz, Version=2.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
|
<Reference Include="Ploeh.AutoFixture, Version=3.40.0.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Quartz.2.3.3\lib\net40\Quartz.dll</HintPath>
|
<HintPath>..\packages\AutoFixture.3.40.0\lib\net40\Ploeh.AutoFixture.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="Quartz, Version=2.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
|
||||||
</ItemGroup>
|
<HintPath>..\packages\Quartz.2.3.3\lib\net40\Quartz.dll</HintPath>
|
||||||
<Choose>
|
<Private>True</Private>
|
||||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
</Reference>
|
||||||
<ItemGroup>
|
<Reference Include="System" />
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
</ItemGroup>
|
||||||
</ItemGroup>
|
<Choose>
|
||||||
</When>
|
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||||
<Otherwise />
|
<ItemGroup>
|
||||||
</Choose>
|
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Compile Include="NotificationServiceTests.cs" />
|
</When>
|
||||||
<Compile Include="PlexAvailabilityCheckerTests.cs" />
|
<Otherwise />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
</Choose>
|
||||||
</ItemGroup>
|
<ItemGroup>
|
||||||
<ItemGroup>
|
<Compile Include="UserRequestLimitResetterTests.cs" />
|
||||||
<None Include="app.config">
|
<Compile Include="NotificationServiceTests.cs" />
|
||||||
<SubType>Designer</SubType>
|
<Compile Include="PlexAvailabilityCheckerTests.cs" />
|
||||||
</None>
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<None Include="job_scheduling_data_2_0.xsd">
|
</ItemGroup>
|
||||||
<SubType>Designer</SubType>
|
<ItemGroup>
|
||||||
</None>
|
<None Include="app.config">
|
||||||
<None Include="packages.config" />
|
<SubType>Designer</SubType>
|
||||||
</ItemGroup>
|
</None>
|
||||||
<ItemGroup>
|
<None Include="job_scheduling_data_2_0.xsd">
|
||||||
<ProjectReference Include="..\PlexRequests.Api.Interfaces\PlexRequests.Api.Interfaces.csproj">
|
<SubType>Designer</SubType>
|
||||||
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
|
</None>
|
||||||
<Name>PlexRequests.Api.Interfaces</Name>
|
<None Include="packages.config" />
|
||||||
</ProjectReference>
|
</ItemGroup>
|
||||||
<ProjectReference Include="..\PlexRequests.Api.Models\PlexRequests.Api.Models.csproj">
|
<ItemGroup>
|
||||||
<Project>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</Project>
|
<ProjectReference Include="..\PlexRequests.Api.Interfaces\PlexRequests.Api.Interfaces.csproj">
|
||||||
<Name>PlexRequests.Api.Models</Name>
|
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Api.Interfaces</Name>
|
||||||
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
|
</ProjectReference>
|
||||||
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
<ProjectReference Include="..\PlexRequests.Api.Models\PlexRequests.Api.Models.csproj">
|
||||||
<Name>PlexRequests.Core</Name>
|
<Project>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Api.Models</Name>
|
||||||
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
|
</ProjectReference>
|
||||||
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
|
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
|
||||||
<Name>PlexRequests.Helpers</Name>
|
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Core</Name>
|
||||||
<ProjectReference Include="..\PlexRequests.Services\PlexRequests.Services.csproj">
|
</ProjectReference>
|
||||||
<Project>{566EFA49-68F8-4716-9693-A6B3F2624DEA}</Project>
|
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
|
||||||
<Name>PlexRequests.Services</Name>
|
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Helpers</Name>
|
||||||
<ProjectReference Include="..\PlexRequests.Store\PlexRequests.Store.csproj">
|
</ProjectReference>
|
||||||
<Project>{92433867-2B7B-477B-A566-96C382427525}</Project>
|
<ProjectReference Include="..\PlexRequests.Services\PlexRequests.Services.csproj">
|
||||||
<Name>PlexRequests.Store</Name>
|
<Project>{566EFA49-68F8-4716-9693-A6B3F2624DEA}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Services</Name>
|
||||||
</ItemGroup>
|
</ProjectReference>
|
||||||
<Choose>
|
<ProjectReference Include="..\PlexRequests.Store\PlexRequests.Store.csproj">
|
||||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
<Project>{92433867-2B7B-477B-A566-96C382427525}</Project>
|
||||||
<ItemGroup>
|
<Name>PlexRequests.Store</Name>
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
</ProjectReference>
|
||||||
<Private>False</Private>
|
</ItemGroup>
|
||||||
</Reference>
|
<Choose>
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||||
<Private>False</Private>
|
<ItemGroup>
|
||||||
</Reference>
|
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Private>False</Private>
|
||||||
<Private>False</Private>
|
</Reference>
|
||||||
</Reference>
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Private>False</Private>
|
||||||
<Private>False</Private>
|
</Reference>
|
||||||
</Reference>
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
</ItemGroup>
|
<Private>False</Private>
|
||||||
</When>
|
</Reference>
|
||||||
</Choose>
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
<Private>False</Private>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
</Reference>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
</ItemGroup>
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
</When>
|
||||||
<Target Name="BeforeBuild">
|
</Choose>
|
||||||
</Target>
|
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||||
<Target Name="AfterBuild">
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
|
</Project>
|
151
PlexRequests.Services.Tests/UserRequestLimitResetterTests.cs
Normal file
151
PlexRequests.Services.Tests/UserRequestLimitResetterTests.cs
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
#region Copyright
|
||||||
|
/************************************************************************
|
||||||
|
Copyright (c) 2016 Jamie Rees
|
||||||
|
File: NotificationServiceTests.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.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Moq;
|
||||||
|
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
|
using PlexRequests.Services.Interfaces;
|
||||||
|
using PlexRequests.Services.Jobs;
|
||||||
|
using PlexRequests.Services.Notification;
|
||||||
|
using PlexRequests.Store;
|
||||||
|
using PlexRequests.Store.Models;
|
||||||
|
using PlexRequests.Store.Repository;
|
||||||
|
|
||||||
|
using Ploeh.AutoFixture;
|
||||||
|
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace PlexRequests.Services.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class UserRequestLimitResetterTests
|
||||||
|
{
|
||||||
|
public UserRequestLimitResetter Resetter { get; set; }
|
||||||
|
private Mock<IJobRecord> JobMock { get; set; }
|
||||||
|
private Mock<IRepository<RequestLimit>> RepoMock { get; set; }
|
||||||
|
private Mock<ISettingsService<PlexRequestSettings>> SettingsMock { get; set; }
|
||||||
|
private Mock<IJobExecutionContext> ContextMock { get; set; }
|
||||||
|
private Fixture F { get; set; }
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
F = new Fixture();
|
||||||
|
JobMock = new Mock<IJobRecord>();
|
||||||
|
RepoMock = new Mock<IRepository<RequestLimit>>();
|
||||||
|
SettingsMock = new Mock<ISettingsService<PlexRequestSettings>>();
|
||||||
|
ContextMock = new Mock<IJobExecutionContext>();
|
||||||
|
|
||||||
|
SettingsMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
|
||||||
|
|
||||||
|
Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TearDown]
|
||||||
|
public void Teardown()
|
||||||
|
{
|
||||||
|
SettingsMock.Verify(x => x.GetSettings(), Times.Once);
|
||||||
|
JobMock.Verify(x => x.Record(It.IsAny<string>()), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ResetTurnedOff()
|
||||||
|
{
|
||||||
|
SetupSettings(0, 0, 0);
|
||||||
|
Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object);
|
||||||
|
|
||||||
|
Resetter.Execute(ContextMock.Object);
|
||||||
|
|
||||||
|
RepoMock.Verify(x => x.Delete(It.IsAny<RequestLimit>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCaseSource(nameof(ResetData))]
|
||||||
|
public void Reset(int movie, int tv, int album, RequestType type)
|
||||||
|
{
|
||||||
|
SetupSettings(movie, tv, album);
|
||||||
|
RepoMock.Setup(x => x.GetAll()).Returns(F.Build<RequestLimit>()
|
||||||
|
.With(x => x.FirstRequestDate, DateTime.Now.AddDays(-8))
|
||||||
|
.With(x => x.RequestType, type).CreateMany());
|
||||||
|
|
||||||
|
Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object);
|
||||||
|
|
||||||
|
Resetter.Execute(ContextMock.Object);
|
||||||
|
|
||||||
|
RepoMock.Verify(x => x.Delete(It.IsAny<RequestLimit>()), Times.Exactly(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCaseSource(nameof(DoNotResetData))]
|
||||||
|
public void DoNotReset(int days, RequestType type)
|
||||||
|
{
|
||||||
|
SetupSettings(1, 1, 1);
|
||||||
|
RepoMock.Setup(x => x.GetAll()).Returns(F.Build<RequestLimit>()
|
||||||
|
.With(x => x.FirstRequestDate, DateTime.Now.AddDays(days))
|
||||||
|
.With(x => x.RequestType, type).CreateMany());
|
||||||
|
|
||||||
|
Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object);
|
||||||
|
|
||||||
|
Resetter.Execute(ContextMock.Object);
|
||||||
|
|
||||||
|
RepoMock.Verify(x => x.Delete(It.IsAny<RequestLimit>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly IEnumerable<TestCaseData> ResetData = new List<TestCaseData>
|
||||||
|
{
|
||||||
|
new TestCaseData(1,0,0,RequestType.Movie).SetName("Reset Movies"),
|
||||||
|
new TestCaseData(0,1,0,RequestType.TvShow).SetName("Reset TV Shows"),
|
||||||
|
new TestCaseData(0,0,1,RequestType.Album).SetName("Reset Albums"),
|
||||||
|
new TestCaseData(1,1,1,RequestType.Album).SetName("Reset Albums with all enabled"),
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly IEnumerable<TestCaseData> DoNotResetData = new List<TestCaseData>
|
||||||
|
{
|
||||||
|
new TestCaseData(1, RequestType.Movie).SetName("1 Day(s)"),
|
||||||
|
new TestCaseData(-6, RequestType.TvShow).SetName("-6 Day(s)"),
|
||||||
|
new TestCaseData(-1, RequestType.TvShow).SetName("-1 Day(s)"),
|
||||||
|
new TestCaseData(-2, RequestType.Album).SetName("-2 Day(s)"),
|
||||||
|
new TestCaseData(-3, RequestType.TvShow).SetName("-3 Day(s)"),
|
||||||
|
new TestCaseData(-4, RequestType.Movie).SetName("-4 Day(s)"),
|
||||||
|
new TestCaseData(-5, RequestType.TvShow).SetName("-5 Day(s)"),
|
||||||
|
new TestCaseData(-6, RequestType.Movie).SetName("-6 Day(s)"),
|
||||||
|
new TestCaseData(0, RequestType.TvShow).SetName("0 Day(s)"),
|
||||||
|
};
|
||||||
|
|
||||||
|
private void SetupSettings(int movie, int tv, int album)
|
||||||
|
{
|
||||||
|
SettingsMock.Setup(x => x.GetSettings())
|
||||||
|
.Returns(new PlexRequestSettings { MovieWeeklyRequestLimit = movie, TvWeeklyRequestLimit = tv, AlbumWeeklyRequestLimit = album });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Common.Logging" version="3.0.0" targetFramework="net452" />
|
<package id="AutoFixture" version="3.40.0" targetFramework="net452" />
|
||||||
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net452" />
|
<package id="Common.Logging" version="3.0.0" targetFramework="net452" />
|
||||||
<package id="Moq" version="4.2.1510.2205" targetFramework="net46" />
|
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net452" />
|
||||||
<package id="NUnit" version="3.2.0" targetFramework="net46" />
|
<package id="Moq" version="4.2.1510.2205" targetFramework="net46" />
|
||||||
<package id="Quartz" version="2.3.3" targetFramework="net452" />
|
<package id="NUnit" version="3.2.0" targetFramework="net46" />
|
||||||
|
<package id="Quartz" version="2.3.3" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
|
@ -109,7 +109,8 @@ namespace PlexRequests.Services.Jobs
|
||||||
var users = allUsers.Where(x => x.RequestType == type);
|
var users = allUsers.Where(x => x.RequestType == type);
|
||||||
foreach (var u in users)
|
foreach (var u in users)
|
||||||
{
|
{
|
||||||
if (u.FirstRequestDate > DateTime.UtcNow.AddDays(-7))
|
var daysDiff = (u.FirstRequestDate - DateTime.UtcNow.AddDays(-7)).Days;
|
||||||
|
if (daysDiff <= 0)
|
||||||
{
|
{
|
||||||
Repo.Delete(u);
|
Repo.Delete(u);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,71 +1,71 @@
|
||||||
@using PlexRequests.UI.Helpers
|
@using PlexRequests.UI.Helpers
|
||||||
@Html.Partial("_Sidebar")
|
@Html.Partial("_Sidebar")
|
||||||
|
|
||||||
<div class="col-sm-8 col-sm-push-1">
|
<div class="col-sm-8 col-sm-push-1">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Status</legend>
|
<legend>Status</legend>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">Version: </label>
|
<label class="control-label">Version: </label>
|
||||||
<label class="control-label">@Model.Version</label>
|
<label class="control-label">@Model.Version</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">Update Available: </label>
|
<label class="control-label">Update Available: </label>
|
||||||
@if (Model.UpdateAvailable)
|
@if (Model.UpdateAvailable)
|
||||||
{
|
{
|
||||||
<label class="control-label"><a href="@Model.UpdateUri" target="_blank"><i class="fa fa-check"></i></a></label>
|
<label class="control-label"><a href="@Model.UpdateUri" target="_blank"><i class="fa fa-check"></i></a></label>
|
||||||
<br />
|
<br />
|
||||||
<button id="autoUpdate" class="btn btn-success-outline">Automatic Update <i class="fa fa-download"></i></button>
|
@*<button id="autoUpdate" class="btn btn-success-outline">Automatic Update <i class="fa fa-download"></i></button>*@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<label class="control-label"><i class="fa fa-times"></i></label>
|
<label class="control-label"><i class="fa fa-times"></i></label>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (Model.UpdateAvailable)
|
@if (Model.UpdateAvailable)
|
||||||
{
|
{
|
||||||
<h2>
|
<h2>
|
||||||
<a href="@Model.DownloadUri">@Model.ReleaseTitle</a>
|
<a href="@Model.DownloadUri">@Model.ReleaseTitle</a>
|
||||||
</h2>
|
</h2>
|
||||||
<hr />
|
<hr />
|
||||||
<label>Release Notes:</label>
|
<label>Release Notes:</label>
|
||||||
@Html.Raw(Model.ReleaseNotes)
|
@Html.Raw(Model.ReleaseNotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var base = '@Html.GetBaseUrl()';
|
var base = '@Html.GetBaseUrl()';
|
||||||
$('#autoUpdate')
|
$('#autoUpdate')
|
||||||
.click(function (e) {
|
.click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$('body').append("<i class=\"fa fa-spinner fa-spin fa-5x fa-fw\" style=\"position: absolute; top: 20%; left: 50%;\"></i>");
|
$('body').append("<i class=\"fa fa-spinner fa-spin fa-5x fa-fw\" style=\"position: absolute; top: 20%; left: 50%;\"></i>");
|
||||||
$('#autoUpdate').prop("disabled", "disabled");
|
$('#autoUpdate').prop("disabled", "disabled");
|
||||||
var count = 0;
|
var count = 0;
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
count++;
|
count++;
|
||||||
var dots = new Array(count % 10).join('.');
|
var dots = new Array(count % 10).join('.');
|
||||||
document.getElementById('autoUpdate').innerHTML = "Updating" + dots;
|
document.getElementById('autoUpdate').innerHTML = "Updating" + dots;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "Post",
|
type: "Post",
|
||||||
url: "autoupdate",
|
url: "autoupdate",
|
||||||
data: { url: "@Model.DownloadUri" },
|
data: { url: "@Model.DownloadUri" },
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
error: function () {
|
error: function () {
|
||||||
setTimeout(
|
setTimeout(
|
||||||
function () {
|
function () {
|
||||||
location.reload();
|
location.reload();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue