public void Updating_overwrites_previous_cf_cache_and_updates_cf_data() { var ctx = new Context(); // Load initial CfCache just to test that it gets replaced var testCfObj = new CustomFormatCache { TrashIdMappings = new List <TrashIdMapping> { new("", "") { CustomFormatId = 5 } } }; ctx.ServiceCache.Load <CustomFormatCache>().Returns(testCfObj); ctx.Persister.Load(); // Update with new cached items var results = new CustomFormatTransactionData(); results.NewCustomFormats.Add(QuickMakeCf("cfname", "trashid", 10)); var customFormatData = new List <ProcessedCustomFormatData> { new("", "trashid", new JObject()) { CacheEntry = new TrashIdMapping("trashid", "cfname", 10) } }; ctx.Persister.Update(customFormatData); ctx.Persister.CfCache.Should().BeEquivalentTo(new CustomFormatCache { TrashIdMappings = new List <TrashIdMapping> { customFormatData[0].CacheEntry ! } });
public void Updates_using_combination_of_id_and_name(int?id, string guideCfName) { const string radarrCfData = @"{ 'id': 1, 'name': 'cf1', 'specifications': [{ 'name': 'spec1', 'fields': [{ 'name': 'value', 'value': 'value1' }] }] }"; var guideCfData = JObject.Parse(@"{ 'name': 'cf1', 'specifications': [{ 'name': 'spec1', 'new': 'valuenew', 'fields': { 'value': 'value2' } }] }"); var cacheEntry = id != null ? new TrashIdMapping("", "") { CustomFormatId = id.Value } : null; var guideCfs = new List <ProcessedCustomFormatData> { new(guideCfName, "", guideCfData) { CacheEntry = cacheEntry } }; var processor = new JsonTransactionStep(); processor.Process(guideCfs, new[] { JObject.Parse(radarrCfData) }); var expectedTransactions = new CustomFormatTransactionData(); expectedTransactions.UpdatedCustomFormats.Add(guideCfs[0]); processor.Transactions.Should().BeEquivalentTo(expectedTransactions); const string expectedJsonData = @"{ 'id': 1, 'name': 'cf1', 'specifications': [{ 'name': 'spec1', 'new': 'valuenew', 'fields': [{ 'name': 'value', 'value': 'value2' }] }] }"; processor.Transactions.UpdatedCustomFormats.First().Json.Should() .BeEquivalentTo(JObject.Parse(expectedJsonData), op => op.Using(new JsonEquivalencyStep())); }
public async Task Process(ICustomFormatService api, CustomFormatTransactionData transactions) { foreach (var cf in transactions.NewCustomFormats) { await api.CreateCustomFormat(cf); } foreach (var cf in transactions.UpdatedCustomFormats) { await api.UpdateCustomFormat(cf); } foreach (var cfId in transactions.DeletedCustomFormatIds) { await api.DeleteCustomFormat(cfId.CustomFormatId); } }
private void PrintApiStatistics(CustomFormatTransactionData transactions) { var created = transactions.NewCustomFormats; if (created.Count > 0) { Log.Information("Created {Count} New Custom Formats: {CustomFormats}", created.Count, created.Select(r => r.Name)); } var updated = transactions.UpdatedCustomFormats; if (updated.Count > 0) { Log.Information("Updated {Count} Existing Custom Formats: {CustomFormats}", updated.Count, updated.Select(r => r.Name)); } var skipped = transactions.UnchangedCustomFormats; if (skipped.Count > 0) { Log.Debug("Skipped {Count} Custom Formats that did not change: {CustomFormats}", skipped.Count, skipped.Select(r => r.Name)); } var deleted = transactions.DeletedCustomFormatIds; if (deleted.Count > 0) { Log.Information("Deleted {Count} Custom Formats: {CustomFormats}", deleted.Count, deleted.Select(r => r.CustomFormatName)); } var totalCount = created.Count + updated.Count; if (totalCount > 0) { Log.Information("Total of {Count} custom formats synced to Radarr", totalCount); } else { Log.Information("All custom formats are already up to date!"); } }
public async Task All_api_operations_behave_normally() { var transactions = new CustomFormatTransactionData(); transactions.NewCustomFormats.Add(QuickMakeCf("cfname1", "trashid1", 1)); transactions.UpdatedCustomFormats.Add(QuickMakeCf("cfname2", "trashid2", 2)); transactions.UnchangedCustomFormats.Add(QuickMakeCf("cfname3", "trashid3", 3)); transactions.DeletedCustomFormatIds.Add(new TrashIdMapping("trashid4", "cfname4") { CustomFormatId = 4 }); var api = Substitute.For <ICustomFormatService>(); var processor = new CustomFormatApiPersistenceStep(); await processor.Process(api, transactions); Received.InOrder(() => { api.CreateCustomFormat(transactions.NewCustomFormats.First()); api.UpdateCustomFormat(transactions.UpdatedCustomFormats.First()); api.DeleteCustomFormat(4); }); }