mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 05:13:18 -07:00
started adding some more unit tests #1596
This commit is contained in:
parent
727c7be9f2
commit
b7b0381ce7
12 changed files with 419 additions and 14 deletions
64
src/Ombi.Core.Tests/Rule/Search/CouchPotatoCacheRuleTests.cs
Normal file
64
src/Ombi.Core.Tests/Rule/Search/CouchPotatoCacheRuleTests.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
|
||||
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 CouchPotatoCacheRuleTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
ContextMock = new Mock<IRepository<CouchPotatoCache>>();
|
||||
Rule = new CouchPotatoCacheRule(ContextMock.Object);
|
||||
|
||||
}
|
||||
|
||||
private CouchPotatoCacheRule Rule { get; set; }
|
||||
private Mock<IRepository<CouchPotatoCache>> ContextMock { get; set; }
|
||||
|
||||
[Test]
|
||||
public async Task Should_ReturnApproved_WhenMovieIsInCouchPotato()
|
||||
{
|
||||
var list = new CouchPotatoCache
|
||||
{
|
||||
TheMovieDbId = 123
|
||||
};
|
||||
|
||||
ContextMock.Setup(x => x.FirstOrDefaultAsync(It.IsAny<Expression<Func<CouchPotatoCache, bool>>>())).ReturnsAsync(list);
|
||||
|
||||
var request = new SearchMovieViewModel { Id = 123 };
|
||||
var result =await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.True(request.Approved);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Should_ReturnNotApproved_WhenMovieIsNotCouchPotato()
|
||||
{
|
||||
var list = DbHelper.GetQueryableMockDbSet(new CouchPotatoCache
|
||||
{
|
||||
TheMovieDbId = 000012
|
||||
});
|
||||
|
||||
ContextMock.Setup(x => x.GetAll()).Returns(list);
|
||||
|
||||
var request = new SearchMovieViewModel { Id = 123 };
|
||||
var result = await Rule.Execute(request);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(request.Approved);
|
||||
}
|
||||
}
|
||||
}
|
50
src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs
Normal file
50
src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System.Collections.Generic;
|
||||
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;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
|
||||
namespace Ombi.Core.Tests.Rule.Search
|
||||
{
|
||||
public class EmbyAvailabilityRuleTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
ContextMock = new Mock<IEmbyContentRepository>();
|
||||
Rule = new EmbyAvailabilityRule(ContextMock.Object);
|
||||
}
|
||||
|
||||
private EmbyAvailabilityRule Rule { get; set; }
|
||||
private Mock<IEmbyContentRepository> ContextMock { get; set; }
|
||||
|
||||
[Test]
|
||||
public async Task Movie_ShouldBe_Available_WhenFoundInEmby()
|
||||
{
|
||||
ContextMock.Setup(x => x.Get(It.IsAny<string>())).ReturnsAsync(new EmbyContent
|
||||
{
|
||||
ProviderId = "123"
|
||||
});
|
||||
var search = new SearchMovieViewModel();
|
||||
var result = await Rule.Execute(search);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.True(search.Available);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInEmby()
|
||||
{
|
||||
ContextMock.Setup(x => x.Get(It.IsAny<string>())).Returns(Task.FromResult(default(EmbyContent)));
|
||||
var search = new SearchMovieViewModel();
|
||||
var result = await Rule.Execute(search);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.False(search.Available);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue