Radarr/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs

94 lines
2.2 KiB
C#
Raw Normal View History

using System;
2013-03-24 19:56:51 +00:00
using System.Data;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
2013-03-25 03:51:32 +00:00
using Marr.Data.Mapping;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore
{
2013-03-25 03:51:32 +00:00
public class BasicType : ModelBase
{
public string Name { get; set; }
public string Tilte { get; set; }
public string Address { get; set; }
}
[TestFixture]
2013-03-25 03:51:32 +00:00
public class
BasicRepositoryFixture : DbTest<BasicRepository<BasicType>, BasicType>
{
2013-03-25 03:51:32 +00:00
private BasicType _basicType;
[SetUp]
public void Setup()
{
2013-03-25 03:51:32 +00:00
_basicType = Builder<BasicType>
2013-03-05 01:47:51 +00:00
.CreateNew()
.With(c => c.Id = 0)
.Build();
2013-03-25 03:51:32 +00:00
var mapping = new FluentMappings(true);
mapping.Entity<BasicType>()
.Columns.AutoMapSimpleTypeProperties()
.For(c => c.Id).SetAutoIncrement()
.SetPrimaryKey();
}
[Test]
public void should_be_able_to_add()
{
2013-03-25 03:51:32 +00:00
Subject.Insert(_basicType);
Subject.All().Should().HaveCount(1);
}
[Test]
public void should_be_able_to_delete_model()
{
2013-03-25 03:51:32 +00:00
Subject.Insert(_basicType);
Subject.All().Should().HaveCount(1);
2013-03-25 03:51:32 +00:00
Subject.Delete(_basicType.Id);
Subject.All().Should().BeEmpty();
}
[Test]
public void should_be_able_to_find_by_id()
{
2013-03-25 03:51:32 +00:00
Subject.Insert(_basicType);
Subject.Get(_basicType.Id)
2013-03-05 01:47:51 +00:00
.ShouldHave()
.AllProperties()
2013-03-25 03:51:32 +00:00
.EqualTo(_basicType);
}
[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 01:47:51 +00:00
[Test]
public void should_be_able_to_call_ToList_on_empty_quariable()
{
Subject.All().ToList().Should().BeEmpty();
}
}
}