1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 02:07:41 +00:00
Sonarr/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs

105 lines
2.5 KiB
C#
Raw Normal View History

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