mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 01:05:07 +08:00
Adding unit tests for IHqlQuery
--HG-- branch : 1.x
This commit is contained in:
parent
eca67d75ff
commit
a6f5f8ad21
@ -232,6 +232,8 @@ namespace Orchard.Tests.ContentManagement {
|
||||
Assert.That(results.First().Record, Has.Property("Quad").EqualTo("3"));
|
||||
Assert.That(results.Last().Record, Has.Property("Quad").EqualTo("2"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.Tests.ContentManagement.Models;
|
||||
using Orchard.Tests.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement.Handlers {
|
||||
public class LambdaPartHandler : ContentHandler {
|
||||
public LambdaPartHandler(IRepository<LambdaRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<LambdaPart>("lambda"));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
983
src/Orchard.Tests/ContentManagement/HqlExpressionTests.cs
Normal file
983
src/Orchard.Tests/ContentManagement/HqlExpressionTests.cs
Normal file
@ -0,0 +1,983 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NHibernate;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Tests.ContentManagement.Handlers;
|
||||
using Orchard.Tests.ContentManagement.Records;
|
||||
using Orchard.Tests.ContentManagement.Models;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Tests.Stubs;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement {
|
||||
[TestFixture]
|
||||
public class HqlExpressionTests {
|
||||
private IContainer _container;
|
||||
private IContentManager _manager;
|
||||
private ISessionFactory _sessionFactory;
|
||||
private ISession _session;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void InitFixture() {
|
||||
var databaseFileName = System.IO.Path.GetTempFileName();
|
||||
_sessionFactory = DataUtility.CreateSessionFactory(
|
||||
databaseFileName,
|
||||
typeof(GammaRecord),
|
||||
typeof(DeltaRecord),
|
||||
typeof(EpsilonRecord),
|
||||
typeof(LambdaRecord),
|
||||
typeof(ContentItemVersionRecord),
|
||||
typeof(ContentItemRecord),
|
||||
typeof(ContentTypeRecord));
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterModule(new ContentModule());
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
|
||||
builder.RegisterType<AlphaPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<BetaPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<GammaPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<DeltaPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<EpsilonPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<LambdaPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<FlavoredPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StyledHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
|
||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||
|
||||
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
|
||||
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
|
||||
|
||||
_session = _sessionFactory.OpenSession();
|
||||
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();
|
||||
|
||||
_session.Delete(string.Format("from {0}", typeof(GammaRecord).FullName));
|
||||
_session.Delete(string.Format("from {0}", typeof(DeltaRecord).FullName));
|
||||
_session.Delete(string.Format("from {0}", typeof(EpsilonRecord).FullName));
|
||||
_session.Delete(string.Format("from {0}", typeof(LambdaRecord).FullName));
|
||||
|
||||
_session.Delete(string.Format("from {0}", typeof(ContentItemVersionRecord).FullName));
|
||||
_session.Delete(string.Format("from {0}", typeof(ContentItemRecord).FullName));
|
||||
_session.Delete(string.Format("from {0}", typeof(ContentTypeRecord).FullName));
|
||||
_session.Flush();
|
||||
_session.Clear();
|
||||
|
||||
_container = builder.Build();
|
||||
_manager = _container.Resolve<IContentManager>();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllDataTypesCanBeQueried() {
|
||||
var dt = DateTime.Now;
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = true;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var lambda = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("BooleanStuff", true)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("DecimalStuff", (decimal)0.0)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("DoubleStuff", 0.0)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("FloatStuff", (float)0.0)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("IntegerStuff", 0)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("LongStuff", (long)0)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("StringStuff", "0")).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
|
||||
lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), x => x.Eq("DateTimeStuff", dt)).List();
|
||||
Assert.That(lambda.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorLike() {
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.StringStuff = "abcdef";
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "bc", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "ab", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "ef", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "gh", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "ab", HqlMatchMode.Start));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "ef", HqlMatchMode.End));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "abcdef", HqlMatchMode.Exact));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Like("StringStuff", "abcde", HqlMatchMode.Exact));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
// default collation in SQL Ce/Server but can be changed during db creation
|
||||
result = queryWhere(x => x.Like("StringStuff", "EF", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorInsensitiveLike() {
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.StringStuff = "abcdef";
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "bc", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "ab", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "ef", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "gh", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "ab", HqlMatchMode.Start));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "ef", HqlMatchMode.End));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "abcdef", HqlMatchMode.Exact));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "abcde", HqlMatchMode.Exact));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.InsensitiveLike("StringStuff", "EF", HqlMatchMode.Anywhere));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorGt() {
|
||||
var dt = new DateTime(1980,1,1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = true;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.Gt("BooleanStuff", true));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("DecimalStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("DoubleStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("FloatStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("IntegerStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("LongStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("StringStuff", "0"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("DateTimeStuff", dt));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Gt("BooleanStuff", false));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("DecimalStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("DoubleStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("FloatStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("IntegerStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("LongStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("StringStuff", ""));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Gt("DateTimeStuff", dt.AddDays(-1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorLt() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.Lt("BooleanStuff", false));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("DecimalStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("DoubleStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("FloatStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("IntegerStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("LongStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("StringStuff", "0"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("DateTimeStuff", dt));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Lt("BooleanStuff", true));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("DecimalStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("DoubleStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("FloatStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("IntegerStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("LongStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("StringStuff", "00"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Lt("DateTimeStuff", dt.AddDays(1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorLe() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.Le("BooleanStuff", false));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("DecimalStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("DoubleStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("FloatStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("IntegerStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("LongStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("StringStuff", "0"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("DateTimeStuff", dt));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// greater values
|
||||
result = queryWhere(x => x.Le("BooleanStuff", true));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("DecimalStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("DoubleStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("FloatStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("IntegerStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("LongStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("StringStuff", "00"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Le("DateTimeStuff", dt.AddDays(1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// lower values
|
||||
result = queryWhere(x => x.Le("DecimalStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Le("DoubleStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Le("FloatStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Le("IntegerStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Le("LongStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Le("StringStuff", ""));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Le("DateTimeStuff", dt.AddDays(-1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorGe() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.Ge("BooleanStuff", false));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("DecimalStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("DoubleStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("FloatStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("IntegerStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("LongStuff", 0));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("StringStuff", "0"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("DateTimeStuff", dt));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// greater values
|
||||
result = queryWhere(x => x.Ge("BooleanStuff", true));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("DecimalStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("DoubleStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("FloatStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("IntegerStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("LongStuff", 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("StringStuff", "00"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Ge("DateTimeStuff", dt.AddDays(1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
// lower values
|
||||
result = queryWhere(x => x.Ge("DecimalStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("DoubleStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("FloatStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("IntegerStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("LongStuff", -1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("StringStuff", ""));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Ge("DateTimeStuff", dt.AddDays(-1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorBetween() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// include
|
||||
result = queryWhere(x => x.Between("DecimalStuff", 0, 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Between("DoubleStuff", 0, 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Between("FloatStuff", 0, 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Between("IntegerStuff", 0, 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Between("LongStuff", 0, 1));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Between("StringStuff", "0", "1"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.Between("DateTimeStuff", dt, dt.AddDays(1)));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// exclude
|
||||
result = queryWhere(x => x.Between("DecimalStuff", 1, 2));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Between("DoubleStuff", 1, 2));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Between("FloatStuff", 1, 2));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Between("IntegerStuff", 1, 2));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Between("LongStuff", 1, 2));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Between("StringStuff", "1", "2"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.Between("DateTimeStuff", dt.AddDays(1), dt.AddDays(2)));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorIn() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// include
|
||||
result = queryWhere(x => x.In("BooleanStuff", new[] { false }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("DecimalStuff", new[] { 0, 1 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("DoubleStuff", new[] { 0, 1 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("FloatStuff", new[] { 0, 1 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("IntegerStuff", new[] { 0, 1 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("LongStuff", new[] { 0, 1 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("StringStuff", new[] { "0", "1" }));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.In("DateTimeStuff", new [] {dt, dt.AddDays(1)}));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// exclude
|
||||
result = queryWhere(x => x.In("BooleanStuff", new[] { true }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("DecimalStuff", new[] { 1, 2 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("DoubleStuff", new[] { 1, 2 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("FloatStuff", new[] { 1, 2 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("IntegerStuff", new[] { 1, 2 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("LongStuff", new[] { 1, 2 }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("StringStuff", new[] { "1", "2" }));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.In("DateTimeStuff", new [] {dt.AddDays(1), dt.AddDays(2)}));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorIsNull() {
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.StringStuff = null;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.IsNull("BooleanStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.IsNull("StringStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorIsNotNull() {
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.StringStuff = null;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.IsNotNull("BooleanStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.IsNotNull("StringStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorEqProperty() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.EqProperty("BooleanStuff", "LongStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
result = queryWhere(x => x.EqProperty("DateTimeStuff", "LongStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorNotEqProperty() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 0;
|
||||
init.Record.LongStuff = 0;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
result = queryWhere(x => x.NotEqProperty("BooleanStuff", "LongStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
result = queryWhere(x => x.NotEqProperty("DateTimeStuff", "LongStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorGtProperty() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 1;
|
||||
init.Record.LongStuff = 2;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.GtProperty("DoubleStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
// lesser
|
||||
result = queryWhere(x => x.GtProperty("FloatStuff", "IntegerStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
// greater
|
||||
result = queryWhere(x => x.GtProperty("IntegerStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorGeProperty() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 1;
|
||||
init.Record.LongStuff = 2;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.GeProperty("DoubleStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// lesser
|
||||
result = queryWhere(x => x.GeProperty("FloatStuff", "IntegerStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
// greater
|
||||
result = queryWhere(x => x.GeProperty("IntegerStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorLeProperty() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 1;
|
||||
init.Record.LongStuff = 2;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.LeProperty("DoubleStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// lesser
|
||||
result = queryWhere(x => x.LeProperty("FloatStuff", "IntegerStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// greater
|
||||
result = queryWhere(x => x.LeProperty("IntegerStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorLtProperty() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 1;
|
||||
init.Record.LongStuff = 2;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.LtProperty("DoubleStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
|
||||
// lesser
|
||||
result = queryWhere(x => x.LtProperty("FloatStuff", "IntegerStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
// greater
|
||||
result = queryWhere(x => x.LtProperty("IntegerStuff", "FloatStuff"));
|
||||
Assert.That(result.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldSortRandomly() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.IntegerStuff = 1;
|
||||
});
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.IntegerStuff = 2;
|
||||
});
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.IntegerStuff = 3;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(3));
|
||||
|
||||
var firstResults = new List<int>();
|
||||
|
||||
var rand = new Randomizer(123);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
result = _manager.HqlQuery().Join(alias => alias.ContentPartRecord<LambdaRecord>()).OrderBy(x => x.Named("civ"), order => order.Random(rand.Next(1000))).List();
|
||||
firstResults.Add(result.First().As<LambdaPart>().Record.IntegerStuff);
|
||||
}
|
||||
|
||||
Assert.That(result.Distinct().Count(), Is.GreaterThan(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldQueryUsingOperatorNot() {
|
||||
var dt = new DateTime(1980, 1, 1);
|
||||
|
||||
_manager.Create<LambdaPart>("lambda", init => {
|
||||
init.Record.BooleanStuff = false;
|
||||
init.Record.DecimalStuff = 0;
|
||||
init.Record.DoubleStuff = 0;
|
||||
init.Record.FloatStuff = 0;
|
||||
init.Record.IntegerStuff = 1;
|
||||
init.Record.LongStuff = 2;
|
||||
init.Record.StringStuff = "0";
|
||||
init.Record.DateTimeStuff = dt;
|
||||
});
|
||||
_session.Flush();
|
||||
|
||||
var result = _manager.HqlQuery().ForType("lambda").List();
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
|
||||
Func<Action<IHqlExpressionFactory>, IEnumerable<ContentItem>> queryWhere = predicate => _manager.HqlQuery().Where(alias => alias.ContentPartRecord<LambdaRecord>(), predicate).List();
|
||||
|
||||
// equal
|
||||
result = queryWhere(x => x.Not(y => y.LtProperty("DoubleStuff", "FloatStuff")));
|
||||
Assert.That(result.Count(), Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
7
src/Orchard.Tests/ContentManagement/Models/LambdaPart.cs
Normal file
7
src/Orchard.Tests/ContentManagement/Models/LambdaPart.cs
Normal file
@ -0,0 +1,7 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Tests.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement.Models {
|
||||
public class LambdaPart : ContentPart<LambdaRecord> {
|
||||
}
|
||||
}
|
19
src/Orchard.Tests/ContentManagement/Records/LambdaRecord.cs
Normal file
19
src/Orchard.Tests/ContentManagement/Records/LambdaRecord.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement.Records {
|
||||
public class LambdaRecord : ContentPartRecord {
|
||||
public LambdaRecord() {
|
||||
DateTimeStuff = new DateTime(1980,1,1);
|
||||
}
|
||||
|
||||
public virtual int IntegerStuff { get; set; }
|
||||
public virtual long LongStuff { get; set; }
|
||||
public virtual bool BooleanStuff { get; set; }
|
||||
public virtual float FloatStuff { get; set; }
|
||||
public virtual double DoubleStuff { get; set; }
|
||||
public virtual Decimal DecimalStuff { get; set; }
|
||||
public virtual string StringStuff { get; set; }
|
||||
public virtual DateTime DateTimeStuff { get; set; }
|
||||
}
|
||||
}
|
@ -168,6 +168,8 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\ContentQueryTests.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\LambdaPartHandler.cs" />
|
||||
<Compile Include="ContentManagement\HqlExpressionTests.cs" />
|
||||
<Compile Include="ContentManagement\DynamicContentQueryTests.cs" />
|
||||
<Compile Include="ContentManagement\DefaultContentManagerTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
@ -187,6 +189,7 @@
|
||||
<Compile Include="ContentManagement\Handlers\AlphaPartHandler.cs" />
|
||||
<Compile Include="ContentManagement\Models\BetaPart.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\BetaPartHandler.cs" />
|
||||
<Compile Include="ContentManagement\Models\LambdaPart.cs" />
|
||||
<Compile Include="ContentManagement\Models\DeltaPart.cs" />
|
||||
<Compile Include="ContentManagement\Models\EpsilonPart.cs" />
|
||||
<Compile Include="ContentManagement\Models\FlavoredPart.cs" />
|
||||
@ -198,6 +201,7 @@
|
||||
<Compile Include="ContentManagement\Handlers\Coordinators\ContentPartDriverCoordinatorTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\Records\LambdaRecord.cs" />
|
||||
<Compile Include="ContentManagement\Records\MegaRecord.cs" />
|
||||
<Compile Include="ContentManagement\Records\DeltaRecord.cs">
|
||||
<SubType>Code</SubType>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@ -226,9 +227,14 @@ namespace Orchard.ContentManagement {
|
||||
var sortFactory = new DefaultHqlSortFactory();
|
||||
sort.Item2(sortFactory);
|
||||
|
||||
sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
|
||||
if (!sortFactory.Ascending) {
|
||||
sb.Append(" desc");
|
||||
if (sortFactory.Randomize) {
|
||||
sb.Append(" rand(" + sortFactory.Seed + ")");
|
||||
}
|
||||
else {
|
||||
sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
|
||||
if (!sortFactory.Ascending) {
|
||||
sb.Append(" desc");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,6 +348,8 @@ namespace Orchard.ContentManagement {
|
||||
{
|
||||
public bool Ascending { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
public bool Randomize { get; set; }
|
||||
public int Seed { get; set; }
|
||||
|
||||
public void Asc(string propertyName) {
|
||||
PropertyName = propertyName;
|
||||
@ -352,6 +360,11 @@ namespace Orchard.ContentManagement {
|
||||
PropertyName = propertyName;
|
||||
Ascending = false;
|
||||
}
|
||||
|
||||
public void Random(int seed) {
|
||||
Seed = seed;
|
||||
Randomize = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultAliasFactory : IAliasFactory{
|
||||
@ -386,5 +399,163 @@ namespace Orchard.ContentManagement {
|
||||
Current = _query.BindNamedAlias(alias);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAliasFactory ContentItem() {
|
||||
return Named("ci");
|
||||
}
|
||||
|
||||
public IAliasFactory ContentItemVersion() {
|
||||
return Named("civ");
|
||||
}
|
||||
|
||||
public IAliasFactory ContentType() {
|
||||
return Named("ct");
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultHqlExpressionFactory : IHqlExpressionFactory {
|
||||
public IHqlCriterion Criterion { get; private set; }
|
||||
|
||||
public void Eq(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Eq(propertyName, value);
|
||||
}
|
||||
|
||||
public void Like(string propertyName, string value, HqlMatchMode matchMode) {
|
||||
Criterion = HqlRestrictions.Like(propertyName, value, matchMode);
|
||||
}
|
||||
|
||||
public void InsensitiveLike(string propertyName, string value, HqlMatchMode matchMode) {
|
||||
Criterion = HqlRestrictions.InsensitiveLike(propertyName, value, matchMode);
|
||||
}
|
||||
|
||||
public void Gt(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Gt(propertyName, value);
|
||||
}
|
||||
|
||||
public void Lt(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Lt(propertyName, value);
|
||||
}
|
||||
|
||||
public void Le(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Le(propertyName, value);
|
||||
}
|
||||
|
||||
public void Ge(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Ge(propertyName, value);
|
||||
}
|
||||
|
||||
public void Between(string propertyName, object lo, object hi) {
|
||||
Criterion = HqlRestrictions.Between(propertyName, lo, hi);
|
||||
}
|
||||
|
||||
public void In(string propertyName, object[] values) {
|
||||
Criterion = HqlRestrictions.In(propertyName, values);
|
||||
}
|
||||
|
||||
public void In(string propertyName, ICollection values) {
|
||||
Criterion = HqlRestrictions.In(propertyName, values);
|
||||
}
|
||||
|
||||
public void InG<T>(string propertyName, ICollection<T> values) {
|
||||
Criterion = HqlRestrictions.InG(propertyName, values);
|
||||
}
|
||||
|
||||
public void IsNull(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsNull(propertyName);
|
||||
}
|
||||
|
||||
public void EqProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.EqProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void NotEqProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.NotEqProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void GtProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.GtProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void GeProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.GeProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void LtProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.LtProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void LeProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.LeProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void IsNotNull(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsNotNull(propertyName);
|
||||
}
|
||||
|
||||
public void IsNotEmpty(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsNotEmpty(propertyName);
|
||||
}
|
||||
|
||||
public void IsEmpty(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsEmpty(propertyName);
|
||||
}
|
||||
|
||||
public void And(Action<IHqlExpressionFactory> lhs, Action<IHqlExpressionFactory> rhs) {
|
||||
lhs(this);
|
||||
var a = Criterion;
|
||||
rhs(this);
|
||||
var b = Criterion;
|
||||
Criterion = HqlRestrictions.And(a, b);
|
||||
}
|
||||
|
||||
public void Or(Action<IHqlExpressionFactory> lhs, Action<IHqlExpressionFactory> rhs) {
|
||||
lhs(this);
|
||||
var a = Criterion;
|
||||
rhs(this);
|
||||
var b = Criterion;
|
||||
Criterion = HqlRestrictions.Or(a, b);
|
||||
}
|
||||
|
||||
public void Not(Action<IHqlExpressionFactory> expression) {
|
||||
expression(this);
|
||||
var a = Criterion;
|
||||
Criterion = HqlRestrictions.Not(a);
|
||||
}
|
||||
|
||||
public void Conjunction(Action<IHqlExpressionFactory> expression, params Action<IHqlExpressionFactory>[] otherExpressions) {
|
||||
var junction = HqlRestrictions.Conjunction();
|
||||
foreach (var exp in Enumerable.Empty<Action<IHqlExpressionFactory>>().Union(new[] { expression }).Union(otherExpressions)) {
|
||||
exp(this);
|
||||
junction.Add(Criterion);
|
||||
}
|
||||
|
||||
Criterion = junction;
|
||||
}
|
||||
|
||||
public void Disjunction(Action<IHqlExpressionFactory> expression, params Action<IHqlExpressionFactory>[] otherExpressions) {
|
||||
var junction = HqlRestrictions.Disjunction();
|
||||
foreach (var exp in Enumerable.Empty<Action<IHqlExpressionFactory>>().Union(new[] { expression }).Union(otherExpressions)) {
|
||||
exp(this);
|
||||
junction.Add(Criterion);
|
||||
}
|
||||
|
||||
Criterion = junction;
|
||||
}
|
||||
|
||||
public void AllEq(IDictionary propertyNameValues) {
|
||||
Criterion = HqlRestrictions.AllEq(propertyNameValues);
|
||||
}
|
||||
|
||||
public void NaturalId() {
|
||||
Criterion = HqlRestrictions.NaturalId();
|
||||
}
|
||||
}
|
||||
|
||||
public enum HqlMatchMode {
|
||||
Exact,
|
||||
Start,
|
||||
End,
|
||||
Anywhere
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ using System.Text;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
public interface IHqlCriterion {
|
||||
|
||||
string ToHql(IAlias alias);
|
||||
}
|
||||
|
||||
@ -17,7 +16,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public class BinaryExpression : HqlCriterion {
|
||||
public BinaryExpression(string op, string propertyName, string value, Func<string, string> processPropertyName = null) {
|
||||
if(value == null) {
|
||||
if (value == null) {
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
|
||||
@ -26,7 +25,7 @@ namespace Orchard.ContentManagement {
|
||||
Value = value;
|
||||
ProcessPropertyName = processPropertyName;
|
||||
}
|
||||
|
||||
|
||||
public string Op { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
public string Value { get; set; }
|
||||
@ -34,13 +33,54 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public override string ToHql(IAlias alias) {
|
||||
var processed = String.Concat(alias.Name, ".", PropertyName);
|
||||
if(ProcessPropertyName != null) {
|
||||
if (ProcessPropertyName != null) {
|
||||
processed = ProcessPropertyName(processed);
|
||||
}
|
||||
return String.Concat(processed, " ", Op, " ", Value);
|
||||
}
|
||||
}
|
||||
|
||||
public class NotExpression : HqlCriterion {
|
||||
public IHqlCriterion Criterion { get; set; }
|
||||
|
||||
public NotExpression(IHqlCriterion criterion) {
|
||||
Criterion = criterion;
|
||||
}
|
||||
|
||||
public override string ToHql(IAlias alias) {
|
||||
return String.Concat("not ", Criterion.ToHql(alias));
|
||||
}
|
||||
}
|
||||
|
||||
public class ComplexExpression : HqlCriterion {
|
||||
public ComplexExpression(string op1, string op2, string propertyName, string value1, string value2) {
|
||||
if(value1 == null) {
|
||||
throw new ArgumentNullException("value1");
|
||||
}
|
||||
|
||||
if(value2 == null) {
|
||||
throw new ArgumentNullException("value2");
|
||||
}
|
||||
|
||||
Op1 = op1;
|
||||
Op2 = op2;
|
||||
PropertyName = propertyName;
|
||||
Value1 = value1;
|
||||
Value2 = value2;
|
||||
}
|
||||
|
||||
public string Op1 { get; set; }
|
||||
public string Op2 { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
public string Value1 { get; set; }
|
||||
public string Value2 { get; set; }
|
||||
|
||||
public override string ToHql(IAlias alias) {
|
||||
var processed = String.Concat(alias.Name, ".", PropertyName);
|
||||
return String.Concat(processed, " ", Op1, " ", Value1, " ", Op2, " ", Value2);
|
||||
}
|
||||
}
|
||||
|
||||
public class CompositeHqlCriterion : HqlCriterion {
|
||||
public string Op { get; set; }
|
||||
public IList<IHqlCriterion> Criterions { get; private set; }
|
||||
@ -88,6 +128,10 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
return Convert.ToString(value, CultureInfo.InvariantCulture);
|
||||
case TypeCode.DateTime:
|
||||
// convert the date time to a valid string representation for Hql
|
||||
var sortableDateTime = ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
return quoteStrings ? String.Concat("'", sortableDateTime, "'") : sortableDateTime;
|
||||
}
|
||||
|
||||
return Convert.ToString(value, CultureInfo.InvariantCulture);
|
||||
@ -110,7 +154,7 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion Between(string propertyName, object lo, object hi) {
|
||||
return null;
|
||||
return new ComplexExpression("between", "and", propertyName, FormatValue(lo), FormatValue(hi));
|
||||
}
|
||||
|
||||
public static CompositeHqlCriterion Conjunction() {
|
||||
@ -126,7 +170,7 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion EqProperty(string propertyName, string otherPropertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("=", propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public static IHqlCriterion Ge(string propertyName, object value) {
|
||||
@ -134,7 +178,7 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion GeProperty(string propertyName, string otherPropertyName) {
|
||||
return null;
|
||||
return new BinaryExpression(">=", propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public static IHqlCriterion Gt(string propertyName, object value) {
|
||||
@ -142,7 +186,7 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion GtProperty(string propertyName, string otherPropertyName) {
|
||||
return null;
|
||||
return new BinaryExpression(">", propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public static IHqlCriterion IdEq(object value) {
|
||||
@ -178,19 +222,19 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion IsEmpty(string propertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("is", propertyName, "empty");
|
||||
}
|
||||
|
||||
public static IHqlCriterion IsNotEmpty(string propertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("is", propertyName, "not empty");
|
||||
}
|
||||
|
||||
public static IHqlCriterion IsNotNull(string propertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("is", propertyName, "not null");
|
||||
}
|
||||
|
||||
public static IHqlCriterion IsNull(string propertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("is", propertyName, "null");
|
||||
}
|
||||
|
||||
public static IHqlCriterion Le(string propertyName, object value) {
|
||||
@ -198,7 +242,7 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion LeProperty(string propertyName, string otherPropertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("<=", propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public static BinaryExpression Like(string propertyName, string value, HqlMatchMode matchMode) {
|
||||
@ -207,6 +251,7 @@ namespace Orchard.ContentManagement {
|
||||
value = "'" + value + "%'";
|
||||
break;
|
||||
case HqlMatchMode.Exact:
|
||||
value = "'" + value + "'";
|
||||
break;
|
||||
case HqlMatchMode.Anywhere:
|
||||
value = "'%" + value + "%'";
|
||||
@ -224,7 +269,7 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion LtProperty(string propertyName, string otherPropertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("<", propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public static IHqlCriterion NaturalId() {
|
||||
@ -232,11 +277,11 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public static IHqlCriterion Not(IHqlCriterion expression) {
|
||||
return null;
|
||||
return new NotExpression(expression);
|
||||
}
|
||||
|
||||
public static IHqlCriterion NotEqProperty(string propertyName, string otherPropertyName) {
|
||||
return null;
|
||||
return new BinaryExpression("!=", propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public static IHqlCriterion Or(IHqlCriterion lhs, IHqlCriterion rhs) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
|
||||
@ -37,149 +36,4 @@ namespace Orchard.ContentManagement {
|
||||
void NaturalId();
|
||||
}
|
||||
|
||||
public class DefaultHqlExpressionFactory : IHqlExpressionFactory {
|
||||
public IHqlCriterion Criterion { get; private set; }
|
||||
|
||||
public void Eq(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Eq(propertyName, value);
|
||||
}
|
||||
|
||||
public void Like(string propertyName, string value, HqlMatchMode matchMode) {
|
||||
Criterion = HqlRestrictions.Like(propertyName, value, matchMode);
|
||||
}
|
||||
|
||||
public void InsensitiveLike(string propertyName, string value, HqlMatchMode matchMode) {
|
||||
Criterion = HqlRestrictions.InsensitiveLike(propertyName, value, matchMode);
|
||||
}
|
||||
|
||||
public void Gt(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Gt(propertyName, value);
|
||||
}
|
||||
|
||||
public void Lt(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Lt(propertyName, value);
|
||||
}
|
||||
|
||||
public void Le(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Le(propertyName, value);
|
||||
}
|
||||
|
||||
public void Ge(string propertyName, object value) {
|
||||
Criterion = HqlRestrictions.Ge(propertyName, value);
|
||||
}
|
||||
|
||||
public void Between(string propertyName, object lo, object hi) {
|
||||
Criterion = HqlRestrictions.Between(propertyName, lo, hi);
|
||||
}
|
||||
|
||||
public void In(string propertyName, object[] values) {
|
||||
Criterion = HqlRestrictions.In(propertyName, values);
|
||||
}
|
||||
|
||||
public void In(string propertyName, ICollection values) {
|
||||
Criterion = HqlRestrictions.In(propertyName, values);
|
||||
}
|
||||
|
||||
public void InG<T>(string propertyName, ICollection<T> values) {
|
||||
Criterion = HqlRestrictions.InG(propertyName, values);
|
||||
}
|
||||
|
||||
public void IsNull(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsNull(propertyName);
|
||||
}
|
||||
|
||||
public void EqProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.EqProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void NotEqProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.NotEqProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void GtProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.GtProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void GeProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.GeProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void LtProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.LtProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void LeProperty(string propertyName, string otherPropertyName) {
|
||||
Criterion = HqlRestrictions.LeProperty(propertyName, otherPropertyName);
|
||||
}
|
||||
|
||||
public void IsNotNull(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsNotNull(propertyName);
|
||||
}
|
||||
|
||||
public void IsNotEmpty(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsNotEmpty(propertyName);
|
||||
}
|
||||
|
||||
public void IsEmpty(string propertyName) {
|
||||
Criterion = HqlRestrictions.IsEmpty(propertyName);
|
||||
}
|
||||
|
||||
public void And(Action<IHqlExpressionFactory> lhs, Action<IHqlExpressionFactory> rhs) {
|
||||
lhs(this);
|
||||
var a = Criterion;
|
||||
rhs(this);
|
||||
var b = Criterion;
|
||||
Criterion = HqlRestrictions.And(a, b);
|
||||
}
|
||||
|
||||
public void Or(Action<IHqlExpressionFactory> lhs, Action<IHqlExpressionFactory> rhs) {
|
||||
lhs(this);
|
||||
var a = Criterion;
|
||||
rhs(this);
|
||||
var b = Criterion;
|
||||
Criterion = HqlRestrictions.Or(a, b);
|
||||
}
|
||||
|
||||
public void Not(Action<IHqlExpressionFactory> expression) {
|
||||
expression(this);
|
||||
var a = Criterion;
|
||||
Criterion = HqlRestrictions.Not(a);
|
||||
}
|
||||
|
||||
public void Conjunction(Action<IHqlExpressionFactory> expression, params Action<IHqlExpressionFactory>[] otherExpressions) {
|
||||
var junction = HqlRestrictions.Conjunction();
|
||||
foreach (var exp in Enumerable.Empty<Action<IHqlExpressionFactory>>().Union(new[] { expression }).Union(otherExpressions)) {
|
||||
exp(this);
|
||||
junction.Add(Criterion);
|
||||
}
|
||||
|
||||
Criterion = junction;
|
||||
}
|
||||
|
||||
public void Disjunction(Action<IHqlExpressionFactory> expression, params Action<IHqlExpressionFactory>[] otherExpressions) {
|
||||
var junction = HqlRestrictions.Disjunction();
|
||||
foreach (var exp in Enumerable.Empty<Action<IHqlExpressionFactory>>().Union(new[] { expression }).Union(otherExpressions)) {
|
||||
exp(this);
|
||||
junction.Add(Criterion);
|
||||
}
|
||||
|
||||
Criterion = junction;
|
||||
}
|
||||
|
||||
public void AllEq(IDictionary propertyNameValues) {
|
||||
Criterion = HqlRestrictions.AllEq(propertyNameValues);
|
||||
}
|
||||
|
||||
public void NaturalId() {
|
||||
Criterion = HqlRestrictions.NaturalId();
|
||||
}
|
||||
}
|
||||
|
||||
public enum HqlMatchMode {
|
||||
Exact,
|
||||
Start,
|
||||
End,
|
||||
Anywhere
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,49 +4,179 @@ using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
|
||||
/// <summary>
|
||||
/// Reprensents dynamically created query on Content Items.
|
||||
/// </summary>
|
||||
public interface IHqlQuery {
|
||||
|
||||
/// <summary>
|
||||
/// The underlying <see cref="ContentManager"/> instance used to execute the query.
|
||||
/// </summary>
|
||||
IContentManager ContentManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Add content type constraints to the query.
|
||||
/// </summary>
|
||||
IHqlQuery ForType(params string[] contentTypes);
|
||||
|
||||
/// <summary>
|
||||
/// Adds versioning options to the query.
|
||||
/// </summary>
|
||||
IHqlQuery ForVersion(VersionOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Defines the resulting type.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IHqlQuery<T>"/></returns>
|
||||
IHqlQuery<T> ForPart<T>() where T : IContent;
|
||||
|
||||
/// <summary>
|
||||
/// Executes the query and returns all results.
|
||||
/// </summary>
|
||||
IEnumerable<ContentItem> List();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a subset of the matching content items.
|
||||
/// </summary>
|
||||
IEnumerable<ContentItem> Slice(int skip, int count);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of matching content items.
|
||||
/// </summary>
|
||||
int Count();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a join to a the query.
|
||||
/// </summary>
|
||||
/// <param name="alias">An expression pointing to the joined relationship.</param>
|
||||
IHqlQuery Join(Action<IAliasFactory> alias);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a where constraint to the query.
|
||||
/// </summary>
|
||||
/// <param name="alias">An expression pointing to the joined relationship.</param>
|
||||
/// <param name="predicate">A predicate expression.</param>
|
||||
IHqlQuery Where(Action<IAliasFactory> alias, Action<IHqlExpressionFactory> predicate);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a join to a specific relationship.
|
||||
/// </summary>
|
||||
/// <param name="alias">An expression pointing to the joined relationship.</param>
|
||||
/// <param name="order">An order expression.</param>
|
||||
IHqlQuery OrderBy(Action<IAliasFactory> alias, Action<IHqlSortFactory> order);
|
||||
}
|
||||
|
||||
public interface IHqlQuery<out TPart> where TPart : IContent {
|
||||
/// <summary>
|
||||
/// Reprensents dynamically created query on Content Items, having a specific Content Part.
|
||||
/// </summary>
|
||||
public interface IHqlQuery<TPart> where TPart : IContent {
|
||||
|
||||
/// <summary>
|
||||
/// Add content type constraints to the query.
|
||||
/// </summary>
|
||||
IHqlQuery<TPart> ForType(params string[] contentTypes);
|
||||
|
||||
/// <summary>
|
||||
/// Adds versioning options to the query.
|
||||
/// </summary>
|
||||
IHqlQuery<TPart> ForVersion(VersionOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Executes the query and returns all results.
|
||||
/// </summary>
|
||||
IEnumerable<TPart> List();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a subset of the matching content items.
|
||||
/// </summary>
|
||||
IEnumerable<TPart> Slice(int skip, int count);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of matching content items.
|
||||
/// </summary>
|
||||
int Count();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a join to a the query.
|
||||
/// </summary>
|
||||
/// <param name="alias">An expression pointing to the joined relationship.</param>
|
||||
IHqlQuery<TPart> Join(Action<IAliasFactory> alias);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a where constraint to the query.
|
||||
/// </summary>
|
||||
/// <param name="alias">An expression pointing to the joined relationship.</param>
|
||||
/// <param name="predicate">A predicate expression.</param>
|
||||
IHqlQuery<TPart> Where(Action<IAliasFactory> alias, Action<IHqlExpressionFactory> predicate);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a join to a specific relationship.
|
||||
/// </summary>
|
||||
/// <param name="alias">An expression pointing to the joined relationship.</param>
|
||||
/// <param name="order">An order expression.</param>
|
||||
IHqlQuery<TPart> OrderBy(Action<IAliasFactory> alias, Action<IHqlSortFactory> order);
|
||||
}
|
||||
|
||||
|
||||
public interface IAlias {
|
||||
|
||||
/// <summary>
|
||||
/// The name of the alias.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
public interface IAliasFactory {
|
||||
/// <summary>
|
||||
/// Creates a join on a content part record or returns it if it already exists.
|
||||
/// </summary>
|
||||
IAliasFactory ContentPartRecord<TRecord>() where TRecord : ContentPartRecord;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a join on a content part record or returns it if it already exists.
|
||||
/// </summary>
|
||||
IAliasFactory ContentPartRecord(Type contentPartRecord);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a join based on a property, or returns it if it already exists.
|
||||
/// </summary>
|
||||
IAliasFactory Property(string propertyName, string alias);
|
||||
IAliasFactory Named(string alias); // returns an existing alias
|
||||
|
||||
/// <summary>
|
||||
/// Returns an existing alias by its name.
|
||||
/// </summary>
|
||||
IAliasFactory Named(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an the <see cref="ContentItemRecord"/> alias.
|
||||
/// </summary>
|
||||
IAliasFactory ContentItem();
|
||||
|
||||
/// <summary>
|
||||
/// Returns an the <see cref="ContentItemVersionRecord"/> alias.
|
||||
/// </summary>
|
||||
IAliasFactory ContentItemVersion();
|
||||
|
||||
/// <summary>
|
||||
/// Returns an the <see cref="ContentTypeRecord"/> alias.
|
||||
/// </summary>
|
||||
IAliasFactory ContentType();
|
||||
}
|
||||
|
||||
public interface IHqlSortFactory {
|
||||
/// <summary>
|
||||
/// Sorts by ascending order
|
||||
/// </summary>
|
||||
void Asc(string propertyName);
|
||||
|
||||
/// <summary>
|
||||
/// Sorts by descending order
|
||||
/// </summary>
|
||||
void Desc(string propertyName);
|
||||
|
||||
/// <summary>
|
||||
/// Sorts randomly
|
||||
/// </summary>
|
||||
void Random(int seed);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user