mirror of https://github.com/lidarr/Lidarr
Fixed: Saving settings changes
This commit is contained in:
parent
c2b9504b15
commit
c8a0f9fa7a
|
@ -53,7 +53,7 @@ namespace NzbDrone.Core.Test.Configuration
|
||||||
|
|
||||||
private void AssertUpsert(string key, object value)
|
private void AssertUpsert(string key, object value)
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IConfigRepository>().Verify(c => c.Upsert(It.Is<Config>(v => v.Key == key.ToLowerInvariant() && v.Value == value.ToString())));
|
Mocker.GetMock<IConfigRepository>().Verify(c => c.Upsert(key.ToLowerInvariant(), value.ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -66,16 +66,14 @@ namespace NzbDrone.Core.Test.Configuration
|
||||||
var keys = new List<string>();
|
var keys = new List<string>();
|
||||||
var values = new List<Config>();
|
var values = new List<Config>();
|
||||||
|
|
||||||
Mocker.GetMock<IConfigRepository>().Setup(c => c.Upsert(It.IsAny<Config>())).Callback<Config>(config =>
|
Mocker.GetMock<IConfigRepository>().Setup(c => c.Upsert(It.IsAny<string>(), It.IsAny<string>())).Callback<string, string>((key, value) =>
|
||||||
{
|
{
|
||||||
keys.Add(config.Key);
|
keys.Add(key);
|
||||||
values.Add(config);
|
values.Add(new Config { Key = key, Value = value });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Mocker.GetMock<IConfigRepository>().Setup(c => c.All()).Returns(values);
|
Mocker.GetMock<IConfigRepository>().Setup(c => c.All()).Returns(values);
|
||||||
|
|
||||||
|
|
||||||
foreach (var propertyInfo in allProperties)
|
foreach (var propertyInfo in allProperties)
|
||||||
{
|
{
|
||||||
object value = null;
|
object value = null;
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
public interface IConfigRepository : IBasicRepository<Config>
|
public interface IConfigRepository : IBasicRepository<Config>
|
||||||
{
|
{
|
||||||
Config Get(string key);
|
Config Get(string key);
|
||||||
|
Config Upsert(string key, string value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigRepository : BasicRepository<Config>, IConfigRepository
|
public class ConfigRepository : BasicRepository<Config>, IConfigRepository
|
||||||
|
@ -23,5 +23,19 @@ namespace NzbDrone.Core.Configuration
|
||||||
{
|
{
|
||||||
return Query.Where(c => c.Key == key).SingleOrDefault();
|
return Query.Where(c => c.Key == key).SingleOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Config Upsert(string key, string value)
|
||||||
|
{
|
||||||
|
var dbValue = Get(key);
|
||||||
|
|
||||||
|
if (dbValue == null)
|
||||||
|
{
|
||||||
|
return Insert(new Config {Key = key, Value = value});
|
||||||
|
}
|
||||||
|
|
||||||
|
dbValue.Value = value;
|
||||||
|
|
||||||
|
return Update(dbValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -376,7 +376,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
key = key.ToLowerInvariant();
|
key = key.ToLowerInvariant();
|
||||||
|
|
||||||
_logger.Trace("Writing Setting to database. Key:'{0}' Value:'{1}'", key, value);
|
_logger.Trace("Writing Setting to database. Key:'{0}' Value:'{1}'", key, value);
|
||||||
_repository.Upsert(new Config {Key = key, Value = value});
|
_repository.Upsert(key, value);
|
||||||
|
|
||||||
ClearCache();
|
ClearCache();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue