-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A number of classes that help us decouple those classes from the rule…
…s the define their business characteristics
- Loading branch information
Showing
20 changed files
with
811 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FluentSpecification.Samples | ||
{ | ||
public class Customer | ||
{ | ||
public string FirstName { get; set; } | ||
public double Balance { get; set; } | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
FluentSpecification.Samples/FluentSpecification.Samples.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{8E9D5337-4557-4272-BD41-3A46FAE0F17A}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>FluentSpecification.Samples</RootNamespace> | ||
<AssemblyName>FluentSpecification.Samples</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Customer.cs" /> | ||
<Compile Include="Loan.cs" /> | ||
<Compile Include="LoanRepository.cs" /> | ||
<Compile Include="ObjectDumper.cs" /> | ||
<Compile Include="OverDueLoanSpecification.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="ValuedCustomerSpecification.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\FluentSpecification\FluentSpecification.csproj"> | ||
<Project>{483cfe02-fc33-47d3-bbd2-d89e5bbddf03}</Project> | ||
<Name>FluentSpecification</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FluentSpecification.Samples | ||
{ | ||
public class Loan | ||
{ | ||
|
||
public string Holder { get; set; } | ||
public double Amount { get; set; } | ||
public DateTime DateTaken { get; set; } | ||
public TimeSpan LoanPeriod { get; set; } | ||
|
||
|
||
public bool IsOverDue() | ||
{ | ||
return DateTaken.Add(LoanPeriod) > DateTime.Now; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FluentSpecification.Samples | ||
{ | ||
|
||
public class LoanRepository | ||
{ | ||
public IQueryable<Loan> FindElementsBy(SpecificationBase<Loan> spec) | ||
{ | ||
Loan[] loans = new[]{ | ||
new Loan(){DateTaken = DateTime.Now.AddDays(-15) , LoanPeriod = new TimeSpan(14,0,0,0),Amount = 15000.0}, | ||
new Loan(){DateTaken = DateTime.Now.AddDays(-5), LoanPeriod = new TimeSpan(6,0,0,0),Amount = 10000.0}, | ||
new Loan(){DateTaken = DateTime.Now.AddDays(-7), LoanPeriod = new TimeSpan(6,0,0,0),Amount = 5000.0} | ||
}; | ||
|
||
|
||
|
||
return spec.SatisfyingElementsFrom(loans.AsQueryable()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// Copyright © Microsoft Corporation. All Rights Reserved. | ||
// This code released under the terms of the | ||
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) | ||
// | ||
//Copyright (C) Microsoft Corporation. All rights reserved. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace FluentSpecification.Samples | ||
{ | ||
public class ObjectDumper { | ||
|
||
public static void Write(object element) | ||
{ | ||
Write(element, 0); | ||
} | ||
|
||
public static void Write(object element, int depth) | ||
{ | ||
Write(element, depth, Console.Out); | ||
} | ||
|
||
public static void Write(object element, int depth, TextWriter log) | ||
{ | ||
ObjectDumper dumper = new ObjectDumper(depth); | ||
dumper.writer = log; | ||
dumper.WriteObject(null, element); | ||
} | ||
|
||
TextWriter writer; | ||
int pos; | ||
int level; | ||
int depth; | ||
|
||
private ObjectDumper(int depth) | ||
{ | ||
this.depth = depth; | ||
} | ||
|
||
private void Write(string s) | ||
{ | ||
if (s != null) { | ||
writer.Write(s); | ||
pos += s.Length; | ||
} | ||
} | ||
|
||
private void WriteIndent() | ||
{ | ||
for (int i = 0; i < level; i++) writer.Write(" "); | ||
} | ||
|
||
private void WriteLine() | ||
{ | ||
writer.WriteLine(); | ||
pos = 0; | ||
} | ||
|
||
private void WriteTab() | ||
{ | ||
Write(" "); | ||
while (pos % 8 != 0) Write(" "); | ||
} | ||
|
||
private void WriteObject(string prefix, object element) | ||
{ | ||
|
||
|
||
if (element == null || element is ValueType || element is string) { | ||
WriteIndent(); | ||
Write(prefix); | ||
WriteValue(element); | ||
WriteLine(); | ||
} | ||
else { | ||
IEnumerable enumerableElement = element as IEnumerable; | ||
if (enumerableElement != null) { | ||
foreach (object item in enumerableElement) { | ||
if (item is IEnumerable && !(item is string)) { | ||
WriteIndent(); | ||
Write(prefix); | ||
Write("..."); | ||
WriteLine(); | ||
if (level < depth) { | ||
level++; | ||
WriteObject(prefix, item); | ||
level--; | ||
} | ||
} | ||
else { | ||
WriteObject(prefix, item); | ||
} | ||
} | ||
} | ||
else { | ||
MemberInfo[] members = element.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance); | ||
WriteIndent(); | ||
Write(prefix); | ||
bool propWritten = false; | ||
foreach (MemberInfo m in members) { | ||
FieldInfo f = m as FieldInfo; | ||
PropertyInfo p = m as PropertyInfo; | ||
if (f != null || p != null) { | ||
if (propWritten) { | ||
WriteTab(); | ||
} | ||
else { | ||
propWritten = true; | ||
} | ||
Write(m.Name); | ||
Write("="); | ||
Type t = f != null ? f.FieldType : p.PropertyType; | ||
if (t.IsValueType || t == typeof(string)) { | ||
WriteValue(f != null ? f.GetValue(element) : p.GetValue(element, null)); | ||
} | ||
else { | ||
if (typeof(IEnumerable).IsAssignableFrom(t)) { | ||
Write("..."); | ||
} | ||
else { | ||
Write("{ }"); | ||
} | ||
} | ||
} | ||
} | ||
if (propWritten) WriteLine(); | ||
if (level < depth) { | ||
foreach (MemberInfo m in members) { | ||
FieldInfo f = m as FieldInfo; | ||
PropertyInfo p = m as PropertyInfo; | ||
if (f != null || p != null) { | ||
Type t = f != null ? f.FieldType : p.PropertyType; | ||
if (!(t.IsValueType || t == typeof(string))) { | ||
object value = f != null ? f.GetValue(element) : p.GetValue(element, null); | ||
if (value != null) { | ||
level++; | ||
WriteObject(m.Name + ": ", value); | ||
level--; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void WriteValue(object o) | ||
{ | ||
if (o == null) { | ||
Write("null"); | ||
} | ||
else if (o is DateTime) { | ||
Write(((DateTime)o).ToShortDateString()); | ||
} | ||
else if (o is ValueType || o is string) { | ||
Write(o.ToString()); | ||
} | ||
else if (o is IEnumerable) { | ||
Write("..."); | ||
} | ||
else { | ||
Write("{ }"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.