@@ -25,24 +25,43 @@ namespace MongoDB.Driver.Tests
2525 public class PipelineStagePipelineDefinitionTests
2626 {
2727 [ 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 ( )
2929 {
30- var stages = new IPipelineStageDefinition [ ]
30+ var stages = new IPipelineStageDefinition [ ]
3131 {
3232 new BsonDocumentPipelineStageDefinition < Person , BsonDocument > ( new BsonDocument ( ) ) ,
3333 new BsonDocumentPipelineStageDefinition < BsonDocument , Pet > ( new BsonDocument ( ) ) ,
3434 new BsonDocumentPipelineStageDefinition < BsonDocument , Person > ( new BsonDocument ( ) )
3535 } ;
3636
37- Action act = ( ) => new PipelineStagePipelineDefinition < Person , Person > ( stages ) ;
37+ var exception = Record . Exception ( ( ) => new PipelineStagePipelineDefinition < Person , Person > ( stages ) ) ;
3838
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 ) } .") ;
4042 }
4143
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+
4261 [ Fact ]
4362 public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages ( )
4463 {
45- var stages = new IPipelineStageDefinition [ ]
64+ var stages = new IPipelineStageDefinition [ ]
4665 {
4766 new BsonDocumentPipelineStageDefinition < Person , BsonDocument > ( new BsonDocument ( ) ) ,
4867 new BsonDocumentPipelineStageDefinition < BsonDocument , Pet > ( new BsonDocument ( ) ) ,
@@ -71,7 +90,7 @@ private class Person
7190 {
7291 [ BsonElement ( "fn" ) ]
7392 public string FirstName { get ; set ; }
74-
93+
7594 [ BsonElement ( "pets" ) ]
7695 public Pet [ ] Pets { get ; set ; }
7796 }
@@ -80,6 +99,6 @@ private class Pet
8099 {
81100 [ BsonElement ( "name" ) ]
82101 public string Name { get ; set ; }
83- }
102+ }
84103 }
85104}
0 commit comments