1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 19:05:55 +00:00
Radarr/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs

102 lines
2.5 KiB
C#
Raw Normal View History

using System.Linq;
2013-02-04 04:18:59 +00:00
using Eloquera.Client;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore
{
[TestFixture]
2013-02-02 20:54:03 +00:00
public class ObjectDatabaseFixture : ObjectDbTest
{
2013-02-04 01:27:34 +00:00
private Series testSeries;
private Episode testEpisode;
[SetUp]
public void SetUp()
{
2013-02-04 00:10:15 +00:00
WithObjectDb();
2013-02-04 01:27:34 +00:00
testSeries = Builder<Series>.CreateNew().Build();
testEpisode = Builder<Episode>.CreateNew().Build();
}
[Test]
public void should_be_able_to_write_to_database()
{
2013-02-04 01:27:34 +00:00
Db.Insert(testSeries);
2013-02-02 20:54:03 +00:00
Db.AsQueryable<Series>().Should().HaveCount(1);
}
[Test]
public void should_not_store_dirty_data_in_cache()
{
2013-02-04 01:27:34 +00:00
Db.Insert(testEpisode);
2013-02-02 20:54:03 +00:00
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
2013-02-04 01:27:34 +00:00
testEpisode.Series = Builder<Series>.CreateNew().Build();
2013-02-02 20:54:03 +00:00
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
}
[Test]
public void should_store_nested_objects()
{
2013-02-04 01:27:34 +00:00
testEpisode.Series = testSeries;
2013-02-04 01:27:34 +00:00
Db.Insert(testEpisode);
2013-02-02 20:54:03 +00:00
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
}
[Test]
public void should_update_nested_objects()
{
2013-02-04 01:27:34 +00:00
testEpisode.Series = Builder<Series>.CreateNew().Build();
2013-02-04 01:27:34 +00:00
Db.Insert(testEpisode);
2013-02-04 01:27:34 +00:00
testEpisode.Series.Title = "UpdatedTitle";
2013-02-04 01:27:34 +00:00
Db.Update(testEpisode);
2013-02-02 20:54:03 +00:00
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
Db.AsQueryable<Episode>().Single().Series.Title.Should().Be("UpdatedTitle");
}
2013-02-04 01:27:34 +00:00
[Test]
public void new_objects_should_get_id()
{
Db.Insert(testSeries);
testSeries.Id.Should().NotBe(0);
}
2013-02-04 04:18:59 +00:00
[Test]
public void should_be_able_to_read_unknow_type()
{
Db.AsQueryable<UnKnowType>().ToList().Should().BeEmpty();
}
}
public class UnKnowType
{
[ID]
public string Id;
public string Field1 { get; set; }
}
}
2013-02-04 01:27:34 +00:00