mirror of https://github.com/Sonarr/Sonarr
elq id is now ignored by petapoco.
This commit is contained in:
parent
c6fa3cc02b
commit
eb90040dd6
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Eloquera.Client;
|
using Eloquera.Client;
|
||||||
|
@ -41,6 +42,20 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
Db.AsQueryable<Series>().Should().HaveCount(1);
|
Db.AsQueryable<Series>().Should().HaveCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void double_insert_should_fail()
|
||||||
|
{
|
||||||
|
Db.Insert(testSeries);
|
||||||
|
Assert.Throws<InvalidOperationException>(() => Db.Insert(testSeries));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void update_item_with_root_index_0_should_faile()
|
||||||
|
{
|
||||||
|
testSeries.Id = 0;
|
||||||
|
Assert.Throws<InvalidOperationException>(() => Db.Update(testSeries));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_not_store_dirty_data_in_cache()
|
public void should_not_store_dirty_data_in_cache()
|
||||||
{
|
{
|
||||||
|
@ -92,11 +107,10 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void new_existing_object_should_get_new_id()
|
public void new_object_should_get_new_id()
|
||||||
{
|
{
|
||||||
testSeries.Id = 0;
|
testSeries.Id = 0;
|
||||||
Db.Insert(testSeries);
|
Db.Insert(testSeries);
|
||||||
Db.Insert(testSeries);
|
|
||||||
|
|
||||||
Db.AsQueryable<Series>().Should().HaveCount(1);
|
Db.AsQueryable<Series>().Should().HaveCount(1);
|
||||||
testSeries.Id.Should().Be(1);
|
testSeries.Id.Should().Be(1);
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace NzbDrone.Core.Datastore
|
||||||
[ID]
|
[ID]
|
||||||
private long _eqId;
|
private long _eqId;
|
||||||
|
|
||||||
|
[PetaPoco.Ignore]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,23 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public T Insert<T>(T obj) where T : BaseRepositoryModel
|
public T Insert<T>(T obj) where T : BaseRepositoryModel
|
||||||
{
|
{
|
||||||
|
if (obj.Id != 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Attempted to insert object with existing ID as new object");
|
||||||
|
}
|
||||||
|
|
||||||
|
_idService.EnsureIds(obj, new HashSet<object>());
|
||||||
|
Db.Store(obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Update<T>(T obj) where T : BaseRepositoryModel
|
||||||
|
{
|
||||||
|
if (obj.Id == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Attempted to update object without ID");
|
||||||
|
}
|
||||||
|
|
||||||
_idService.EnsureIds(obj, new HashSet<object>());
|
_idService.EnsureIds(obj, new HashSet<object>());
|
||||||
Db.Store(obj);
|
Db.Store(obj);
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -36,24 +53,23 @@ namespace NzbDrone.Core.Datastore
|
||||||
return DoMany(objects, Insert);
|
return DoMany(objects, Insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Update<T>(T obj)
|
public IList<T> UpdateMany<T>(IList<T> objects) where T : BaseRepositoryModel
|
||||||
{
|
|
||||||
Db.Store(obj);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IList<T> UpdateMany<T>(IList<T> objects)
|
|
||||||
{
|
{
|
||||||
_idService.EnsureIds(objects, new HashSet<object>());
|
_idService.EnsureIds(objects, new HashSet<object>());
|
||||||
return DoMany(objects, Update);
|
return DoMany(objects, Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete<T>(T obj) where T : new()
|
public void Delete<T>(T obj) where T : BaseRepositoryModel
|
||||||
{
|
{
|
||||||
|
if (obj.Id == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Attempted to delete an object without an ID");
|
||||||
|
}
|
||||||
|
|
||||||
Db.Delete(obj);
|
Db.Delete(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteMany<T>(IEnumerable<T> objects) where T : new()
|
public void DeleteMany<T>(IEnumerable<T> objects) where T : BaseRepositoryModel
|
||||||
{
|
{
|
||||||
foreach (var o in objects)
|
foreach (var o in objects)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +77,7 @@ namespace NzbDrone.Core.Datastore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function)
|
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function) where T : BaseRepositoryModel
|
||||||
{
|
{
|
||||||
return objects.Select(function).ToList();
|
return objects.Select(function).ToList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore.PetaPoco
|
namespace PetaPoco
|
||||||
{
|
{
|
||||||
public class EpisodeSeasonRelator
|
public class EpisodeSeasonRelator
|
||||||
{
|
{
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue