sonarr-repo-only/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs

79 lines
2.1 KiB
C#
Raw Normal View History

using System.Linq;
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
{
[SetUp]
public void SetUp()
{
2013-02-04 00:10:15 +00:00
WithObjectDb();
}
[Test]
public void should_be_able_to_write_to_database()
{
var series = Builder<Series>.CreateNew().Build();
2013-02-02 20:54:03 +00:00
Db.Create(series);
2013-02-02 20:54:03 +00:00
Db.AsQueryable<Series>().Should().HaveCount(1);
}
[Test]
public void should_not_store_dirty_data_in_cache()
{
var episode = Builder<Episode>.CreateNew().Build();
2013-02-02 20:54:03 +00:00
//Save series without episode attached
2013-02-02 20:54:03 +00:00
Db.Create(episode);
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
episode.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()
{
var episode = Builder<Episode>.CreateNew().Build();
episode.Series = Builder<Series>.CreateNew().Build();
2013-02-02 20:54:03 +00:00
Db.Create(episode);
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()
{
var episode = Builder<Episode>.CreateNew().Build();
episode.Series = Builder<Series>.CreateNew().Build();
2013-02-02 20:54:03 +00:00
Db.Create(episode);
episode.Series.Title = "UpdatedTitle";
2013-02-04 00:10:15 +00:00
Db.Update(episode);
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");
}
}
}