Marr is almost working.

This commit is contained in:
kay.one
2013-03-24 23:13:53 -07:00
parent 971053f8a2
commit ea4f0dbe5f
18 changed files with 300 additions and 126 deletions
@@ -1,44 +1,29 @@
using System;
using System.Data;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Marr.Data.Mapping;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore
{
public class BasicType : ModelBase
{
public string Name { get; set; }
public string Tilte { get; set; }
public string Address { get; set; }
}
[TestFixture]
public class
BasicRepositoryFixture : DbTest<BasicRepository<BasicType>, BasicType>
public class
BasicRepositoryFixture : DbTest<BasicRepository<JobDefinition>, JobDefinition>
{
private BasicType _basicType;
private JobDefinition _basicType;
[SetUp]
public void Setup()
{
_basicType = Builder<BasicType>
_basicType = Builder<JobDefinition>
.CreateNew()
.With(c => c.Id = 0)
.Build();
var mapping = new FluentMappings(true);
mapping.Entity<BasicType>()
.Columns.AutoMapSimpleTypeProperties()
.For(c => c.Id).SetAutoIncrement()
.SetPrimaryKey();
}
[Test]
@@ -6,19 +6,20 @@ using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore
{
[TestFixture]
public class ObjectDatabaseFixture : DbTest<BasicRepository<BasicType>, BasicType>
public class ObjectDatabaseFixture : DbTest<BasicRepository<JobDefinition>, JobDefinition>
{
private BasicType _sampleType;
private JobDefinition _sampleType;
[SetUp]
public void SetUp()
{
_sampleType = Builder<BasicType>
_sampleType = Builder<JobDefinition>
.CreateNew()
.With(s => s.Id = 0)
.Build();
@@ -29,7 +30,7 @@ namespace NzbDrone.Core.Test.Datastore
public void should_be_able_to_write_to_database()
{
Subject.Insert(_sampleType);
Db.All<BasicType>().Should().HaveCount(1);
Db.All<JobDefinition>().Should().HaveCount(1);
}
[Test]
@@ -49,7 +50,7 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_be_able_to_store_empty_list()
{
var series = new List<BasicType>();
var series = new List<JobDefinition>();
Subject.InsertMany(series);
}
@@ -68,7 +69,7 @@ namespace NzbDrone.Core.Test.Datastore
_sampleType.Id = 0;
Subject.Insert(_sampleType);
Db.All<BasicType>().Should().HaveCount(1);
Db.All<JobDefinition>().Should().HaveCount(1);
_sampleType.Id.Should().Be(1);
}
@@ -80,7 +81,7 @@ namespace NzbDrone.Core.Test.Datastore
{
_sampleType.Id = 0;
Subject.Insert(_sampleType);
var item = Db.All<BasicType>();
var item = Db.All<JobDefinition>();
item.Should().HaveCount(1);
item.First().Id.Should().NotBe(0);
@@ -92,7 +93,7 @@ namespace NzbDrone.Core.Test.Datastore
public void should_be_able_to_find_object_by_id()
{
Subject.Insert(_sampleType);
var item = Db.All<BasicType>().Single(c => c.Id == _sampleType.Id);
var item = Db.All<JobDefinition>().Single(c => c.Id == _sampleType.Id);
item.Id.Should().NotBe(0);
item.Id.Should().Be(_sampleType.Id);
@@ -102,25 +103,25 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void update_field_should_only_update_that_filed()
{
var childModel = new BasicType
var childModel = new JobDefinition
{
Address = "Address",
Type = "Address",
Name = "Name",
Tilte = "Title"
Interval = 12
};
Subject.Insert(childModel);
childModel.Address = "A";
childModel.Type = "A";
childModel.Name = "B";
childModel.Tilte = "C";
childModel.Interval = 0;
Subject.UpdateFields(childModel, t => t.Name);
Db.All<BasicType>().Single().Address.Should().Be("Address");
Db.All<BasicType>().Single().Name.Should().Be("B");
Db.All<BasicType>().Single().Tilte.Should().Be("Title");
Db.All<JobDefinition>().Single().Type.Should().Be("Address");
Db.All<JobDefinition>().Single().Name.Should().Be("B");
Db.All<JobDefinition>().Single().Interval.Should().Be(12);
}
+2 -1
View File
@@ -7,6 +7,7 @@ using Marr.Data;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Test.Framework
{
@@ -85,7 +86,7 @@ namespace NzbDrone.Core.Test.Framework
MapRepository.Instance.EnableTraceLogging = true;
var factory = new DbFactory();
var factory = new DbFactory(new MigrationController(new NlogAnnouncer()));
_database = factory.Create(_dbName);
_db = new TestTestDatabase(_database);
Mocker.SetConstant(_database);
@@ -79,6 +79,11 @@
</Reference>
<Reference Include="Marr.Data">
<HintPath>..\packages\MarrDataMapper.3.17.4747.34302\lib\Marr.Data.dll</HintPath>
<Reference Include="FluentMigrator">
<HintPath>..\packages\FluentMigrator.1.0.6.0\lib\40\FluentMigrator.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner">
<HintPath>..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+1
View File
@@ -4,6 +4,7 @@
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="FluentAssertions" version="2.0.0.1" targetFramework="net40" />
<package id="FluentMigrator" version="1.0.6.0" targetFramework="net40" />
<package id="Moq" version="4.0.10827" />
<package id="NBuilder" version="3.0.1.1" />
<package id="NCrunch.Framework" version="1.43.0.23" targetFramework="net40" />