This commit is contained in:
Jamie.Rees 2017-09-14 16:08:46 +01:00
commit 599cb013d5
10 changed files with 117 additions and 111 deletions

View file

@ -1,4 +1,4 @@
#tool "xunit.runner.console" #tool "nuget:?package=NUnit.Runners
#tool "nuget:?package=GitVersion.CommandLine" #tool "nuget:?package=GitVersion.CommandLine"
#addin "Cake.Gulp" #addin "Cake.Gulp"
#addin "Cake.Npm" #addin "Cake.Npm"
@ -217,6 +217,7 @@ Task("Run-Unit-Tests")
.IsDependentOn("Publish") .IsDependentOn("Publish")
.Does(() => .Does(() =>
{ {
NUnit("./src/**/bin/Release/*.Tests.dll");
}); });
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View file

@ -2,14 +2,16 @@
//using System.Linq; //using System.Linq;
//using System.Threading.Tasks; //using System.Threading.Tasks;
//using Moq; //using Moq;
//using NUnit.Framework;
//using Ombi.Core.Engine; //using Ombi.Core.Engine;
//using Ombi.Core.Models.Requests; //using Ombi.Core.Models.Requests;
//using Ombi.Store.Entities.Requests; //using Ombi.Store.Entities.Requests;
//using Ombi.Store.Repository; //using Ombi.Store.Repository;
//using Xunit; //using Assert = Xunit.Assert;
//namespace Ombi.Core.Tests.Engine //namespace Ombi.Core.Tests.Engine
//{ //{
// [TestFixture]
// public class MovieRequestEngineTests // public class MovieRequestEngineTests
// { // {
// public MovieRequestEngineTests() // public MovieRequestEngineTests()
@ -22,7 +24,7 @@
// private MovieRequestEngine Engine { get; } // private MovieRequestEngine Engine { get; }
// private Mock<IMovieRequestRepository> RequestService { get; } // private Mock<IMovieRequestRepository> RequestService { get; }
// [Fact] // [Test]
// public async Task GetNewRequests_Should_ReturnEmpty_WhenThereAreNoNewRequests() // public async Task GetNewRequests_Should_ReturnEmpty_WhenThereAreNoNewRequests()
// { // {
// var requests = new List<MovieRequests> // var requests = new List<MovieRequests>
@ -39,95 +41,95 @@
// Assert.False(result.Any()); // Assert.False(result.Any());
// } // }
// //[Fact] // [Test]
// //public async Task GetNewRequests_Should_ReturnOnlyNewRequests_WhenThereAreMultipleRequests() // public async Task GetNewRequests_Should_ReturnOnlyNewRequests_WhenThereAreMultipleRequests()
// //{ // {
// // var requests = new List<MovieRequestModel> // var requests = new List<MovieRequests>
// // { // {
// // new MovieRequestModel { Available = true }, // new MovieRequests { Available = true },
// // new MovieRequestModel { Approved = true }, // new MovieRequests { Approved = true },
// // new MovieRequestModel(), // new MovieRequests(),
// // }; // };
// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); // RequestService.Setup(x => x.Get()).Returns(requests.AsQueryable);
// // var result = await Engine.GetNewRequests(); // var result = await Engine.GetNewRequests();
// // Assert.Equal(result.Count(), 1); // Assert.Single(result);
// // Assert.All(result, x => // Assert.All(result, x =>
// // { // {
// // Assert.Equal(x.Available, false); // Assert.False(x.Available);
// // Assert.Equal(x.Approved, false); // Assert.False(x.Approved);
// // }); // });
// //} // }
// //[Fact] // [Test]
// //public async Task GetApprovedRequests_Should_ReturnEmpty_WhenThereAreNoApprovedRequests() // public async Task GetApprovedRequests_Should_ReturnEmpty_WhenThereAreNoApprovedRequests()
// //{ // {
// // var requests = new List<MovieRequestModel> // var requests = new List<MovieRequests>
// // { // {
// // new MovieRequestModel { Available = true }, // new MovieRequests { Available = true },
// // }; // };
// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); // RequestService.Setup(x => x.Get()).Returns(requests.AsQueryable);
// // var result = await Engine.GetApprovedRequests(); // var result = await Engine.GetApprovedRequests();
// // Assert.False(result.Any()); // Assert.False(result.Any());
// //} // }
// //[Fact] // [Test]
// //public async Task GetApprovedRequests_Should_ReturnOnlyApprovedRequests_WhenThereAreMultipleRequests() // public async Task GetApprovedRequests_Should_ReturnOnlyApprovedRequests_WhenThereAreMultipleRequests()
// //{ // {
// // var requests = new List<MovieRequestModel> // var requests = new List<MovieRequests>
// // { // {
// // new MovieRequestModel { Available = true }, // new MovieRequests { Available = true },
// // new MovieRequestModel { Approved = true }, // new MovieRequests { Approved = true },
// // new MovieRequestModel(), // new MovieRequests(),
// // }; // };
// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); // RequestService.Setup(x => x.Get()).Returns(requests.AsQueryable);
// // var result = await Engine.GetApprovedRequests(); // var result = await Engine.GetApprovedRequests();
// // Assert.Equal(result.Count(), 1); // Assert.Single(result);
// // Assert.All(result, x => // Assert.All(result, x =>
// // { // {
// // Assert.Equal(x.Available, false); // Assert.False(x.Available);
// // Assert.Equal(x.Approved, true); // Assert.True(x.Approved);
// // }); // });
// //} // }
// //[Fact] // [Test]
// //public async Task GetAvailableRequests_Should_ReturnEmpty_WhenThereAreNoAvailableRequests() // public async Task GetAvailableRequests_Should_ReturnEmpty_WhenThereAreNoAvailableRequests()
// //{ // {
// // var requests = new List<MovieRequestModel> // var requests = new List<MovieRequests>
// // { // {
// // new MovieRequestModel { Approved = true }, // new MovieRequests { Approved = true },
// // }; // };
// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); // RequestService.Setup(x => x.Get()).Returns(requests.AsQueryable);
// // var result = await Engine.GetAvailableRequests(); // var result = await Engine.GetAvailableRequests();
// // Assert.False(result.Any()); // Assert.False(result.Any());
// //} // }
// //[Fact] // [Test]
// //public async Task GetAvailableRequests_Should_ReturnOnlyAvailableRequests_WhenThereAreMultipleRequests() // public async Task GetAvailableRequests_Should_ReturnOnlyAvailableRequests_WhenThereAreMultipleRequests()
// //{ // {
// // var requests = new List<MovieRequestModel> // var requests = new List<MovieRequests>
// // { // {
// // new MovieRequestModel { Available = true }, // new MovieRequests { Available = true },
// // new MovieRequestModel { Approved = true }, // new MovieRequests { Approved = true },
// // new MovieRequestModel(), // new MovieRequests(),
// // }; // };
// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); // RequestService.Setup(x => x.Get()).Returns(requests.AsQueryable);
// // var result = await Engine.GetAvailableRequests(); // var result = await Engine.GetAvailableRequests();
// // Assert.Equal(result.Count(), 1); // Assert.Single(result);
// // Assert.All(result, x => // Assert.All(result, x =>
// // { // {
// // Assert.Equal(x.Available, true); // Assert.True(x.Available);
// // Assert.Equal(x.Approved, false); // Assert.False(x.Approved);
// // }); // });
// //} // }
// } // }
//} //}

View file

@ -5,9 +5,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Moq" Version="4.7.10" /> <PackageReference Include="Moq" Version="4.7.99" />
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" /> <PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
<PackageReference Include="Nunit" Version="3.7.1" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
</ItemGroup> </ItemGroup>

View file

@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Hangfire;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
@ -112,7 +113,6 @@ namespace Ombi.DependencyInjection
services.AddSingleton<IEmailProvider, GenericEmailProvider>(); services.AddSingleton<IEmailProvider, GenericEmailProvider>();
services.AddTransient<INotificationHelper, NotificationHelper>(); services.AddTransient<INotificationHelper, NotificationHelper>();
services.AddTransient<IDiscordNotification, DiscordNotification>(); services.AddTransient<IDiscordNotification, DiscordNotification>();
services.AddTransient<IEmailNotification, EmailNotification>(); services.AddTransient<IEmailNotification, EmailNotification>();
services.AddTransient<IPushbulletNotification, PushbulletNotification>(); services.AddTransient<IPushbulletNotification, PushbulletNotification>();
@ -120,6 +120,8 @@ namespace Ombi.DependencyInjection
services.AddTransient<ISlackNotification, SlackNotification>(); services.AddTransient<ISlackNotification, SlackNotification>();
services.AddTransient<IMattermostNotification, MattermostNotification>(); services.AddTransient<IMattermostNotification, MattermostNotification>();
services.AddTransient<IPushoverNotification, PushoverNotification>(); services.AddTransient<IPushoverNotification, PushoverNotification>();
services.AddTransient<IBackgroundJobClient, BackgroundJobClient>();
} }
public static void RegisterJobs(this IServiceCollection services) public static void RegisterJobs(this IServiceCollection services)

View file

@ -5,10 +5,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170914-09" />
<PackageReference Include="Moq" Version="4.7.10" /> <PackageReference Include="Moq" Version="4.7.99" />
<PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Castle.Components.DictionaryAdapter; using Castle.Components.DictionaryAdapter;
using Hangfire;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using Ombi.Core.Notifications; using Ombi.Core.Notifications;
@ -23,7 +24,7 @@ namespace Ombi.Schedule.Tests
_movie = new Mock<IMovieRequestRepository>(); _movie = new Mock<IMovieRequestRepository>();
_movie = new Mock<IMovieRequestRepository>(); _movie = new Mock<IMovieRequestRepository>();
_notify = new Mock<INotificationService>(); _notify = new Mock<INotificationService>();
Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object); Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock<IBackgroundJobClient>().Object);
} }
private readonly Mock<IPlexContentRepository> _repo; private readonly Mock<IPlexContentRepository> _repo;
@ -60,7 +61,6 @@ namespace Ombi.Schedule.Tests
await Checker.Start(); await Checker.Start();
_movie.Verify(x => x.Save(), Times.Once);
Assert.False(request.Available); Assert.False(request.Available);
} }

View file

@ -15,18 +15,20 @@ namespace Ombi.Schedule.Jobs.Plex
public class PlexAvailabilityChecker : IPlexAvailabilityChecker public class PlexAvailabilityChecker : IPlexAvailabilityChecker
{ {
public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository tvRequest, IMovieRequestRepository movies, public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository tvRequest, IMovieRequestRepository movies,
INotificationService notification) INotificationService notification, IBackgroundJobClient background)
{ {
_tvRepo = tvRequest; _tvRepo = tvRequest;
_repo = repo; _repo = repo;
_movieRepo = movies; _movieRepo = movies;
_notificationService = notification; _notificationService = notification;
_backgroundJobClient = background;
} }
private readonly ITvRequestRepository _tvRepo; private readonly ITvRequestRepository _tvRepo;
private readonly IMovieRequestRepository _movieRepo; private readonly IMovieRequestRepository _movieRepo;
private readonly IPlexContentRepository _repo; private readonly IPlexContentRepository _repo;
private readonly INotificationService _notificationService; private readonly INotificationService _notificationService;
private readonly IBackgroundJobClient _backgroundJobClient;
public async Task Start() public async Task Start()
{ {
@ -64,7 +66,7 @@ namespace Ombi.Schedule.Jobs.Plex
{ {
// We have fulfulled this request! // We have fulfulled this request!
child.Available = true; child.Available = true;
BackgroundJob.Enqueue(() => _notificationService.Publish(new NotificationOptions _backgroundJobClient.Enqueue(() => _notificationService.Publish(new NotificationOptions
{ {
DateTime = DateTime.Now, DateTime = DateTime.Now,
NotificationType = NotificationType.RequestAvailable, NotificationType = NotificationType.RequestAvailable,
@ -94,7 +96,7 @@ namespace Ombi.Schedule.Jobs.Plex
movie.Available = true; movie.Available = true;
if (movie.Available) if (movie.Available)
{ {
BackgroundJob.Enqueue(() => _notificationService.Publish(new NotificationOptions _backgroundJobClient.Enqueue(() => _notificationService.Publish(new NotificationOptions
{ {
DateTime = DateTime.Now, DateTime = DateTime.Now,
NotificationType = NotificationType.RequestAvailable, NotificationType = NotificationType.RequestAvailable,

View file

@ -22,7 +22,6 @@ namespace Ombi.Store.Context
} }
public DbSet<NotificationTemplates> NotificationTemplates { get; set; } public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
public DbSet<GlobalSettings> Settings { get; set; } public DbSet<GlobalSettings> Settings { get; set; }
public DbSet<PlexContent> PlexContent { get; set; } public DbSet<PlexContent> PlexContent { get; set; }

View file

@ -10,8 +10,8 @@ if (module['hot']) {
module['hot'].accept(); module['hot'].accept();
module['hot'].dispose(() => { module['hot'].dispose(() => {
// Before restarting the app, we create a new root element and dispose the old one // Before restarting the app, we create a new root element and dispose the old one
const oldRootElem = document.querySelector('app'); const oldRootElem = document.querySelector('ombi');
const newRootElem = document.createElement('app'); const newRootElem = document.createElement('ombi');
if (oldRootElem && oldRootElem.parentNode) { if (oldRootElem && oldRootElem.parentNode) {
oldRootElem.parentNode.insertBefore(newRootElem, oldRootElem); oldRootElem.parentNode.insertBefore(newRootElem, oldRootElem);
} }

View file

@ -196,9 +196,6 @@ namespace Ombi
{ {
var ctx = serviceProvider.GetService<IOmbiContext>(); var ctx = serviceProvider.GetService<IOmbiContext>();
loggerFactory.AddSerilog(); loggerFactory.AddSerilog();
if (env.IsDevelopment()) if (env.IsDevelopment())