Sonarr/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs

137 lines
4.4 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
2013-03-26 07:17:46 +00:00
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.Datastore
{
[TestFixture]
2013-03-26 07:17:46 +00:00
public class DatabaseRelationshipFixture : DbTest
{
2013-05-03 04:40:22 +00:00
/* [Test]
[Explicit]
public void benchmark()
{
var series = Builder<Series>.CreateNew()
.With(c => c.Id = 0)
.Build();
2013-05-03 04:40:22 +00:00
Marr.Data.MapRepository.Instance.EnableTraceLogging = false;
2013-05-03 04:40:22 +00:00
Db.Insert(series);
2013-05-03 04:40:22 +00:00
var covers = Builder<MediaCover.MediaCover>.CreateListOfSize(5)
.All()
.With(c => c.SeriesId = series.Id)
.With(c => c.Id = 0)
.Build()
.ToList();
2013-05-03 04:40:22 +00:00
Db.InsertMany(covers);
2013-05-03 04:40:22 +00:00
var loadedSeries = Db.Single<Series>();
2013-05-03 04:40:22 +00:00
var sw = Stopwatch.StartNew();
for (int i = 0; i < 10000; i++)
{
loadedSeries = Db.Single<Series>();
var list = loadedSeries.Covers.Value;
}
2013-05-03 04:40:22 +00:00
sw.Stop();
2013-05-03 04:40:22 +00:00
Console.WriteLine(sw.Elapsed);
2013-05-03 04:40:22 +00:00
loadedSeries.Covers.Value.Should().HaveSameCount(covers);
}
2013-05-03 04:40:22 +00:00
[Test]
public void one_to_many()
{
var series = Builder<Series>.CreateNew()
.With(c => c.Id = 0)
.Build();
2013-05-03 04:40:22 +00:00
Db.Insert(series);
2013-05-03 04:40:22 +00:00
var covers = Builder<MediaCover.MediaCover>.CreateListOfSize(5)
.All()
.With(c => c.SeriesId = series.Id)
.With(c => c.Id = 0)
.Build()
.ToList();
2013-05-03 04:40:22 +00:00
Db.InsertMany(covers);
2013-05-03 04:40:22 +00:00
var loadedSeries = Db.Single<Series>();
loadedSeries.Covers.Value.Should().HaveSameCount(covers);
}*/
[Test]
2013-03-26 07:17:46 +00:00
public void one_to_one()
{
var episode = Builder<Episode>.CreateNew()
.With(c => c.Id = 0)
.Build();
Db.Insert(episode);
var history = Builder<History.History>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.EpisodeId = episode.Id)
.With(c => c.Quality = new QualityModel())
.Build();
Db.Insert(history);
2013-03-26 07:17:46 +00:00
var loadedEpisode = Db.Single<History.History>().Episode.Value;
loadedEpisode.Should().NotBeNull();
2013-05-03 04:40:22 +00:00
loadedEpisode.ShouldHave().AllProperties().But(c => c.SeriesTitle).EqualTo(episode);
2013-03-26 07:17:46 +00:00
}
[Test]
public void embedded_document_as_json()
{
var quality = new QualityModel { Quality = Quality.Bluray720p, Proper = true };
var history = Builder<History.History>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.Quality = quality)
.Build();
Db.Insert(history);
var loadedQuality = Db.Single<History.History>().Quality;
loadedQuality.Should().Be(quality);
}
[Test]
public void embedded_list_of_document_with_json()
{
var quality = new QualityModel { Quality = Quality.Bluray720p, Proper = true };
var history = Builder<History.History>.CreateListOfSize(2)
.All().With(c => c.Id = 0)
.Build().ToList();
history[0].Quality = new QualityModel(Quality.HDTV1080p, true);
history[1].Quality = new QualityModel(Quality.Bluray720p, true);
Db.InsertMany(history);
var returnedHistory = Db.All<History.History>();
returnedHistory[0].Quality.Quality.Should().Be(Quality.HDTV1080p);
}
}
}