/src/NzbDrone.Core.Test/Datastore/Migration/158_cdh_per_downloadclientFixture.cs

https://github.com/NzbDrone/NzbDrone · C# · 119 lines · 108 code · 11 blank · 0 comment · 0 complexity · 7bce5b33fee122a32919afcceaa42226 MD5 · raw file

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using FluentAssertions;
  4. using Newtonsoft.Json.Linq;
  5. using NUnit.Framework;
  6. using NzbDrone.Common.Serializer;
  7. using NzbDrone.Core.Datastore.Migration;
  8. using NzbDrone.Core.Download.Clients.RTorrent;
  9. using NzbDrone.Core.Test.Framework;
  10. namespace NzbDrone.Core.Test.Datastore.Migration
  11. {
  12. [TestFixture]
  13. public class cdh_per_downloadclientFixture : MigrationTest<cdh_per_downloadclient>
  14. {
  15. [Test]
  16. public void should_set_cdh_to_enabled()
  17. {
  18. var db = WithMigrationTestDb(c =>
  19. {
  20. c.Insert.IntoTable("DownloadClients").Row(new
  21. {
  22. Enable = 1,
  23. Name = "Deluge",
  24. Implementation = "Deluge",
  25. Priority = 1,
  26. Settings = new DelugeSettings85
  27. {
  28. Host = "127.0.0.1",
  29. TvCategory = "abc",
  30. UrlBase = "/my/"
  31. }.ToJson(),
  32. ConfigContract = "DelugeSettings"
  33. });
  34. });
  35. var items = db.Query<DownloadClientDefinition158>("SELECT * FROM DownloadClients");
  36. items.Should().HaveCount(1);
  37. items.First().RemoveCompletedDownloads.Should().BeFalse();
  38. items.First().RemoveFailedDownloads.Should().BeTrue();
  39. }
  40. [Test]
  41. public void should_set_cdh_to_disabled_when_globally_disabled()
  42. {
  43. var db = WithMigrationTestDb(c =>
  44. {
  45. c.Insert.IntoTable("Config").Row(new
  46. {
  47. Key = "removecompleteddownloads",
  48. Value = "True"
  49. });
  50. c.Insert.IntoTable("DownloadClients").Row(new
  51. {
  52. Enable = 1,
  53. Name = "Deluge",
  54. Implementation = "Deluge",
  55. Priority = 1,
  56. Settings = new DelugeSettings85
  57. {
  58. Host = "127.0.0.1",
  59. TvCategory = "abc",
  60. UrlBase = "/my/"
  61. }.ToJson(),
  62. ConfigContract = "DelugeSettings"
  63. });
  64. });
  65. var items = db.Query<DownloadClientDefinition158>("SELECT * FROM DownloadClients");
  66. items.Should().HaveCount(1);
  67. items.First().RemoveCompletedDownloads.Should().BeTrue();
  68. items.First().RemoveFailedDownloads.Should().BeTrue();
  69. }
  70. [Test]
  71. public void should_disable_remove_for_existing_rtorrent()
  72. {
  73. var db = WithMigrationTestDb(c =>
  74. {
  75. c.Insert.IntoTable("DownloadClients").Row(new
  76. {
  77. Enable = 1,
  78. Name = "RTorrent",
  79. Implementation = "RTorrent",
  80. Priority = 1,
  81. Settings = new RTorrentSettings
  82. {
  83. Host = "127.0.0.1",
  84. TvCategory = "abc",
  85. UrlBase = "/my/"
  86. }.ToJson(),
  87. ConfigContract = "RTorrentSettings"
  88. });
  89. });
  90. var items = db.Query<DownloadClientDefinition158>("SELECT * FROM DownloadClients");
  91. items.Should().HaveCount(1);
  92. items.First().RemoveCompletedDownloads.Should().BeFalse();
  93. items.First().RemoveFailedDownloads.Should().BeTrue();
  94. }
  95. }
  96. public class DownloadClientDefinition158
  97. {
  98. public int Id { get; set; }
  99. public bool Enable { get; set; }
  100. public int Priority { get; set; }
  101. public string Name { get; set; }
  102. public string Implementation { get; set; }
  103. public JObject Settings { get; set; }
  104. public string ConfigContract { get; set; }
  105. public bool RemoveCompletedDownloads { get; set; }
  106. public bool RemoveFailedDownloads { get; set; }
  107. }
  108. }