2013-02-16 07:03:54 +03:00
|
|
|
using System;
|
2013-02-16 06:50:22 +03:00
|
|
|
using System.Collections.Generic;
|
2013-03-24 22:56:51 +03:00
|
|
|
using System.Data;
|
2013-02-05 07:07:07 +03:00
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2013-02-13 04:25:32 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-02-05 07:07:07 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Datastore
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-03-25 06:51:32 +03:00
|
|
|
public class ObjectDatabaseFixture : DbTest<BasicRepository<BasicType>, BasicType>
|
2013-02-05 07:07:07 +03:00
|
|
|
{
|
2013-03-25 06:51:32 +03:00
|
|
|
private BasicType _sampleType;
|
2013-02-05 07:07:07 +03:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
2013-03-25 06:51:32 +03:00
|
|
|
_sampleType = Builder<BasicType>
|
2013-02-06 11:40:57 +03:00
|
|
|
.CreateNew()
|
2013-02-26 06:58:57 +03:00
|
|
|
.With(s => s.Id = 0)
|
2013-02-06 11:40:57 +03:00
|
|
|
.Build();
|
2013-03-24 22:56:51 +03:00
|
|
|
|
2013-02-05 07:07:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_be_able_to_write_to_database()
|
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
Subject.Insert(_sampleType);
|
2013-03-25 06:51:32 +03:00
|
|
|
Db.All<BasicType>().Should().HaveCount(1);
|
2013-02-05 07:07:07 +03:00
|
|
|
}
|
|
|
|
|
2013-02-16 07:03:54 +03:00
|
|
|
[Test]
|
|
|
|
public void double_insert_should_fail()
|
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
Subject.Insert(_sampleType);
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Subject.Insert(_sampleType));
|
2013-02-16 07:03:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void update_item_with_root_index_0_should_faile()
|
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
_sampleType.Id = 0;
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Subject.Update(_sampleType));
|
2013-02-16 07:03:54 +03:00
|
|
|
}
|
|
|
|
|
2013-02-16 07:17:23 +03:00
|
|
|
[Test]
|
|
|
|
public void should_be_able_to_store_empty_list()
|
|
|
|
{
|
2013-03-25 06:51:32 +03:00
|
|
|
var series = new List<BasicType>();
|
2013-02-05 07:07:07 +03:00
|
|
|
|
2013-03-24 07:16:00 +03:00
|
|
|
Subject.InsertMany(series);
|
2013-02-05 07:07:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void new_objects_should_get_id()
|
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
_sampleType.Id = 0;
|
|
|
|
Subject.Insert(_sampleType);
|
|
|
|
_sampleType.Id.Should().NotBe(0);
|
2013-02-05 07:07:07 +03:00
|
|
|
}
|
|
|
|
|
2013-02-16 06:50:22 +03:00
|
|
|
[Test]
|
2013-02-16 07:03:54 +03:00
|
|
|
public void new_object_should_get_new_id()
|
2013-02-16 06:50:22 +03:00
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
_sampleType.Id = 0;
|
|
|
|
Subject.Insert(_sampleType);
|
2013-02-16 06:50:22 +03:00
|
|
|
|
2013-03-25 06:51:32 +03:00
|
|
|
Db.All<BasicType>().Should().HaveCount(1);
|
2013-03-24 07:16:00 +03:00
|
|
|
_sampleType.Id.Should().Be(1);
|
2013-02-16 06:50:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-05 07:07:07 +03:00
|
|
|
[Test]
|
2013-02-06 11:40:57 +03:00
|
|
|
public void should_have_id_when_returned_from_database()
|
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
_sampleType.Id = 0;
|
|
|
|
Subject.Insert(_sampleType);
|
2013-03-25 06:51:32 +03:00
|
|
|
var item = Db.All<BasicType>();
|
2013-02-06 11:40:57 +03:00
|
|
|
|
|
|
|
item.Should().HaveCount(1);
|
2013-02-26 06:58:57 +03:00
|
|
|
item.First().Id.Should().NotBe(0);
|
|
|
|
item.First().Id.Should().BeLessThan(100);
|
2013-03-24 07:16:00 +03:00
|
|
|
item.First().Id.Should().Be(_sampleType.Id);
|
2013-02-06 11:40:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_be_able_to_find_object_by_id()
|
|
|
|
{
|
2013-03-24 07:16:00 +03:00
|
|
|
Subject.Insert(_sampleType);
|
2013-03-25 06:51:32 +03:00
|
|
|
var item = Db.All<BasicType>().Single(c => c.Id == _sampleType.Id);
|
2013-02-06 11:40:57 +03:00
|
|
|
|
2013-02-26 06:58:57 +03:00
|
|
|
item.Id.Should().NotBe(0);
|
2013-03-24 07:16:00 +03:00
|
|
|
item.Id.Should().Be(_sampleType.Id);
|
2013-02-27 10:25:56 +03:00
|
|
|
}
|
|
|
|
|
2013-03-01 10:03:41 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void update_field_should_only_update_that_filed()
|
|
|
|
{
|
2013-03-25 06:51:32 +03:00
|
|
|
var childModel = new BasicType
|
2013-03-01 10:03:41 +03:00
|
|
|
{
|
2013-03-24 22:56:51 +03:00
|
|
|
Address = "Address",
|
|
|
|
Name = "Name",
|
|
|
|
Tilte = "Title"
|
2013-03-01 10:03:41 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-03-24 07:16:00 +03:00
|
|
|
Subject.Insert(childModel);
|
2013-03-01 10:03:41 +03:00
|
|
|
|
2013-03-24 07:16:00 +03:00
|
|
|
childModel.Address = "A";
|
|
|
|
childModel.Name = "B";
|
|
|
|
childModel.Tilte = "C";
|
2013-03-01 10:03:41 +03:00
|
|
|
|
2013-03-24 22:56:51 +03:00
|
|
|
Subject.UpdateFields(childModel, t => t.Name);
|
2013-03-01 10:03:41 +03:00
|
|
|
|
2013-03-25 06:51:32 +03:00
|
|
|
Db.All<BasicType>().Single().Address.Should().Be("Address");
|
|
|
|
Db.All<BasicType>().Single().Name.Should().Be("B");
|
|
|
|
Db.All<BasicType>().Single().Tilte.Should().Be("Title");
|
2013-03-01 10:03:41 +03:00
|
|
|
}
|
2013-02-27 10:25:56 +03:00
|
|
|
|
2013-02-17 07:33:56 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-05 07:07:07 +03:00
|
|
|
}
|
|
|
|
|