Skip to content

Commit 98aaa11

Browse files
committed
Merge branch 'release/2.0.0' into production
2 parents 5155c26 + 1c41b3d commit 98aaa11

33 files changed

Lines changed: 1555 additions & 1158 deletions

CSF.Specifications.Tests/AutoMoqDataAttribute.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
namespace CSF.Specifications.Tests
3232
{
33-
public class AutoMoqDataAttribute : AutoDataAttribute
34-
{
35-
public AutoMoqDataAttribute() : base(()=> new Fixture().Customize(new AutoMoqCustomization()))
33+
public class AutoMoqDataAttribute : AutoDataAttribute
3634
{
35+
public AutoMoqDataAttribute() : base(() => new Fixture().Customize(new AutoMoqCustomization()))
36+
{
37+
}
3738
}
38-
}
3939
}

CSF.Specifications.Tests/CSF.Specifications.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<IsTestProject>true</IsTestProject>
6-
<ReleaseVersion>1.2.0</ReleaseVersion>
6+
<ReleaseVersion>2.0.0</ReleaseVersion>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

CSF.Specifications.Tests/PredicateTests.cs

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,72 +30,72 @@
3030

3131
namespace CSF.Specifications.Tests
3232
{
33-
[TestFixture,Parallelizable]
34-
public class PredicateTests
35-
{
36-
[Test,AutoMoqData]
37-
public void And_creates_predicate_which_satisfies_both_predicates(Person personOne,
38-
Person personTwo,
39-
Person personThree)
33+
[TestFixture, Parallelizable]
34+
public class PredicateTests
4035
{
41-
// Arrange
42-
personOne.Name = "Billy";
43-
personTwo.Name = "Bob";
44-
personThree.Name = "Thornton";
36+
[Test, AutoMoqData]
37+
public void And_creates_predicate_which_satisfies_both_predicates(Person personOne,
38+
Person personTwo,
39+
Person personThree)
40+
{
41+
// Arrange
42+
personOne.Name = "Billy";
43+
personTwo.Name = "Bob";
44+
personThree.Name = "Thornton";
4545

46-
var firstPredicate = Predicate.Create<Person>(p => p.Name.StartsWith("B", StringComparison.InvariantCulture));
47-
var secondPredicate = Predicate.Create<Person>(p => p.Name.EndsWith("b", StringComparison.InvariantCulture));
46+
var firstPredicate = Predicate.Create<Person>(p => p.Name.StartsWith("B", StringComparison.InvariantCulture));
47+
var secondPredicate = Predicate.Create<Person>(p => p.Name.EndsWith("b", StringComparison.InvariantCulture));
4848

49-
// Act
50-
var composedPredicate = firstPredicate.And(secondPredicate);
49+
// Act
50+
var composedPredicate = firstPredicate.And(secondPredicate);
5151

52-
// Assert
53-
Assert.That(() => composedPredicate.Compile()(personOne), Is.False, "First person is not matched");
54-
Assert.That(() => composedPredicate.Compile()(personTwo), Is.True, "Second person is matched");
55-
Assert.That(() => composedPredicate.Compile()(personThree), Is.False, "Third person is not matched");
56-
}
52+
// Assert
53+
Assert.That(() => composedPredicate.Compile()(personOne), Is.False, "First person is not matched");
54+
Assert.That(() => composedPredicate.Compile()(personTwo), Is.True, "Second person is matched");
55+
Assert.That(() => composedPredicate.Compile()(personThree), Is.False, "Third person is not matched");
56+
}
5757

58-
[Test,AutoMoqData]
59-
public void Or_creates_predicate_which_satisfies_both_predicates(Person personOne,
60-
Person personTwo,
61-
Person personThree)
62-
{
63-
// Arrange
64-
personOne.Name = "Billy";
65-
personTwo.Name = "Bob";
66-
personThree.Name = "Thornton";
58+
[Test, AutoMoqData]
59+
public void Or_creates_predicate_which_satisfies_both_predicates(Person personOne,
60+
Person personTwo,
61+
Person personThree)
62+
{
63+
// Arrange
64+
personOne.Name = "Billy";
65+
personTwo.Name = "Bob";
66+
personThree.Name = "Thornton";
6767

68-
var firstPredicate = Predicate.Create<Person>(p => p.Name.EndsWith("y", StringComparison.InvariantCulture));
69-
var secondPredicate = Predicate.Create<Person>(p => p.Name.EndsWith("n", StringComparison.InvariantCulture));
68+
var firstPredicate = Predicate.Create<Person>(p => p.Name.EndsWith("y", StringComparison.InvariantCulture));
69+
var secondPredicate = Predicate.Create<Person>(p => p.Name.EndsWith("n", StringComparison.InvariantCulture));
7070

71-
// Act
72-
var composedPredicate = firstPredicate.Or(secondPredicate);
71+
// Act
72+
var composedPredicate = firstPredicate.Or(secondPredicate);
7373

74-
// Assert
75-
Assert.That(() => composedPredicate.Compile()(personOne), Is.True, "First person is matched");
76-
Assert.That(() => composedPredicate.Compile()(personTwo), Is.False, "Second person is not matched");
77-
Assert.That(() => composedPredicate.Compile()(personThree), Is.True, "Third person is matched");
78-
}
74+
// Assert
75+
Assert.That(() => composedPredicate.Compile()(personOne), Is.True, "First person is matched");
76+
Assert.That(() => composedPredicate.Compile()(personTwo), Is.False, "Second person is not matched");
77+
Assert.That(() => composedPredicate.Compile()(personThree), Is.True, "Third person is matched");
78+
}
7979

80-
[Test,AutoMoqData]
81-
public void Not_negates_a_predicate(Person personOne,
82-
Person personTwo,
83-
Person personThree)
84-
{
85-
// Arrange
86-
personOne.Name = "Billy";
87-
personTwo.Name = "Bob";
88-
personThree.Name = "Thornton";
80+
[Test, AutoMoqData]
81+
public void Not_negates_a_predicate(Person personOne,
82+
Person personTwo,
83+
Person personThree)
84+
{
85+
// Arrange
86+
personOne.Name = "Billy";
87+
personTwo.Name = "Bob";
88+
personThree.Name = "Thornton";
8989

90-
var predicate = Predicate.Create<Person>(p => p.Name.EndsWith("y", StringComparison.InvariantCulture));
90+
var predicate = Predicate.Create<Person>(p => p.Name.EndsWith("y", StringComparison.InvariantCulture));
9191

92-
// Act
93-
var composedPredicate = predicate.Not();
92+
// Act
93+
var composedPredicate = predicate.Not();
9494

95-
// Assert
96-
Assert.That(() => composedPredicate.Compile()(personOne), Is.False, "First person is not matched");
97-
Assert.That(() => composedPredicate.Compile()(personTwo), Is.True, "Second person is matched");
98-
Assert.That(() => composedPredicate.Compile()(personThree), Is.True, "Third person is matched");
95+
// Assert
96+
Assert.That(() => composedPredicate.Compile()(personOne), Is.False, "First person is not matched");
97+
Assert.That(() => composedPredicate.Compile()(personTwo), Is.True, "Second person is matched");
98+
Assert.That(() => composedPredicate.Compile()(personThree), Is.True, "Third person is matched");
99+
}
99100
}
100-
}
101101
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//
2+
// SpecificationExtensionsTests.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@csf-dev.com>
6+
//
7+
// Copyright (c) 2018 Craig Fowler
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using NUnit.Framework;
27+
using System.Linq;
28+
using CSF.Specifications.Tests.Stubs;
29+
using System.Collections.Generic;
30+
31+
namespace CSF.Specifications.Tests.Specifications
32+
{
33+
[TestFixture, Parallelizable]
34+
public class EnumerableExtensionsTests
35+
{
36+
[Test, AutoMoqData]
37+
public void Where_filters_by_spec_expression()
38+
{
39+
Assert.That(() => GetCollection().Where(GetSpecExpression("Anna")).FirstOrDefault()?.Identity, Is.EqualTo(2));
40+
}
41+
42+
[Test, AutoMoqData]
43+
public void First_uses_spec_expression()
44+
{
45+
Assert.That(() => GetCollection().First(GetSpecExpression("Anna"))?.Identity, Is.EqualTo(2));
46+
}
47+
48+
[Test, AutoMoqData]
49+
public void FirstOrDefault_uses_spec_expression()
50+
{
51+
Assert.That(() => GetCollection().FirstOrDefault(GetSpecExpression("Anna"))?.Identity, Is.EqualTo(2));
52+
}
53+
54+
[Test, AutoMoqData]
55+
public void Single_uses_spec_expression()
56+
{
57+
Assert.That(() => GetCollection().Single(GetSpecExpression("Anna"))?.Identity, Is.EqualTo(2));
58+
}
59+
60+
[Test, AutoMoqData]
61+
public void SingleOrDefault_uses_spec_expression()
62+
{
63+
Assert.That(() => GetCollection().SingleOrDefault(GetSpecExpression("Anna"))?.Identity, Is.EqualTo(2));
64+
}
65+
66+
[Test, AutoMoqData]
67+
public void Count_uses_spec_expression()
68+
{
69+
Assert.That(() => GetCollection().Count(GetSpecExpression("Anna")), Is.EqualTo(1));
70+
}
71+
72+
[Test, AutoMoqData]
73+
public void Any_uses_spec_expression()
74+
{
75+
Assert.That(() => GetCollection().Any(GetSpecExpression("Anna")), Is.True);
76+
}
77+
78+
[Test, AutoMoqData]
79+
public void Where_filters_by_spec_function()
80+
{
81+
Assert.That(() => GetCollection().Where(GetSpecFunction("Anna")).FirstOrDefault()?.Identity, Is.EqualTo(2));
82+
}
83+
84+
[Test, AutoMoqData]
85+
public void First_uses_spec_function()
86+
{
87+
Assert.That(() => GetCollection().First(GetSpecFunction("Anna"))?.Identity, Is.EqualTo(2));
88+
}
89+
90+
[Test, AutoMoqData]
91+
public void FirstOrDefault_uses_spec_function()
92+
{
93+
Assert.That(() => GetCollection().FirstOrDefault(GetSpecFunction("Anna"))?.Identity, Is.EqualTo(2));
94+
}
95+
96+
[Test, AutoMoqData]
97+
public void Single_uses_spec_function()
98+
{
99+
Assert.That(() => GetCollection().Single(GetSpecFunction("Anna"))?.Identity, Is.EqualTo(2));
100+
}
101+
102+
[Test, AutoMoqData]
103+
public void SingleOrDefault_uses_spec_function()
104+
{
105+
Assert.That(() => GetCollection().SingleOrDefault(GetSpecFunction("Anna"))?.Identity, Is.EqualTo(2));
106+
}
107+
108+
[Test, AutoMoqData]
109+
public void Count_uses_spec_function()
110+
{
111+
Assert.That(() => GetCollection().Count(GetSpecFunction("Anna")), Is.EqualTo(1));
112+
}
113+
114+
[Test, AutoMoqData]
115+
public void Any_uses_spec_function()
116+
{
117+
Assert.That(() => GetCollection().Any(GetSpecFunction("Anna")), Is.True);
118+
}
119+
120+
ISpecificationExpression<Person> GetSpecExpression(string name) => new PersonNameSpecificationExpression(name);
121+
122+
ISpecificationFunction<Person> GetSpecFunction(string name) => new PersonNameSpecificationFunction(name);
123+
124+
IEnumerable<Person> GetCollection()
125+
{
126+
var personOne = new Person
127+
{
128+
Identity = 1,
129+
Name = "Bob",
130+
};
131+
var personTwo = new Person
132+
{
133+
Identity = 2,
134+
Name = "Anna",
135+
};
136+
var personThree = new Person
137+
{
138+
Identity = 3,
139+
Name = "Jo",
140+
};
141+
return new[] { personOne, personTwo, personThree };
142+
}
143+
}
144+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// SpecificationExtensionsTests.cs
3+
//
4+
// Author:
5+
// Craig Fowler <craig@csf-dev.com>
6+
//
7+
// Copyright (c) 2018 Craig Fowler
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using NUnit.Framework;
27+
using System.Linq;
28+
using CSF.Specifications.Tests.Stubs;
29+
30+
namespace CSF.Specifications.Tests.Specifications
31+
{
32+
[TestFixture, Parallelizable]
33+
public class QueryableExtensionsTests
34+
{
35+
[Test, AutoMoqData]
36+
public void Where_filters_by_spec()
37+
{
38+
Assert.That(() => GetCollection().Where(GetSut("Anna")).FirstOrDefault()?.Identity, Is.EqualTo(2));
39+
}
40+
41+
[Test, AutoMoqData]
42+
public void First_uses_spec()
43+
{
44+
Assert.That(() => GetCollection().First(GetSut("Anna"))?.Identity, Is.EqualTo(2));
45+
}
46+
47+
[Test, AutoMoqData]
48+
public void FirstOrDefault_uses_spec()
49+
{
50+
Assert.That(() => GetCollection().FirstOrDefault(GetSut("Anna"))?.Identity, Is.EqualTo(2));
51+
}
52+
53+
[Test, AutoMoqData]
54+
public void Single_uses_spec()
55+
{
56+
Assert.That(() => GetCollection().Single(GetSut("Anna"))?.Identity, Is.EqualTo(2));
57+
}
58+
59+
[Test, AutoMoqData]
60+
public void SingleOrDefault_uses_spec()
61+
{
62+
Assert.That(() => GetCollection().SingleOrDefault(GetSut("Anna"))?.Identity, Is.EqualTo(2));
63+
}
64+
65+
[Test, AutoMoqData]
66+
public void Count_uses_spec()
67+
{
68+
Assert.That(() => GetCollection().Count(GetSut("Anna")), Is.EqualTo(1));
69+
}
70+
71+
[Test, AutoMoqData]
72+
public void Any_uses_spec()
73+
{
74+
Assert.That(() => GetCollection().Any(GetSut("Anna")), Is.True);
75+
}
76+
77+
ISpecificationExpression<Person> GetSut(string name) => new PersonNameSpecificationExpression(name);
78+
79+
IQueryable<Person> GetCollection()
80+
{
81+
var personOne = new Person
82+
{
83+
Identity = 1,
84+
Name = "Bob",
85+
};
86+
var personTwo = new Person
87+
{
88+
Identity = 2,
89+
Name = "Anna",
90+
};
91+
var personThree = new Person
92+
{
93+
Identity = 3,
94+
Name = "Jo",
95+
};
96+
return new[] { personOne, personTwo, personThree }.AsQueryable();
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)