2013-02-02 19:39:27 +00:00
|
|
|
using System.Linq;
|
2013-02-04 04:18:59 +00:00
|
|
|
using Eloquera.Client;
|
2013-02-02 19:39:27 +00:00
|
|
|
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
|
|
|
{
|
2013-02-04 01:27:34 +00:00
|
|
|
private Series testSeries;
|
|
|
|
private Episode testEpisode;
|
|
|
|
|
|
|
|
|
2013-02-02 19:39:27 +00:00
|
|
|
[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();
|
|
|
|
|
|
|
|
|
2013-02-02 19:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_be_able_to_write_to_database()
|
|
|
|
{
|
2013-02-04 01:27:34 +00:00
|
|
|
Db.Insert(testSeries);
|
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()
|
|
|
|
{
|
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 19:39:27 +00:00
|
|
|
|
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()
|
|
|
|
{
|
2013-02-04 01:27:34 +00:00
|
|
|
testEpisode.Series = testSeries;
|
2013-02-02 20:22:46 +00:00
|
|
|
|
2013-02-04 01:27:34 +00:00
|
|
|
Db.Insert(testEpisode);
|
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()
|
|
|
|
{
|
2013-02-04 01:27:34 +00:00
|
|
|
testEpisode.Series = Builder<Series>.CreateNew().Build();
|
2013-02-02 20:22:46 +00:00
|
|
|
|
2013-02-04 01:27:34 +00:00
|
|
|
Db.Insert(testEpisode);
|
2013-02-02 20:22:46 +00:00
|
|
|
|
2013-02-04 01:27:34 +00:00
|
|
|
testEpisode.Series.Title = "UpdatedTitle";
|
2013-02-02 20:22:46 +00:00
|
|
|
|
2013-02-04 01:27:34 +00:00
|
|
|
Db.Update(testEpisode);
|
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
|
|
|
}
|
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-02 19:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-04 01:27:34 +00:00
|
|
|
|