Swap to dapper and system.text.json for database backend

This commit is contained in:
ta264
2019-12-15 15:04:42 +00:00
parent 7b17c3e36c
commit d2065bfa1b
155 changed files with 2333 additions and 2340 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
@@ -15,7 +16,7 @@ namespace NzbDrone.Core.Test.Datastore
BasicRepositoryFixture : DbTest<BasicRepository<ScheduledTask>, ScheduledTask>
{
private ScheduledTask _basicType;
private List<ScheduledTask> _basicList;
[SetUp]
public void Setup()
@@ -25,15 +26,28 @@ namespace NzbDrone.Core.Test.Datastore
.With(c => c.Id = 0)
.With(c => c.LastExecution = DateTime.UtcNow)
.Build();
_basicList = Builder<ScheduledTask>
.CreateListOfSize(5)
.All()
.With(x => x.Id = 0)
.BuildList();
}
[Test]
public void should_be_able_to_add()
public void should_be_able_to_insert()
{
Subject.Insert(_basicType);
Subject.All().Should().HaveCount(1);
}
[Test]
public void should_be_able_to_insert_many()
{
Subject.InsertMany(_basicList);
Subject.All().Should().HaveCount(5);
}
[Test]
public void purge_should_delete_all()
{
@@ -47,7 +61,6 @@ namespace NzbDrone.Core.Test.Datastore
}
[Test]
public void should_be_able_to_delete_model()
{
@@ -58,6 +71,16 @@ namespace NzbDrone.Core.Test.Datastore
Subject.All().Should().BeEmpty();
}
[Test]
public void should_be_able_to_delete_many()
{
Subject.InsertMany(_basicList);
Subject.All().Should().HaveCount(5);
Subject.DeleteMany(_basicList.Take(2).ToList());
Subject.All().Should().HaveCount(3);
}
[Test]
public void should_be_able_to_find_by_id()
{
@@ -67,6 +90,64 @@ namespace NzbDrone.Core.Test.Datastore
storeObject.Should().BeEquivalentTo(_basicType, o=>o.IncludingAllRuntimeProperties());
}
[Test]
public void should_be_able_to_find_by_multiple_id()
{
Subject.InsertMany(_basicList);
var storeObject = Subject.Get(_basicList.Take(2).Select(x => x.Id));
storeObject.Should().HaveCount(2);
}
[Test]
public void should_be_able_to_update()
{
Subject.Insert(_basicType);
_basicType.Interval = 999;
Subject.Update(_basicType);
Subject.All().First().Interval.Should().Be(999);
}
[Test]
public void should_be_able_to_update_many()
{
Subject.InsertMany(_basicList);
_basicList.ForEach(x => x.Interval = 999);
Subject.UpdateMany(_basicList);
Subject.All().All(x => x.Interval == 999);
}
[Test]
public void should_be_able_to_update_single_field()
{
Subject.Insert(_basicType);
_basicType.Interval = 999;
_basicType.LastExecution = DateTime.UtcNow;
Subject.SetFields(_basicType, x => x.Interval);
var dbValue = Subject.Single();
dbValue.Interval.Should().Be(999);
dbValue.LastExecution.Should().NotBe(_basicType.LastExecution);
}
[Test]
public void should_be_able_to_update_many_single_field()
{
Subject.InsertMany(_basicList);
_basicList.ForEach(x => x.Interval = 999);
_basicList.ForEach(x => x.LastExecution = DateTime.UtcNow);
Subject.SetFields(_basicList, x => x.Interval);
var dbValue = Subject.All().First();
dbValue.Interval.Should().Be(999);
dbValue.LastExecution.Should().NotBe(_basicType.LastExecution);
}
[Test]
public void should_be_able_to_get_single()
{
@@ -86,7 +167,6 @@ namespace NzbDrone.Core.Test.Datastore
Assert.Throws<ModelNotFoundException>(() => Subject.Get(12));
}
[Test]
public void get_all_with_empty_db_should_return_empty_list()
{
@@ -98,7 +178,6 @@ namespace NzbDrone.Core.Test.Datastore
public void should_be_able_to_call_ToList_on_empty_quariable()
{
Subject.All().ToList().Should().BeEmpty();
}
}
}
}