23
23
//
24
24
using NUnit . Framework ;
25
25
using System ;
26
+ using Rhino . Mocks ;
27
+ using Epic . Math ;
26
28
27
29
namespace Epic . Specifications
28
30
{
@@ -31,7 +33,7 @@ interface DummySpec<T> : ISpecification<T>, IEquatable<DummySpec<T>>
31
33
{
32
34
}
33
35
[ TestFixture ( ) ]
34
- public class SpecificationBaseQA
36
+ public class SpecificationBaseQA : RhinoMocksFixtureBase
35
37
{
36
38
[ Test ]
37
39
public void Initialize_aSpecificationTooAbstract_throwsTypeInitializationException ( )
@@ -88,6 +90,7 @@ public void Equals_toItself_isTrue()
88
90
Assert . IsTrue ( toTest . Equals ( toTest as Object ) ) ;
89
91
Assert . IsTrue ( toTest . Equals ( toTest as Fakes . ISampleSpecification < string > ) ) ;
90
92
Assert . IsTrue ( toTest . Equals ( toTest as ISpecification < string > ) ) ;
93
+ Assert . AreEqual ( typeof ( Fakes . ISampleSpecification < string > ) . GetHashCode ( ) , toTest . GetHashCode ( ) ) ;
91
94
}
92
95
93
96
[ Test ]
@@ -120,6 +123,69 @@ public void Equals_toAnotherSpecificationOfTheSameType_callEqualsA()
120
123
Assert . AreEqual ( 3 , toTest . EqualsACalled ) ;
121
124
Assert . AreEqual ( 3 , other . EqualsACalled ) ;
122
125
}
126
+
127
+ [ Test ]
128
+ public void Accept_withValidArguments_delegateVisitToTheRightVisitor ( )
129
+ {
130
+ // arrange:
131
+ Fakes . ISampleSpecification < string > toTest = new Fakes . SampleSpecification < string > ( ) ;
132
+ object expectedResult = new object ( ) ;
133
+ IVisitContext context = GenerateStrictMock < IVisitContext > ( ) ;
134
+ IVisitor < object , Fakes . ISampleSpecification < string > > specificationVisitor = GenerateStrictMock < IVisitor < object , Fakes . ISampleSpecification < string > > > ( ) ;
135
+ specificationVisitor . Expect ( v => v . Visit ( toTest , context ) ) . Return ( expectedResult ) . Repeat . Once ( ) ;
136
+ IVisitor < object > visitor = GenerateStrictMock < IVisitor < object > > ( ) ;
137
+ visitor . Expect ( v => v . GetVisitor ( toTest ) ) . Return ( specificationVisitor ) . Repeat . Once ( ) ;
138
+
139
+ // act:
140
+ object result = toTest . Accept ( visitor , context ) ;
141
+
142
+ // assert:
143
+ Assert . AreSame ( expectedResult , result ) ;
144
+ }
145
+
146
+ [ Test ]
147
+ public void IsSatisfiedBy_null_isFalse ( )
148
+ {
149
+ // arrange:
150
+ Fakes . SampleSpecification < string > toTest = new Fakes . SampleSpecification < string > ( ) ;
151
+
152
+ // act:
153
+ bool result = toTest . IsSatisfiedBy ( null ) ;
154
+
155
+ // assert:
156
+ Assert . IsFalse ( result ) ;
157
+ Assert . AreEqual ( 0 , toTest . IsSatisfiedByACalled ) ;
158
+ }
159
+
160
+ [ Test ]
161
+ public void IsSatifiedBy_aCandidate_callIsSatisfiedByA ( )
162
+ {
163
+ // arrange:
164
+ string candidate = "test" ;
165
+ Fakes . SampleSpecification < string > toTest1 = new Fakes . SampleSpecification < string > ( s => true ) ;
166
+ Fakes . SampleSpecification < string > toTest2 = new Fakes . SampleSpecification < string > ( s => false ) ;
167
+
168
+ // assert:
169
+ Assert . IsTrue ( toTest1 . IsSatisfiedBy ( candidate ) ) ;
170
+ Assert . AreEqual ( 1 , toTest1 . IsSatisfiedByACalled ) ;
171
+ Assert . IsFalse ( toTest2 . IsSatisfiedBy ( candidate ) ) ;
172
+ Assert . AreEqual ( 1 , toTest2 . IsSatisfiedByACalled ) ;
173
+ }
174
+
175
+ [ Test ]
176
+ public void ApplyTo_aCandidate_callIsSatisfiedByA ( )
177
+ {
178
+ // arrange:
179
+ string candidate = "test" ;
180
+ Fakes . SampleSpecification < string > toTest1 = new Fakes . SampleSpecification < string > ( s => true ) ;
181
+ Fakes . SampleSpecification < string > toTest2 = new Fakes . SampleSpecification < string > ( s => false ) ;
182
+
183
+ // assert:
184
+ Assert . IsTrue ( ( toTest1 as IMapping < string , bool > ) . ApplyTo ( candidate ) ) ;
185
+ Assert . AreEqual ( 1 , toTest1 . IsSatisfiedByACalled ) ;
186
+ Assert . IsFalse ( ( toTest2 as IMapping < string , bool > ) . ApplyTo ( candidate ) ) ;
187
+ Assert . AreEqual ( 1 , toTest2 . IsSatisfiedByACalled ) ;
188
+ }
123
189
}
124
190
}
125
191
0 commit comments