fixed more tests.
This commit is contained in:
parent
7603d8e1ba
commit
cd6f0fc55c
|
@ -1,10 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using ServiceStack.OrmLite;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Datastore
|
namespace NzbDrone.Core.Test.Datastore
|
||||||
{
|
{
|
||||||
|
@ -29,6 +31,7 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
.With(c => c.Id = 0)
|
.With(c => c.Id = 0)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
Mocker.Resolve<IDbConnection>().CreateTable<BaiscType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using ServiceStack.OrmLite;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Datastore
|
namespace NzbDrone.Core.Test.Datastore
|
||||||
{
|
{
|
||||||
|
@ -21,6 +23,9 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
.CreateNew()
|
.CreateNew()
|
||||||
.With(s => s.Id = 0)
|
.With(s => s.Id = 0)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
Mocker.Resolve<IDbConnection>().CreateTable<BaiscType>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -102,9 +107,9 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
{
|
{
|
||||||
var childModel = new BaiscType
|
var childModel = new BaiscType
|
||||||
{
|
{
|
||||||
Address = "Address",
|
Address = "Address",
|
||||||
Name = "Name",
|
Name = "Name",
|
||||||
Tilte = "Title"
|
Tilte = "Title"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,7 +119,7 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
childModel.Name = "B";
|
childModel.Name = "B";
|
||||||
childModel.Tilte = "C";
|
childModel.Tilte = "C";
|
||||||
|
|
||||||
Subject.UpdateFields(childModel, t=>t.Name);
|
Subject.UpdateFields(childModel, t => t.Name);
|
||||||
|
|
||||||
Db.All<BaiscType>().Single().Address.Should().Be("Address");
|
Db.All<BaiscType>().Single().Address.Should().Be("Address");
|
||||||
Db.All<BaiscType>().Single().Name.Should().Be("B");
|
Db.All<BaiscType>().Single().Name.Should().Be("B");
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
using System.Linq;
|
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
using ServiceStack.DataAnnotations;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Configuration
|
namespace NzbDrone.Core.Configuration
|
||||||
{
|
{
|
||||||
public class Config : ModelBase
|
public class Config : ModelBase
|
||||||
{
|
{
|
||||||
|
[Index(Unique = true)]
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
|
||||||
public string Value { get; set; }
|
public string Value { get; set; }
|
||||||
|
|
|
@ -57,7 +57,15 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public TModel Get(int id)
|
public TModel Get(int id)
|
||||||
{
|
{
|
||||||
return _database.GetById<TModel>(id);
|
try
|
||||||
|
{
|
||||||
|
return _database.GetById<TModel>(id);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException e)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TModel Single(Expression<Func<TModel, bool>> predicate)
|
public TModel Single(Expression<Func<TModel, bool>> predicate)
|
||||||
|
@ -87,6 +95,11 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public TModel Insert(TModel model)
|
public TModel Insert(TModel model)
|
||||||
{
|
{
|
||||||
|
if (model.Id != 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Can't insert model with existing ID");
|
||||||
|
}
|
||||||
|
|
||||||
_database.Insert(model);
|
_database.Insert(model);
|
||||||
model.Id = (int)_database.GetLastInsertId();
|
model.Id = (int)_database.GetLastInsertId();
|
||||||
return model;
|
return model;
|
||||||
|
@ -94,6 +107,11 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public TModel Update(TModel model)
|
public TModel Update(TModel model)
|
||||||
{
|
{
|
||||||
|
if (model.Id == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Can't update model with ID 0");
|
||||||
|
}
|
||||||
|
|
||||||
_database.Update(model);
|
_database.Update(model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue