started adding some more unit tests #1596

This commit is contained in:
Jamie.Rees 2017-10-19 12:11:23 +01:00
commit b7b0381ce7
12 changed files with 419 additions and 14 deletions

View 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);
}
}
}

View 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);
}
}
}