Skip to content

Commit 3845293

Browse files
committed
A number of classes that help us decouple those classes from the rules the define their business characteristics
1 parent 08003ff commit 3845293

20 files changed

+811
-0
lines changed

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FluentSpecification.Samples
8+
{
9+
public class Customer
10+
{
11+
public string FirstName { get; set; }
12+
public double Balance { get; set; }
13+
14+
}
15+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{8E9D5337-4557-4272-BD41-3A46FAE0F17A}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>FluentSpecification.Samples</RootNamespace>
11+
<AssemblyName>FluentSpecification.Samples</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Customer.cs" />
47+
<Compile Include="Loan.cs" />
48+
<Compile Include="LoanRepository.cs" />
49+
<Compile Include="ObjectDumper.cs" />
50+
<Compile Include="OverDueLoanSpecification.cs" />
51+
<Compile Include="Program.cs" />
52+
<Compile Include="Properties\AssemblyInfo.cs" />
53+
<Compile Include="ValuedCustomerSpecification.cs" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<None Include="App.config" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<ProjectReference Include="..\FluentSpecification\FluentSpecification.csproj">
60+
<Project>{483cfe02-fc33-47d3-bbd2-d89e5bbddf03}</Project>
61+
<Name>FluentSpecification</Name>
62+
</ProjectReference>
63+
</ItemGroup>
64+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
65+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
66+
Other similar extension points exist, see Microsoft.Common.targets.
67+
<Target Name="BeforeBuild">
68+
</Target>
69+
<Target Name="AfterBuild">
70+
</Target>
71+
-->
72+
</Project>

FluentSpecification.Samples/Loan.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FluentSpecification.Samples
8+
{
9+
public class Loan
10+
{
11+
12+
public string Holder { get; set; }
13+
public double Amount { get; set; }
14+
public DateTime DateTaken { get; set; }
15+
public TimeSpan LoanPeriod { get; set; }
16+
17+
18+
public bool IsOverDue()
19+
{
20+
return DateTaken.Add(LoanPeriod) > DateTime.Now;
21+
}
22+
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FluentSpecification.Samples
8+
{
9+
10+
public class LoanRepository
11+
{
12+
public IQueryable<Loan> FindElementsBy(SpecificationBase<Loan> spec)
13+
{
14+
Loan[] loans = new[]{
15+
new Loan(){DateTaken = DateTime.Now.AddDays(-15) , LoanPeriod = new TimeSpan(14,0,0,0),Amount = 15000.0},
16+
new Loan(){DateTaken = DateTime.Now.AddDays(-5), LoanPeriod = new TimeSpan(6,0,0,0),Amount = 10000.0},
17+
new Loan(){DateTaken = DateTime.Now.AddDays(-7), LoanPeriod = new TimeSpan(6,0,0,0),Amount = 5000.0}
18+
};
19+
20+
21+
22+
return spec.SatisfyingElementsFrom(loans.AsQueryable());
23+
}
24+
}
25+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright © Microsoft Corporation. All Rights Reserved.
2+
// This code released under the terms of the
3+
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
4+
//
5+
//Copyright (C) Microsoft Corporation. All rights reserved.
6+
7+
using System;
8+
using System.Collections;
9+
using System.IO;
10+
using System.Reflection;
11+
12+
namespace FluentSpecification.Samples
13+
{
14+
public class ObjectDumper {
15+
16+
public static void Write(object element)
17+
{
18+
Write(element, 0);
19+
}
20+
21+
public static void Write(object element, int depth)
22+
{
23+
Write(element, depth, Console.Out);
24+
}
25+
26+
public static void Write(object element, int depth, TextWriter log)
27+
{
28+
ObjectDumper dumper = new ObjectDumper(depth);
29+
dumper.writer = log;
30+
dumper.WriteObject(null, element);
31+
}
32+
33+
TextWriter writer;
34+
int pos;
35+
int level;
36+
int depth;
37+
38+
private ObjectDumper(int depth)
39+
{
40+
this.depth = depth;
41+
}
42+
43+
private void Write(string s)
44+
{
45+
if (s != null) {
46+
writer.Write(s);
47+
pos += s.Length;
48+
}
49+
}
50+
51+
private void WriteIndent()
52+
{
53+
for (int i = 0; i < level; i++) writer.Write(" ");
54+
}
55+
56+
private void WriteLine()
57+
{
58+
writer.WriteLine();
59+
pos = 0;
60+
}
61+
62+
private void WriteTab()
63+
{
64+
Write(" ");
65+
while (pos % 8 != 0) Write(" ");
66+
}
67+
68+
private void WriteObject(string prefix, object element)
69+
{
70+
71+
72+
if (element == null || element is ValueType || element is string) {
73+
WriteIndent();
74+
Write(prefix);
75+
WriteValue(element);
76+
WriteLine();
77+
}
78+
else {
79+
IEnumerable enumerableElement = element as IEnumerable;
80+
if (enumerableElement != null) {
81+
foreach (object item in enumerableElement) {
82+
if (item is IEnumerable && !(item is string)) {
83+
WriteIndent();
84+
Write(prefix);
85+
Write("...");
86+
WriteLine();
87+
if (level < depth) {
88+
level++;
89+
WriteObject(prefix, item);
90+
level--;
91+
}
92+
}
93+
else {
94+
WriteObject(prefix, item);
95+
}
96+
}
97+
}
98+
else {
99+
MemberInfo[] members = element.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance);
100+
WriteIndent();
101+
Write(prefix);
102+
bool propWritten = false;
103+
foreach (MemberInfo m in members) {
104+
FieldInfo f = m as FieldInfo;
105+
PropertyInfo p = m as PropertyInfo;
106+
if (f != null || p != null) {
107+
if (propWritten) {
108+
WriteTab();
109+
}
110+
else {
111+
propWritten = true;
112+
}
113+
Write(m.Name);
114+
Write("=");
115+
Type t = f != null ? f.FieldType : p.PropertyType;
116+
if (t.IsValueType || t == typeof(string)) {
117+
WriteValue(f != null ? f.GetValue(element) : p.GetValue(element, null));
118+
}
119+
else {
120+
if (typeof(IEnumerable).IsAssignableFrom(t)) {
121+
Write("...");
122+
}
123+
else {
124+
Write("{ }");
125+
}
126+
}
127+
}
128+
}
129+
if (propWritten) WriteLine();
130+
if (level < depth) {
131+
foreach (MemberInfo m in members) {
132+
FieldInfo f = m as FieldInfo;
133+
PropertyInfo p = m as PropertyInfo;
134+
if (f != null || p != null) {
135+
Type t = f != null ? f.FieldType : p.PropertyType;
136+
if (!(t.IsValueType || t == typeof(string))) {
137+
object value = f != null ? f.GetValue(element) : p.GetValue(element, null);
138+
if (value != null) {
139+
level++;
140+
WriteObject(m.Name + ": ", value);
141+
level--;
142+
}
143+
}
144+
}
145+
}
146+
}
147+
}
148+
}
149+
}
150+
151+
private void WriteValue(object o)
152+
{
153+
if (o == null) {
154+
Write("null");
155+
}
156+
else if (o is DateTime) {
157+
Write(((DateTime)o).ToShortDateString());
158+
}
159+
else if (o is ValueType || o is string) {
160+
Write(o.ToString());
161+
}
162+
else if (o is IEnumerable) {
163+
Write("...");
164+
}
165+
else {
166+
Write("{ }");
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)