@ -8,116 +8,85 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.HealthCheck.Checks
namespace NzbDrone.Core.Test.HealthCheck.Checks
{
{
[TestFixture]
[TestFixture]
public class Indexer CheckFixture : CoreTest < Indexer Check>
public class Indexer Search CheckFixture : CoreTest < Indexer Search Check>
{
{
private Mock < IIndexer > _indexerMock ;
private Mock < IIndexer > _indexerMock ;
private void GivenIndexer ( bool supportsRss , bool supportsSearch )
[SetUp]
public void SetUp ( )
{
{
_indexerMock = Mocker . GetMock < IIndexer > ( ) ;
_indexerMock . SetupGet ( s = > s . SupportsRss ) . Returns ( supportsRss ) ;
_indexerMock . SetupGet ( s = > s . SupportsSearch ) . Returns ( supportsSearch ) ;
Mocker . GetMock < IIndexerFactory > ( )
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . GetAvailableProviders ( ) )
. Setup ( s = > s . GetAvailableProviders ( ) )
. Returns ( new List < IIndexer > { _indexerMock . Object } ) ;
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . RssEnabled ( true ) )
. Returns ( new List < IIndexer > ( ) ) ;
. Returns ( new List < IIndexer > ( ) ) ;
Mocker . GetMock < IIndexerFactory > ( )
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . SearchEnabled ( true ) )
. Setup ( s = > s . SearchEnabled ( It . IsAny < bool > ( ) ) )
. Returns ( new List < IIndexer > ( ) ) ;
. Returns ( new List < IIndexer > ( ) ) ;
}
}
private void Given RssEnabled( )
private void Given Indexer( bool supportsRss , bool supportsSearch )
{
{
_indexerMock = Mocker . GetMock < IIndexer > ( ) ;
_indexerMock . SetupGet ( s = > s . SupportsRss ) . Returns ( supportsRss ) ;
_indexerMock . SetupGet ( s = > s . SupportsSearch ) . Returns ( supportsSearch ) ;
Mocker . GetMock < IIndexerFactory > ( )
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . RssEnabled ( true ) )
. Setup ( s = > s . GetAvailableProviders( ) )
. Returns ( new List < IIndexer > { _indexerMock . Object } ) ;
. Returns ( new List < IIndexer > { _indexerMock . Object } ) ;
}
}
private void GivenSearchEnabled ( )
private void GivenSearchEnabled ( )
{
{
Mocker . GetMock < IIndexerFactory > ( )
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . SearchEnabled ( true ) )
. Setup ( s = > s . SearchEnabled ( It . IsAny < bool > ( ) ) )
. Returns ( new List < IIndexer > { _indexerMock . Object } ) ;
. Returns ( new List < IIndexer > { _indexerMock . Object } ) ;
}
}
[Test]
private void GivenSearchFiltered ( )
public void should_return_error_when_not_indexers_are_enabled ( )
{
{
Mocker . GetMock < IIndexerFactory > ( )
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . GetAvailableProviders ( ) )
. Setup ( s = > s . SearchEnabled ( false ) )
. Returns ( new List < IIndexer > ( ) ) ;
. Returns ( new List < IIndexer > { _indexerMock . Object } ) ;
Subject . Check ( ) . ShouldBeError ( ) ;
}
}
[Test]
[Test]
public void should_return_warning_when_ only_enabled_indexer_doesnt_support_search ( )
public void should_return_warning_when_ no_indexer_present ( )
{
{
GivenIndexer ( true , false ) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
}
}
[Test]
[Test]
public void should_return_warning_when_ only_enabled_indexer_doesnt_support_rss ( )
public void should_return_warning_when_ no_search_supported_indexer_present ( )
{
{
GivenIndexer ( false, tru e) ;
GivenIndexer ( true, fals e) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
}
}
[Test]
[Test]
public void should_return_ok_when_ multiple_indexers_are _enabled( )
public void should_return_ok_when_ search_is _enabled( )
{
{
GivenRssEnabled ( ) ;
GivenIndexer ( false , true ) ;
GivenSearchEnabled ( ) ;
var indexer1 = Mocker . GetMock < IIndexer > ( ) ;
indexer1 . SetupGet ( s = > s . SupportsRss ) . Returns ( true ) ;
indexer1 . SetupGet ( s = > s . SupportsSearch ) . Returns ( true ) ;
var indexer2 = new Moq . Mock < IIndexer > ( ) ;
indexer2 . SetupGet ( s = > s . SupportsRss ) . Returns ( true ) ;
indexer2 . SetupGet ( s = > s . SupportsSearch ) . Returns ( false ) ;
Mocker . GetMock < IIndexerFactory > ( )
. Setup ( s = > s . GetAvailableProviders ( ) )
. Returns ( new List < IIndexer > { indexer1 . Object , indexer2 . Object } ) ;
Subject . Check ( ) . ShouldBeOk ( ) ;
}
[Test]
public void should_return_ok_when_indexer_supports_rss_and_search ( )
{
GivenIndexer ( true , true ) ;
GivenRssEnabled ( ) ;
GivenSearchEnabled ( ) ;
GivenSearchEnabled ( ) ;
Subject . Check ( ) . ShouldBeOk ( ) ;
Subject . Check ( ) . ShouldBeOk ( ) ;
}
}
[Test]
[Test]
public void should_return_warning_if_ rss _is_supported_but_disabled( )
public void should_return_warning_if_search_is_supported_but_disabled ( )
{
{
GivenIndexer ( true , true ) ;
GivenIndexer ( false , true ) ;
GivenSearchEnabled ( ) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
}
}
[Test]
[Test]
public void should_return_ warning_if_search_is_supported_but_disabl ed( )
public void should_return_filter_warning_if_search_is_enabled_but_filtered ( )
{
{
GivenIndexer ( tru e, true ) ;
GivenIndexer ( false , true ) ;
Given RssEnabl ed( ) ;
GivenSearchFiltered ( ) ;
Subject . Check ( ) . ShouldBeWarning ( ) ;
Subject . Check ( ) . ShouldBeWarning ( "recent indexer errors" ) ;
}
}
}
}
}
}