mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 15:32:31 +01:00
Added tests for RootDirProvider.
This commit is contained in:
parent
bfeb7b35e3
commit
0a7f7fc1fc
@ -93,6 +93,7 @@
|
||||
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RootDirProviderTest.cs" />
|
||||
<Compile Include="RssProviderTest.cs" />
|
||||
<Compile Include="HistoryProviderTest.cs" />
|
||||
<Compile Include="MediaFileProviderTests.cs" />
|
||||
|
121
NzbDrone.Core.Test/RootDirProviderTest.cs
Normal file
121
NzbDrone.Core.Test/RootDirProviderTest.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoMoq;
|
||||
using Gallio.Framework;
|
||||
using MbUnit.Framework;
|
||||
using MbUnit.Framework.ContractVerifiers;
|
||||
using Moq;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class RootDirProviderTest
|
||||
{
|
||||
[Test]
|
||||
public void GetRootDirs()
|
||||
{
|
||||
//Setup
|
||||
var sonicRepo = MockLib.GetEmptyRepository();
|
||||
sonicRepo.Add(new RootDir { Path = @"C:\TV" });
|
||||
sonicRepo.Add(new RootDir { Path = @"C:\TV2" });
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(f => f.All<RootDir>())
|
||||
.Returns(sonicRepo.All<RootDir>);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<RootDirProvider>().GetAll();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(result.Count, 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddRootDir()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
|
||||
string path = @"C:\TV\";
|
||||
|
||||
//Act
|
||||
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
||||
rootDirProvider.Add(new RootDir{ Path = path });
|
||||
|
||||
|
||||
//Assert
|
||||
var rootDirs = rootDirProvider.GetAll();
|
||||
Assert.IsNotEmpty(rootDirs);
|
||||
Assert.Count(1, rootDirs);
|
||||
Assert.AreEqual(path, rootDirs.First().Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateRootDir()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
|
||||
string path = @"C:\TV2";
|
||||
|
||||
//Act
|
||||
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
||||
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
||||
rootDirProvider.Update(new RootDir { Id = 1, Path = path });
|
||||
|
||||
//Assert
|
||||
var rootDirs = rootDirProvider.GetAll();
|
||||
Assert.IsNotEmpty(rootDirs);
|
||||
Assert.Count(1, rootDirs);
|
||||
Assert.AreEqual(path, rootDirs.First().Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveRootDir()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
|
||||
string path = @"C:\TV2";
|
||||
|
||||
//Act
|
||||
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
||||
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
||||
rootDirProvider.Remove(1);
|
||||
|
||||
//Assert
|
||||
var rootDirs = rootDirProvider.GetAll();
|
||||
Assert.Count(0, rootDirs);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRootDir()
|
||||
{
|
||||
//Setup
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
|
||||
int id = 1;
|
||||
string path = @"C:\TV";
|
||||
|
||||
//Act
|
||||
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
||||
rootDirProvider.Add(new RootDir { Id = id, Path = path });
|
||||
|
||||
//Assert
|
||||
var rootDir = rootDirProvider.GetRootDir(id);
|
||||
Assert.AreEqual(1, rootDir.Id);
|
||||
Assert.AreEqual(path, rootDir.Path);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user