parent
efc4455d92
commit
2424d28015
@ -0,0 +1,68 @@
|
||||
using AutoFixture.NUnit3;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Infrastructure;
|
||||
using FluentAssertions;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using TestLibrary.AutoFixture;
|
||||
using Trash.Command;
|
||||
using TrashLib.Sonarr;
|
||||
|
||||
namespace Trash.Tests.Command;
|
||||
|
||||
[TestFixture]
|
||||
[Parallelizable(ParallelScope.All)]
|
||||
public class SonarrCommandTest
|
||||
{
|
||||
[Test, AutoMockData]
|
||||
public async Task List_terms_without_value_fails(
|
||||
IConsole console,
|
||||
SonarrCommand sut)
|
||||
{
|
||||
// When `--list-terms` is specified on the command line without a value, it gets a `null` value assigned.
|
||||
sut.ListTerms = null;
|
||||
|
||||
var act = () => sut.ExecuteAsync(console).AsTask();
|
||||
|
||||
await act.Should().ThrowAsync<CommandException>();
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public async Task List_terms_with_empty_value_fails(
|
||||
IConsole console,
|
||||
SonarrCommand sut)
|
||||
{
|
||||
// If the user specifies a blank string as the value, it should still fail.
|
||||
sut.ListTerms = "";
|
||||
|
||||
var act = () => sut.ExecuteAsync(console).AsTask();
|
||||
|
||||
await act.Should().ThrowAsync<CommandException>();
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public async Task List_terms_uses_specified_trash_id(
|
||||
[Frozen] IReleaseProfileLister lister,
|
||||
IConsole console,
|
||||
SonarrCommand sut)
|
||||
{
|
||||
sut.ListTerms = "some_id";
|
||||
|
||||
await sut.ExecuteAsync(console);
|
||||
|
||||
lister.Received().ListTerms("some_id");
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public async Task List_release_profiles_is_invoked(
|
||||
[Frozen] IReleaseProfileLister lister,
|
||||
IConsole console,
|
||||
SonarrCommand sut)
|
||||
{
|
||||
sut.ListReleaseProfiles = true;
|
||||
|
||||
await sut.ExecuteAsync(console);
|
||||
|
||||
lister.Received().ListReleaseProfiles();
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using AutoFixture.NUnit3;
|
||||
using CliFx.Infrastructure;
|
||||
using FluentAssertions;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using TestLibrary.AutoFixture;
|
||||
using TrashLib.Sonarr;
|
||||
using TrashLib.Sonarr.ReleaseProfile;
|
||||
using TrashLib.Sonarr.ReleaseProfile.Guide;
|
||||
|
||||
namespace TrashLib.Tests.Sonarr;
|
||||
|
||||
[TestFixture]
|
||||
[Parallelizable(ParallelScope.All)]
|
||||
public class ReleaseProfileListerTest
|
||||
{
|
||||
[Test, AutoMockData]
|
||||
public void Release_profiles_appear_in_console_output(
|
||||
[Frozen] ISonarrGuideService guide,
|
||||
[Frozen(Matching.ImplementedInterfaces)] FakeInMemoryConsole console,
|
||||
ReleaseProfileLister sut)
|
||||
{
|
||||
var testData = new[]
|
||||
{
|
||||
new ReleaseProfileData {Name = "First", TrashId = "123"},
|
||||
new ReleaseProfileData {Name = "Second", TrashId = "456"}
|
||||
};
|
||||
|
||||
guide.GetReleaseProfileData().Returns(testData);
|
||||
|
||||
sut.ListReleaseProfiles();
|
||||
|
||||
console.ReadOutputString().Should().ContainAll(
|
||||
testData.SelectMany(x => new[] {x.Name, x.TrashId}));
|
||||
}
|
||||
|
||||
[Test, AutoMockData]
|
||||
public void Terms_appear_in_console_output(
|
||||
[Frozen] ISonarrGuideService guide,
|
||||
[Frozen(Matching.ImplementedInterfaces)] FakeInMemoryConsole console,
|
||||
ReleaseProfileLister sut)
|
||||
{
|
||||
var requiredData = new[]
|
||||
{
|
||||
new TermData {Name = "First", TrashId = "111", Term = "term1"},
|
||||
new TermData {Name = "Second", TrashId = "222", Term = "term2"}
|
||||
};
|
||||
|
||||
var ignoredData = new[]
|
||||
{
|
||||
new TermData {Name = "Third", TrashId = "333", Term = "term3"},
|
||||
new TermData {Name = "Fourth", TrashId = "444", Term = "term4"}
|
||||
};
|
||||
|
||||
var preferredData = new[]
|
||||
{
|
||||
new TermData {Name = "Fifth", TrashId = "555", Term = "term5"},
|
||||
new TermData {Name = "Sixth", TrashId = "666", Term = "term6"}
|
||||
};
|
||||
|
||||
guide.GetUnfilteredProfileById(Arg.Any<string>()).Returns(new ReleaseProfileData
|
||||
{
|
||||
Name = "Release Profile",
|
||||
TrashId = "098",
|
||||
Required = requiredData,
|
||||
Ignored = ignoredData,
|
||||
Preferred = new PreferredTermData[]
|
||||
{
|
||||
new() {Score = 100, Terms = preferredData}
|
||||
}
|
||||
});
|
||||
|
||||
sut.ListTerms("098");
|
||||
|
||||
var expectedOutput = new[]
|
||||
{
|
||||
requiredData.SelectMany(x => new[] {x.Name, x.TrashId}),
|
||||
ignoredData.SelectMany(x => new[] {x.Name, x.TrashId}),
|
||||
preferredData.SelectMany(x => new[] {x.Name, x.TrashId})
|
||||
};
|
||||
|
||||
console.ReadOutputString().Should().ContainAll(expectedOutput.SelectMany(x => x));
|
||||
}
|
||||
|
||||
|
||||
[Test, AutoMockData]
|
||||
public void Release_profile_trash_id_is_used_to_look_up_data(
|
||||
[Frozen] ISonarrGuideService guide,
|
||||
ReleaseProfileLister sut)
|
||||
{
|
||||
sut.ListTerms("098");
|
||||
guide.Received().GetUnfilteredProfileById("098");
|
||||
}
|
||||
}
|
Loading…
Reference in new issue