test: Update some tests to use async/await

pull/56/head
Robert Dailey 2 years ago
parent 67cc4bd98f
commit 3960f24f99

@ -16,7 +16,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors;
public class PersistenceProcessorTest
{
[Test]
public void Custom_formats_are_deleted_if_deletion_option_is_enabled_in_config()
public async Task Custom_formats_are_deleted_if_deletion_option_is_enabled_in_config()
{
var steps = Substitute.For<IPersistenceProcessorSteps>();
var cfApi = Substitute.For<ICustomFormatService>();
@ -30,13 +30,13 @@ public class PersistenceProcessorTest
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
var processor = new PersistenceProcessor(cfApi, qpApi, configProvider, () => steps);
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
await processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
steps.JsonTransactionStep.Received().RecordDeletions(Arg.Is(deletedCfsInCache), Arg.Any<List<JObject>>());
}
[Test]
public void Custom_formats_are_not_deleted_if_deletion_option_is_disabled_in_config()
public async Task Custom_formats_are_not_deleted_if_deletion_option_is_disabled_in_config()
{
var steps = Substitute.For<IPersistenceProcessorSteps>();
var cfApi = Substitute.For<ICustomFormatService>();
@ -50,14 +50,14 @@ public class PersistenceProcessorTest
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
var processor = new PersistenceProcessor(cfApi, qpApi, configProvider, () => steps);
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
await processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
steps.JsonTransactionStep.DidNotReceive()
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());
}
[Test]
public void Different_active_configuration_is_properly_used()
public async Task Different_active_configuration_is_properly_used()
{
var steps = Substitute.For<IPersistenceProcessorSteps>();
var cfApi = Substitute.For<ICustomFormatService>();
@ -71,10 +71,10 @@ public class PersistenceProcessorTest
var processor = new PersistenceProcessor(cfApi, qpApi, configProvider, () => steps);
configProvider.ActiveConfiguration = new RadarrConfiguration {DeleteOldCustomFormats = false};
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
await processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
configProvider.ActiveConfiguration = new RadarrConfiguration {DeleteOldCustomFormats = true};
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
await processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
steps.JsonTransactionStep.Received(1)
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());

@ -18,7 +18,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps;
public class QualityProfileApiPersistenceStepTest
{
[Test]
public void Do_not_invoke_api_if_no_scores_to_update()
public async Task Do_not_invoke_api_if_no_scores_to_update()
{
const string radarrQualityProfileData = @"[{
'name': 'profile1',
@ -56,13 +56,13 @@ public class QualityProfileApiPersistenceStepTest
};
var processor = new QualityProfileApiPersistenceStep();
processor.Process(api, cfScores);
await processor.Process(api, cfScores);
api.DidNotReceive().UpdateQualityProfile(Arg.Any<JObject>(), Arg.Any<int>());
await api.DidNotReceive().UpdateQualityProfile(Arg.Any<JObject>(), Arg.Any<int>());
}
[Test]
public void Invalid_quality_profile_names_are_reported()
public async Task Invalid_quality_profile_names_are_reported()
{
const string radarrQualityProfileData = @"[{'name': 'profile1'}]";
@ -75,14 +75,14 @@ public class QualityProfileApiPersistenceStepTest
};
var processor = new QualityProfileApiPersistenceStep();
processor.Process(api, cfScores);
await processor.Process(api, cfScores);
processor.InvalidProfileNames.Should().Equal("wrong_profile_name");
processor.UpdatedScores.Should().BeEmpty();
}
[Test]
public void Reset_scores_for_unmatched_cfs_if_enabled()
public async Task Reset_scores_for_unmatched_cfs_if_enabled()
{
const string radarrQualityProfileData = @"[{
'name': 'profile1',
@ -120,7 +120,7 @@ public class QualityProfileApiPersistenceStepTest
};
var processor = new QualityProfileApiPersistenceStep();
processor.Process(api, cfScores);
await processor.Process(api, cfScores);
processor.InvalidProfileNames.Should().BeEmpty();
processor.UpdatedScores.Should()
@ -132,13 +132,13 @@ public class QualityProfileApiPersistenceStepTest
new("cf3", 0, FormatScoreUpdateReason.Reset)
});
api.Received().UpdateQualityProfile(
await api.Received().UpdateQualityProfile(
Verify.That<JObject>(j => j["formatItems"]!.Children().Should().HaveCount(3)),
Arg.Any<int>());
}
[Test]
public void Scores_are_set_in_quality_profile()
public async Task Scores_are_set_in_quality_profile()
{
const string radarrQualityProfileData = @"[{
'name': 'profile1',
@ -207,7 +207,7 @@ public class QualityProfileApiPersistenceStepTest
};
var processor = new QualityProfileApiPersistenceStep();
processor.Process(api, cfScores);
await processor.Process(api, cfScores);
var expectedProfileJson = JObject.Parse(@"{
'name': 'profile1',
@ -250,7 +250,7 @@ public class QualityProfileApiPersistenceStepTest
'id': 1
}");
api.Received()
await api.Received()
.UpdateQualityProfile(Verify.That<JObject>(a => a.Should().BeEquivalentTo(expectedProfileJson)), 1);
processor.InvalidProfileNames.Should().BeEmpty();
processor.UpdatedScores.Should()

Loading…
Cancel
Save