@@ -25,24 +25,43 @@ namespace MongoDB.Driver.Tests
25
25
public class PipelineStagePipelineDefinitionTests
26
26
{
27
27
[ Fact ]
28
- public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages_and_throw_when_invalid ( )
28
+ public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages_and_throw_when_intermediate_stage_is_invalid ( )
29
29
{
30
- var stages = new IPipelineStageDefinition [ ]
30
+ var stages = new IPipelineStageDefinition [ ]
31
31
{
32
32
new BsonDocumentPipelineStageDefinition < Person , BsonDocument > ( new BsonDocument ( ) ) ,
33
33
new BsonDocumentPipelineStageDefinition < BsonDocument , Pet > ( new BsonDocument ( ) ) ,
34
34
new BsonDocumentPipelineStageDefinition < BsonDocument , Person > ( new BsonDocument ( ) )
35
35
} ;
36
36
37
- Action act = ( ) => new PipelineStagePipelineDefinition < Person , Person > ( stages ) ;
37
+ var exception = Record . Exception ( ( ) => new PipelineStagePipelineDefinition < Person , Person > ( stages ) ) ;
38
38
39
- act . ShouldThrow < ArgumentException > ( ) ;
39
+ var e = exception . Should ( ) . BeOfType < ArgumentException > ( ) . Subject ;
40
+ e . ParamName . Should ( ) . Be ( "stages" ) ;
41
+ e . Message . Should ( ) . Contain ( $ "The input type to stage[2] was expected to be { typeof ( Pet ) } , but was { typeof ( BsonDocument ) } .") ;
40
42
}
41
43
44
+ [ Fact ]
45
+ public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages_and_throw_when_final_stage_is_invalid ( )
46
+ {
47
+ var stages = new IPipelineStageDefinition [ ]
48
+ {
49
+ new BsonDocumentPipelineStageDefinition < Person , BsonDocument > ( new BsonDocument ( ) ) ,
50
+ new BsonDocumentPipelineStageDefinition < BsonDocument , Pet > ( new BsonDocument ( ) ) ,
51
+ new BsonDocumentPipelineStageDefinition < Pet , BsonDocument > ( new BsonDocument ( ) )
52
+ } ;
53
+
54
+ var exception = Record . Exception ( ( ) => new PipelineStagePipelineDefinition < Person , Person > ( stages ) ) ;
55
+
56
+ var e = exception . Should ( ) . BeOfType < ArgumentException > ( ) . Subject ;
57
+ e . ParamName . Should ( ) . Be ( "stages" ) ;
58
+ e . Message . Should ( ) . Contain ( $ "The output type to the last stage was expected to be { typeof ( Person ) } , but was { typeof ( BsonDocument ) } .") ;
59
+ }
60
+
42
61
[ Fact ]
43
62
public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages ( )
44
63
{
45
- var stages = new IPipelineStageDefinition [ ]
64
+ var stages = new IPipelineStageDefinition [ ]
46
65
{
47
66
new BsonDocumentPipelineStageDefinition < Person , BsonDocument > ( new BsonDocument ( ) ) ,
48
67
new BsonDocumentPipelineStageDefinition < BsonDocument , Pet > ( new BsonDocument ( ) ) ,
@@ -71,7 +90,7 @@ private class Person
71
90
{
72
91
[ BsonElement ( "fn" ) ]
73
92
public string FirstName { get ; set ; }
74
-
93
+
75
94
[ BsonElement ( "pets" ) ]
76
95
public Pet [ ] Pets { get ; set ; }
77
96
}
@@ -80,6 +99,6 @@ private class Pet
80
99
{
81
100
[ BsonElement ( "name" ) ]
82
101
public string Name { get ; set ; }
83
- }
102
+ }
84
103
}
85
104
}
0 commit comments