2013-02-17 06:35:52 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-03-25 07:13:53 +01:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2013-02-17 06:35:52 +01:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Datastore
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
2013-03-25 07:13:53 +01:00
|
|
|
|
public class
|
2013-05-09 08:38:20 +02:00
|
|
|
|
BasicRepositoryFixture : DbTest<BasicRepository<ScheduledTask>, ScheduledTask>
|
2013-02-17 06:35:52 +01:00
|
|
|
|
{
|
2013-05-09 08:38:20 +02:00
|
|
|
|
private ScheduledTask _basicType;
|
2013-02-17 06:35:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-05-09 08:38:20 +02:00
|
|
|
|
_basicType = Builder<ScheduledTask>
|
2013-03-05 02:47:51 +01:00
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(c => c.Id = 0)
|
2013-05-11 08:16:10 +02:00
|
|
|
|
.With(c => c.LastExecution = DateTime.UtcNow)
|
2013-03-05 02:47:51 +01:00
|
|
|
|
.Build();
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_add()
|
|
|
|
|
{
|
2013-03-25 04:51:32 +01:00
|
|
|
|
Subject.Insert(_basicType);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
Subject.All().Should().HaveCount(1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-09 08:38:20 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void purge_should_delete_all()
|
|
|
|
|
{
|
|
|
|
|
Subject.InsertMany(Builder<ScheduledTask>.CreateListOfSize(10).BuildListOfNew());
|
|
|
|
|
|
|
|
|
|
AllStoredModels.Should().HaveCount(10);
|
|
|
|
|
|
|
|
|
|
Subject.Purge();
|
|
|
|
|
|
|
|
|
|
AllStoredModels.Should().BeEmpty();
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-17 06:35:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_delete_model()
|
|
|
|
|
{
|
2013-03-25 04:51:32 +01:00
|
|
|
|
Subject.Insert(_basicType);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
Subject.All().Should().HaveCount(1);
|
|
|
|
|
|
2013-03-25 04:51:32 +01:00
|
|
|
|
Subject.Delete(_basicType.Id);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
Subject.All().Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_find_by_id()
|
|
|
|
|
{
|
2013-03-25 04:51:32 +01:00
|
|
|
|
Subject.Insert(_basicType);
|
|
|
|
|
Subject.Get(_basicType.Id)
|
2013-03-05 02:47:51 +01:00
|
|
|
|
.ShouldHave()
|
|
|
|
|
.AllProperties()
|
2013-03-25 04:51:32 +01:00
|
|
|
|
.EqualTo(_basicType);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 06:27:49 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_get_single()
|
|
|
|
|
{
|
|
|
|
|
Subject.Insert(_basicType);
|
|
|
|
|
Subject.SingleOrDefault().Should().NotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-09 08:38:20 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void single_or_default_on_empty_table_should_return_null()
|
|
|
|
|
{
|
|
|
|
|
Subject.SingleOrDefault().Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-17 06:35:52 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void getting_model_with_invalid_id_should_throw()
|
|
|
|
|
{
|
2013-07-10 00:06:30 +02:00
|
|
|
|
Assert.Throws<ModelNotFoundException>(() => Subject.Get(12));
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void get_all_with_empty_db_should_return_empty_list()
|
|
|
|
|
{
|
|
|
|
|
Subject.All().Should().BeEmpty();
|
|
|
|
|
}
|
2013-03-05 02:47:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_call_ToList_on_empty_quariable()
|
|
|
|
|
{
|
|
|
|
|
Subject.All().ToList().Should().BeEmpty();
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
}
|