2013-02-02 19:39:27 +00:00
|
|
|
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
|
2013-02-02 19:39:27 +00:00
|
|
|
{
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
2013-02-04 00:10:15 +00:00
|
|
|
WithObjectDb();
|
2013-02-02 19:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[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 19:39:27 +00:00
|
|
|
|
|
|
|
|
2013-02-02 20:54:03 +00:00
|
|
|
Db.AsQueryable<Series>().Should().HaveCount(1);
|
2013-02-02 19:39:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_store_dirty_data_in_cache()
|
|
|
|
{
|
|
|
|
var episode = Builder<Episode>.CreateNew().Build();
|
2013-02-02 20:54:03 +00:00
|
|
|
|
2013-02-02 19:39:27 +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();
|
|
|
|
|
2013-02-02 19:39:27 +00:00
|
|
|
episode.Series = Builder<Series>.CreateNew().Build();
|
|
|
|
|
2013-02-02 20:54:03 +00:00
|
|
|
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
|
2013-02-02 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[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:22:46 +00:00
|
|
|
|
2013-02-02 20:54:03 +00:00
|
|
|
Db.AsQueryable<Episode>().Should().HaveCount(1);
|
|
|
|
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
|
2013-02-02 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[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);
|
2013-02-02 20:22:46 +00:00
|
|
|
|
|
|
|
episode.Series.Title = "UpdatedTitle";
|
|
|
|
|
2013-02-04 00:10:15 +00:00
|
|
|
Db.Update(episode);
|
2013-02-02 19:39:27 +00:00
|
|
|
|
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-02 19:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|