mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
post grab notification and updates are now using the new EventAggregator
This commit is contained in:
parent
13658e3c6d
commit
554924a522
40 changed files with 670 additions and 482 deletions
34
NzbDrone.Core.Test/Configuration/ConfigCachingFixture.cs
Normal file
34
NzbDrone.Core.Test/Configuration/ConfigCachingFixture.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Test.Configuration
|
||||
{
|
||||
[TestFixture]
|
||||
public class ConfigCachingFixture : CoreTest<ConfigService>
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IConfigRepository>().Setup(c => c.All())
|
||||
.Returns(new List<Config> { new Config { Key = "Key1", Value = "Value1" } });
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_value_more_than_once_should_hit_db_once()
|
||||
{
|
||||
Subject.GetValue("Key1", null).Should().Be("Value1");
|
||||
Subject.GetValue("Key1", null).Should().Be("Value1");
|
||||
Subject.GetValue("Key1", null).Should().Be("Value1");
|
||||
|
||||
Mocker.GetMock<IConfigRepository>().Verify(c => c.All(), Times.Once());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
183
NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs
Normal file
183
NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs
Normal file
|
@ -0,0 +1,183 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Configuration
|
||||
{
|
||||
[TestFixture]
|
||||
public class ConfigServiceFixture : ObjectDbTest<ConfigService, Config>
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Mocker.Resolve<IConfigRepository, ConfigRepository>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Add_new_value_to_database()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
const string value = "MY_VALUE";
|
||||
|
||||
Subject.SetValue(key, value);
|
||||
Subject.GetValue(key, "").Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_value_from_database()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
const string value = "MY_VALUE";
|
||||
|
||||
|
||||
Db.Insert(new Config { Key = key, Value = value });
|
||||
Db.Insert(new Config { Key = "Other Key", Value = "OtherValue" });
|
||||
|
||||
var result = Subject.GetValue(key, "");
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Get_value_should_return_default_when_no_value()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
const string value = "MY_VALUE";
|
||||
|
||||
var result = Subject.GetValue(key, value);
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void New_value_should_update_old_value_new_value()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
const string originalValue = "OLD_VALUE";
|
||||
const string newValue = "NEW_VALUE";
|
||||
|
||||
Db.Insert(new Config { Key = key, Value = originalValue });
|
||||
|
||||
//Act
|
||||
Subject.SetValue(key, newValue);
|
||||
var result = Subject.GetValue(key, "");
|
||||
|
||||
//Assert
|
||||
result.Should().Be(newValue);
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void New_value_should_update_old_value_same_value()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
const string value = "OLD_VALUE";
|
||||
|
||||
Subject.SetValue(key, value);
|
||||
Subject.SetValue(key, value);
|
||||
var result = Subject.GetValue(key, "");
|
||||
|
||||
result.Should().Be(value);
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_value_with_persist_should_store_default_value()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
string value = Guid.NewGuid().ToString();
|
||||
|
||||
Subject.GetValue(key, value, persist: true).Should().Be(value);
|
||||
Subject.GetValue(key, string.Empty).Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_value_with_out_persist_should_not_store_default_value()
|
||||
{
|
||||
const string key = "MY_KEY";
|
||||
string value1 = Guid.NewGuid().ToString();
|
||||
string value2 = Guid.NewGuid().ToString();
|
||||
|
||||
Subject.GetValue(key, value1).Should().Be(value1);
|
||||
Subject.GetValue(key, value2).Should().Be(value2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void uguid_should_only_be_set_once()
|
||||
{
|
||||
var guid1 = Subject.UGuid;
|
||||
var guid2 = Subject.UGuid;
|
||||
|
||||
guid1.Should().Be(guid2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void uguid_should_return_valid_result_on_first_call()
|
||||
{
|
||||
var guid = Subject.UGuid;
|
||||
guid.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void updating_a_vakye_should_update_its_value()
|
||||
{
|
||||
Subject.SabHost = "Test";
|
||||
Subject.SabHost.Should().Be("Test");
|
||||
|
||||
Subject.SabHost = "Test2";
|
||||
Subject.SabHost.Should().Be("Test2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Description("This test will use reflection to ensure each config property read/writes to a unique key")]
|
||||
public void config_properties_should_write_and_read_using_same_key()
|
||||
{
|
||||
var configProvider = Subject;
|
||||
var allProperties = typeof(ConfigService).GetProperties().Where(p => p.GetSetMethod() != null).ToList();
|
||||
|
||||
|
||||
//Act
|
||||
foreach (var propertyInfo in allProperties)
|
||||
{
|
||||
object value = null;
|
||||
|
||||
if (propertyInfo.PropertyType == typeof(string))
|
||||
{
|
||||
value = new Guid().ToString();
|
||||
}
|
||||
else if (propertyInfo.PropertyType == typeof(int))
|
||||
{
|
||||
value = DateTime.Now.Millisecond;
|
||||
}
|
||||
else if (propertyInfo.PropertyType == typeof(bool))
|
||||
{
|
||||
value = true;
|
||||
}
|
||||
else if (propertyInfo.PropertyType.BaseType == typeof(Enum))
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
propertyInfo.GetSetMethod().Invoke(configProvider, new[] { value });
|
||||
var returnValue = propertyInfo.GetGetMethod().Invoke(configProvider, null);
|
||||
|
||||
if (propertyInfo.PropertyType.BaseType == typeof(Enum))
|
||||
{
|
||||
returnValue = (int)returnValue;
|
||||
}
|
||||
|
||||
returnValue.Should().Be(value, propertyInfo.Name);
|
||||
}
|
||||
|
||||
AllStoredModels.Should()
|
||||
.HaveSameCount(allProperties, "two different properties are writing to the same key in db. Copy/Past fail.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue