2013-02-17 06:35:52 +01:00
|
|
|
|
using System;
|
2013-03-24 20:56:51 +01:00
|
|
|
|
using System.Data;
|
2013-02-17 06:35:52 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-03-24 20:56:51 +01:00
|
|
|
|
using ServiceStack.OrmLite;
|
2013-02-17 06:35:52 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Datastore
|
|
|
|
|
{
|
2013-03-05 02:47:51 +01:00
|
|
|
|
public class BaiscType : ModelBase
|
2013-02-17 06:35:52 +01:00
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Tilte { get; set; }
|
|
|
|
|
public string Address { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
2013-03-24 05:16:00 +01:00
|
|
|
|
public class BasicRepositoryFixture : DbTest<BasicRepository<BaiscType>,BaiscType>
|
2013-02-17 06:35:52 +01:00
|
|
|
|
{
|
2013-03-05 02:47:51 +01:00
|
|
|
|
private BaiscType _baiscType;
|
2013-02-17 06:35:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-03-05 02:47:51 +01:00
|
|
|
|
_baiscType = Builder<BaiscType>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(c => c.Id = 0)
|
|
|
|
|
.Build();
|
2013-02-17 06:35:52 +01:00
|
|
|
|
|
2013-03-24 20:56:51 +01:00
|
|
|
|
Mocker.Resolve<IDbConnection>().CreateTable<BaiscType>();
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_add()
|
|
|
|
|
{
|
2013-03-05 02:47:51 +01:00
|
|
|
|
Subject.Insert(_baiscType);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
Subject.All().Should().HaveCount(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_delete_model()
|
|
|
|
|
{
|
2013-03-05 02:47:51 +01:00
|
|
|
|
Subject.Insert(_baiscType);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
Subject.All().Should().HaveCount(1);
|
|
|
|
|
|
2013-03-05 02:47:51 +01:00
|
|
|
|
Subject.Delete(_baiscType.Id);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
Subject.All().Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_find_by_id()
|
|
|
|
|
{
|
2013-03-05 02:47:51 +01:00
|
|
|
|
Subject.Insert(_baiscType);
|
|
|
|
|
Subject.Get(_baiscType.Id)
|
|
|
|
|
.ShouldHave()
|
|
|
|
|
.AllProperties()
|
|
|
|
|
.EqualTo(_baiscType);
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void getting_model_with_invalid_id_should_throw()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Subject.Get(12));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void get_all_with_empty_db_should_return_empty_list()
|
|
|
|
|
{
|
|
|
|
|
Subject.All().Should().BeEmpty();
|
|
|
|
|
}
|
2013-03-05 02:47:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_call_ToList_on_empty_quariable()
|
|
|
|
|
{
|
|
|
|
|
Subject.All().ToList().Should().BeEmpty();
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-17 06:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
}
|