Skip to content

Commit

Permalink
Should_order_by
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMischke committed Jun 10, 2014
1 parent 0c6350c commit 8caf63b
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions scr/Lib.Persistence/2 Lib.Persistence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
1 change: 0 additions & 1 deletion scr/Lib.Persistence/Persistence.NHibernate/RepositoryDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public virtual IList<TDomainObject> GetBy(ISearchDesc searchSpec)
return GetBy(searchSpec, null);
}


/// <param name="searchSpec"></param>
/// <param name="criteriaExtender">Here you can plug in additional changes of the criteria.</param>
/// <returns></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ internal void EndAdding()
IsAdding = false;
}

public void Add(OrderBy orderBy)
public OrderByCriteria Add(OrderBy orderBy)
{
CurrentList.RemoveAll(order => order.PropertyName == orderBy.PropertyName);
CurrentList.Add(orderBy);
return this;
}

public bool IsSet()
Expand Down
1 change: 1 addition & 0 deletions scr/Lib.Settings/2 Lib.Settings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
1 change: 1 addition & 0 deletions scr/Lib/1 Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
3 changes: 3 additions & 0 deletions scr/Lib/ExtensionMethods/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public static string Truncate(this string text, int maxLength)
/// <returns></returns>
public static List<string> WordWrap(this string text, int maxLineLength)
{
if (String.IsNullOrEmpty(text))
return new List<string>();

text = text.Replace(Environment.NewLine, "\n");

var lines = text.Split('\n').ToList();
Expand Down
3 changes: 2 additions & 1 deletion scr/Seedworks.sln.DotSettings.user

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions scr/Tests/Lib.Persistance/RepositoryOrderBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Conventions;
using NUnit.Framework;
using Seedworks.Lib.Persistence;

namespace Seedworks.Tests.Lib.Persistence
{
public class RepositoryOrderBy : BaseTestEntitites
{
[Test]
public void Should_order_by()
{
var entityRepository = Resolve<SampleEntityRepository>();
entityRepository.Create(new SampleEntity { Name = "A", Text = "A"});
entityRepository.Create(new SampleEntity { Name = "B", Text = "B"});
entityRepository.Create(new SampleEntity { Name = "B", Text = "A"});

var spec = new SampleEntitySearchSpec();
spec.OrderBy.Name.Asc();
spec.OrderBy.Text.Asc();

var entities = entityRepository.GetBy(spec);

Assert.That(entities[0].Name, Is.EqualTo("A"));
Assert.That(entities[1].Name, Is.EqualTo("B"));
Assert.That(entities[1].Text, Is.EqualTo("A"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class SampleEntity : IPersistable, WithDateModified, WithDateCreated
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Text { get; set; }

public virtual DateTime DateCreated { get; set; }
public virtual DateTime DateModified { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public SampleEntityMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Text);
Map(x => x.DateCreated);
Map(x => x.DateModified);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Seedworks.Tests.Lib.Persistence
{
public class SampleEntitySearchSpec : SearchSpecificationBase<SampleEntityFilter, OrderByCriteria>
public class SampleEntitySearchSpec : SearchSpecificationBase<SampleEntityFilter, SampleOrderBy>
{
}

Expand All @@ -26,13 +26,19 @@ public SampleEntityFilter()

public class SampleOrderBy : OrderByCriteria
{
public OrderBy Name;
public OrderBy Text;

public OrderBy Created;
public OrderBy Modified;

public SampleOrderBy()
{
Created = new OrderBy("DateCreated", this);
Modified = new OrderBy("DateModified", this);

Name = new OrderBy("Name", this);
Text = new OrderBy("Text", this);
}
}

Expand Down
2 changes: 2 additions & 0 deletions scr/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -83,6 +84,7 @@
<Compile Include="Infrastructure\BaseTestSetting.cs" />
<Compile Include="Lib.Persistance\EntityFilterTestsEntitites.cs" />
<Compile Include="Lib.Persistance\RepositoryGetBySingleTestsEntitites.cs" />
<Compile Include="Lib.Persistance\RepositoryOrderBy.cs" />
<Compile Include="Lib.Persistance\Sample\Entity.BaseTypeEntity\SampleEntityBaseEntity.cs" />
<Compile Include="Lib.Persistance\Sample\Entity.BaseTypeEntity\SampleEntityBaseEntityMap.cs" />
<Compile Include="Lib.Persistance\Sample\Entity.BaseTypeEntity\SampleEntityBaseEntityRepository.cs" />
Expand Down
1 change: 1 addition & 0 deletions scr/Web.Lib.State/3 Web.Lib.State.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down

0 comments on commit 8caf63b

Please sign in to comment.