Skip to content

Commit abc9ff2

Browse files
authored
Merge pull request #32 from codepb/develop
Querying Improvements and Validation
2 parents ca3749a + cee11ce commit abc9ff2

33 files changed

Lines changed: 431 additions & 60 deletions

DDDToolkit.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "DDDToolkit.Samples.Library.
3737
EndProject
3838
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DDDToolkit.Querying", "src\DDDToolkit.Querying\DDDToolkit.Querying.csproj", "{AAAF943F-C3DE-4BD5-BC2D-850E77A9B607}"
3939
EndProject
40-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DDDToolkit.Querying.Tests", "DDDToolkit.Querying.Tests\DDDToolkit.Querying.Tests.csproj", "{4D18A7F4-169C-4399-BFF3-F2F8AE665C55}"
40+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DDDToolkit.Querying.Tests", "tests\DDDToolkit.Querying.Tests\DDDToolkit.Querying.Tests.csproj", "{4D18A7F4-169C-4399-BFF3-F2F8AE665C55}"
41+
EndProject
42+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DDDToolkit.Validation", "src\DDDToolkit.Validation\DDDToolkit.Validation.csproj", "{0D0A57EF-3B95-4D6B-A3E6-0217FEB0DC6F}"
4143
EndProject
4244
Global
4345
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -103,6 +105,10 @@ Global
103105
{4D18A7F4-169C-4399-BFF3-F2F8AE665C55}.Debug|Any CPU.Build.0 = Debug|Any CPU
104106
{4D18A7F4-169C-4399-BFF3-F2F8AE665C55}.Release|Any CPU.ActiveCfg = Release|Any CPU
105107
{4D18A7F4-169C-4399-BFF3-F2F8AE665C55}.Release|Any CPU.Build.0 = Release|Any CPU
108+
{0D0A57EF-3B95-4D6B-A3E6-0217FEB0DC6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
109+
{0D0A57EF-3B95-4D6B-A3E6-0217FEB0DC6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
110+
{0D0A57EF-3B95-4D6B-A3E6-0217FEB0DC6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
111+
{0D0A57EF-3B95-4D6B-A3E6-0217FEB0DC6F}.Release|Any CPU.Build.0 = Release|Any CPU
106112
EndGlobalSection
107113
GlobalSection(SolutionProperties) = preSolution
108114
HideSolutionNode = FALSE
@@ -123,6 +129,7 @@ Global
123129
{1D41D8D2-B6A5-47DD-8E98-9512EC48B429} = {BDD881C3-118B-42D6-9D77-DDAB213CA4B0}
124130
{AAAF943F-C3DE-4BD5-BC2D-850E77A9B607} = {EF054C6D-056E-417A-A40A-376A20DF90A6}
125131
{4D18A7F4-169C-4399-BFF3-F2F8AE665C55} = {57967491-B4BB-44B9-B270-6533A1E388B0}
132+
{0D0A57EF-3B95-4D6B-A3E6-0217FEB0DC6F} = {EF054C6D-056E-417A-A40A-376A20DF90A6}
126133
EndGlobalSection
127134
GlobalSection(ExtensibilityGlobals) = postSolution
128135
SolutionGuid = {E3DCC906-DD65-4478-A617-AC943C719834}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# DDDToolkit
22
[<img src="https://ninthlight.visualstudio.com/_apis/public/build/definitions/2a0b2dd5-5fb3-41e4-a3bb-09ae80277b94/6/badge"/>](https://ninthlight.visualstudio.com/2a0b2dd5-5fb3-41e4-a3bb-09ae80277b94/_build/index?definitionId=6)
3+
4+
DDD Toolkit is a collection of libraries to support development following a Domain Driven Design pattern, using dotnet standard. The libraries are designed to support development by providing the building blocks for you to build on.
5+
6+
Find more in the [Wiki](https://github.com/codepb/DDDToolkit/wiki)

samples/library/DDDToolkit.Samples.Library.Domain/DDDToolkit.Samples.Library.Domain.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<ItemGroup>
1212
<ProjectReference Include="..\..\..\src\DDDToolkit.Core\DDDToolkit.Core.csproj" />
13+
<ProjectReference Include="..\..\..\src\DDDToolkit.Validation\DDDToolkit.Validation.csproj" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

samples/library/DDDToolkit.Samples.Library.Domain/ISBN.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ protected ISBN() { }
1515
[JsonConstructor]
1616
public ISBN(string value)
1717
{
18-
if(!IsValid(value))
19-
{
20-
throw new ArgumentException($"{value} is not a valid ISBN.", nameof(value));
21-
}
18+
2219
_value = value;
2320
}
2421

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using DDDToolkit.Querying;
2+
3+
namespace DDDToolkit.Samples.Library.Domain
4+
{
5+
public class AuthorHasFirstName : Query<Author>
6+
{
7+
public AuthorHasFirstName() : base(Has(a => a.FirstName).Satisfying(x => !string.IsNullOrWhiteSpace(x)))
8+
{
9+
}
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using DDDToolkit.Querying;
2+
3+
namespace DDDToolkit.Samples.Library.Domain
4+
{
5+
internal class AuthorHasLastName : Query<Author>
6+
{
7+
public AuthorHasLastName() : base(Has(a => a.LastName).Satisfying(x => !string.IsNullOrWhiteSpace(x)))
8+
{
9+
}
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using DDDToolkit.Querying;
2+
3+
namespace DDDToolkit.Samples.Library.Domain
4+
{
5+
public class AuthorHasName : Query<Author>
6+
{
7+
public AuthorHasName(string firstName, string lastName)
8+
: base(
9+
Has(a => a.FirstName)
10+
.EqualTo(firstName)
11+
.And()
12+
.Has(a => a.LastName)
13+
.EqualTo(lastName)
14+
) { }
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using DDDToolkit.Validation;
2+
using DDDToolkit.Querying;
3+
using DDDToolkit.Samples.Library.Domain.Validation;
4+
using System;
5+
6+
namespace DDDToolkit.Samples.Library.Domain
7+
{
8+
public class BookValidator : Validator<Book>
9+
{
10+
public BookValidator()
11+
{
12+
Property(b => b.ISBN)
13+
.HasRule<IsbnIsNumeric>("ISBN is not numeric")
14+
.HasRule<IsbnIsOfValidLength>();
15+
Property(b => b.Author)
16+
.HasRule<AuthorHasFirstName>()
17+
.HasRule<AuthorHasLastName>();
18+
Property(b => b.Title)
19+
.HasRule(Query<string>.Is.Satisfying(s => !string.IsNullOrEmpty(s)), "Title is required");
20+
}
21+
}
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using DDDToolkit.Querying;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using System.Linq.Expressions;
6+
using System.Text.RegularExpressions;
7+
8+
namespace DDDToolkit.Samples.Library.Domain.Validation
9+
{
10+
public class IsbnIsNumeric : Query<ISBN>
11+
{
12+
public IsbnIsNumeric() :
13+
base(Has(i => i.Value).Satisfying(i => Regex.IsMatch(i, @"^\d+$")))
14+
{
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using DDDToolkit.Querying;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using System.Linq.Expressions;
6+
7+
namespace DDDToolkit.Samples.Library.Domain.Validation
8+
{
9+
public class IsbnIsOfValidLength : Query<ISBN>
10+
{
11+
public IsbnIsOfValidLength()
12+
: base(Has(i => i.Value.Length)
13+
.EqualToAnyOf(10, 13))
14+
{
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)