mirror of https://github.com/Ombi-app/Ombi
parent
90b38e09ec
commit
b98f5607d6
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using MockQueryable.Moq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Rule.Rules;
|
||||
using Ombi.Core.Rule.Rules.Request;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
using Ombi.Test.Common;
|
||||
|
||||
namespace Ombi.Core.Tests.Rule.Request
|
||||
{
|
||||
public class ExistingMovieRequestRuleTests
|
||||
{
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
ContextMock = new Mock<IMovieRequestRepository>();
|
||||
Rule = new ExistingMovieRequestRule(ContextMock.Object);
|
||||
}
|
||||
|
||||
|
||||
private ExistingMovieRequestRule Rule { get; set; }
|
||||
private Mock<IMovieRequestRepository> ContextMock { get; set; }
|
||||
|
||||
[Test]
|
||||
public async Task ExistingRequestRule_Movie_Has_Been_Requested_With_TheMovieDBId()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<MovieRequests>
|
||||
{
|
||||
new MovieRequests
|
||||
{
|
||||
TheMovieDbId = 1,
|
||||
RequestType = RequestType.Movie
|
||||
}
|
||||
}.AsQueryable().BuildMock().Object);
|
||||
var o = new MovieRequests
|
||||
{
|
||||
TheMovieDbId = 1,
|
||||
};
|
||||
var result = await Rule.Execute(o);
|
||||
|
||||
Assert.That(result.Success, Is.False);
|
||||
Assert.That(result.Message, Is.Not.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExistingRequestRule_Movie_Has_Been_Requested_With_ImdbId()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<MovieRequests>
|
||||
{
|
||||
new MovieRequests
|
||||
{
|
||||
TheMovieDbId = 11111,
|
||||
ImdbId = 1.ToString(),
|
||||
RequestType = RequestType.Movie
|
||||
}
|
||||
}.AsQueryable().BuildMock().Object);
|
||||
var o = new MovieRequests
|
||||
{
|
||||
ImdbId = 1.ToString(),
|
||||
};
|
||||
var result = await Rule.Execute(o);
|
||||
|
||||
Assert.That(result.Success, Is.False);
|
||||
Assert.That(result.Message, Is.Not.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExistingRequestRule_Movie_HasNot_Been_Requested()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<MovieRequests>
|
||||
{
|
||||
new MovieRequests
|
||||
{
|
||||
TheMovieDbId = 2,
|
||||
ImdbId = "2",
|
||||
RequestType = RequestType.Movie
|
||||
}
|
||||
}.AsQueryable().BuildMock().Object);
|
||||
var o = new MovieRequests
|
||||
{
|
||||
TheMovieDbId = 1,
|
||||
ImdbId = "1"
|
||||
};
|
||||
var result = await Rule.Execute(o);
|
||||
|
||||
Assert.That(result.Success, Is.True);
|
||||
Assert.That(result.Message, Is.Null.Or.Empty);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Rules.Search;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
|
||||
namespace Ombi.Core.Tests.Rule.Search
|
||||
{
|
||||
public class LidarrAlbumCacheRuleTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
ContextMock = new Mock<IExternalRepository<LidarrAlbumCache>>();
|
||||
Rule = new LidarrAlbumCacheRule(ContextMock.Object);
|
||||
|
||||
}
|
||||
|
||||
private LidarrAlbumCacheRule Rule { get; set; }
|
||||
private Mock<IExternalRepository<LidarrAlbumCache>> ContextMock { get; set; }
|
||||
|
||||
[Test]
|
||||
public async Task Should_Not_Be_Monitored_Or_Available()
|
||||
{
|
||||
var request = new SearchAlbumViewModel { ForeignAlbumId = "abc" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Approved);
|
||||
Assert.False(request.Monitored);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Should_Be_Monitored_But_Not_Available()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<LidarrAlbumCache>
|
||||
{
|
||||
new LidarrAlbumCache
|
||||
{
|
||||
ForeignAlbumId = "abc",
|
||||
PercentOfTracks = 0
|
||||
}
|
||||
}.AsQueryable());
|
||||
var request = new SearchAlbumViewModel { ForeignAlbumId = "abc" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Approved);
|
||||
Assert.True(request.Monitored);
|
||||
Assert.That(request.PartiallyAvailable, Is.EqualTo(false));
|
||||
Assert.That(request.Available, Is.EqualTo(false));
|
||||
Assert.That(request.FullyAvailable, Is.EqualTo(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Should_Be_Monitored_And_Partly_Available()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<LidarrAlbumCache>
|
||||
{
|
||||
new LidarrAlbumCache
|
||||
{
|
||||
ForeignAlbumId = "abc",
|
||||
PercentOfTracks = 1
|
||||
}
|
||||
}.AsQueryable());
|
||||
var request = new SearchAlbumViewModel { ForeignAlbumId = "abc" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Approved);
|
||||
Assert.True(request.Monitored);
|
||||
Assert.That(request.PartiallyAvailable, Is.EqualTo(true));
|
||||
Assert.That(request.Available, Is.EqualTo(false));
|
||||
Assert.That(request.FullyAvailable, Is.EqualTo(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Should_Be_Monitored_And_Fully_Available()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<LidarrAlbumCache>
|
||||
{
|
||||
new LidarrAlbumCache
|
||||
{
|
||||
ForeignAlbumId = "abc",
|
||||
PercentOfTracks = 100
|
||||
}
|
||||
}.AsQueryable());
|
||||
var request = new SearchAlbumViewModel { ForeignAlbumId = "abc" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Approved);
|
||||
Assert.True(request.Monitored);
|
||||
Assert.That(request.PartiallyAvailable, Is.EqualTo(false));
|
||||
Assert.That(request.FullyAvailable, Is.EqualTo(true));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Should_Be_Monitored_And_Fully_Available_Casing()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<LidarrAlbumCache>
|
||||
{
|
||||
new LidarrAlbumCache
|
||||
{
|
||||
ForeignAlbumId = "abc",
|
||||
PercentOfTracks = 100
|
||||
}
|
||||
}.AsQueryable());
|
||||
var request = new SearchAlbumViewModel { ForeignAlbumId = "ABC" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Approved);
|
||||
Assert.True(request.Monitored);
|
||||
Assert.That(request.PartiallyAvailable, Is.EqualTo(false));
|
||||
Assert.That(request.FullyAvailable, Is.EqualTo(true));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Rules.Search;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
|
||||
namespace Ombi.Core.Tests.Rule.Search
|
||||
{
|
||||
public class LidarrArtistCacheRuleTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
ContextMock = new Mock<IExternalRepository<LidarrArtistCache>>();
|
||||
Rule = new LidarrArtistCacheRule(ContextMock.Object);
|
||||
}
|
||||
|
||||
private LidarrArtistCacheRule Rule { get; set; }
|
||||
private Mock<IExternalRepository<LidarrArtistCache>> ContextMock { get; set; }
|
||||
|
||||
[Test]
|
||||
public async Task Should_Not_Be_Monitored()
|
||||
{
|
||||
var request = new SearchArtistViewModel { ForignArtistId = "abc" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Monitored);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Should_Be_Monitored()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<LidarrArtistCache>
|
||||
{
|
||||
new LidarrArtistCache
|
||||
{
|
||||
ForeignArtistId = "abc",
|
||||
}
|
||||
}.AsQueryable());
|
||||
var request = new SearchArtistViewModel { ForignArtistId = "abc" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.True(request.Monitored);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Should_Be_Monitored_Casing()
|
||||
{
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(new List<LidarrArtistCache>
|
||||
{
|
||||
new LidarrArtistCache
|
||||
{
|
||||
ForeignArtistId = "abc",
|
||||
}
|
||||
}.AsQueryable());
|
||||
var request = new SearchArtistViewModel { ForignArtistId = "ABC" };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.True(request.Monitored);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue