mongo-csharp-driver /tests/MongoDB.Driver.Tests/PipelineDefinitionTests.cs

Language C# Lines 86
MD5 Hash f330f60d0f1da4e16e713a2a3d19f58f Estimated Cost $1,359 (why?)
Repository git://github.com/mongodb/mongo-csharp-driver.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright 2010-2015 MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using FluentAssertions;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Attributes;
using Xunit;

namespace MongoDB.Driver.Tests
{
    public class PipelineStagePipelineDefinitionTests
    {
        [Fact]
        public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages_and_throw_when_invalid()
        {
            var stages = new IPipelineStageDefinition[] 
            {
                new BsonDocumentPipelineStageDefinition<Person, BsonDocument>(new BsonDocument()),
                new BsonDocumentPipelineStageDefinition<BsonDocument, Pet>(new BsonDocument()),
                new BsonDocumentPipelineStageDefinition<BsonDocument, Person>(new BsonDocument())
            };

            Action act = () => new PipelineStagePipelineDefinition<Person, Person>(stages);

            act.ShouldThrow<ArgumentException>();
        }

        [Fact]
        public void Constructor_should_verify_the_inputs_and_outputs_of_the_stages()
        {
            var stages = new IPipelineStageDefinition[] 
            {
                new BsonDocumentPipelineStageDefinition<Person, BsonDocument>(new BsonDocument()),
                new BsonDocumentPipelineStageDefinition<BsonDocument, Pet>(new BsonDocument()),
                new BsonDocumentPipelineStageDefinition<Pet, Person>(new BsonDocument())
            };

            Action act = () => new PipelineStagePipelineDefinition<Person, Person>(stages);

            act.ShouldNotThrow<ArgumentException>();
        }

        private void Assert<TDocument>(ProjectionDefinition<TDocument> projection, string expectedJson)
        {
            var documentSerializer = BsonSerializer.SerializerRegistry.GetSerializer<TDocument>();
            var renderedProjection = projection.Render(documentSerializer, BsonSerializer.SerializerRegistry);

            renderedProjection.Should().Be(expectedJson);
        }

        private ProjectionDefinitionBuilder<TDocument> CreateSubject<TDocument>()
        {
            return new ProjectionDefinitionBuilder<TDocument>();
        }

        private class Person
        {
            [BsonElement("fn")]
            public string FirstName { get; set; }
        
            [BsonElement("pets")]
            public Pet[] Pets { get; set; }
        }

        private class Pet
        {
            [BsonElement("name")]
            public string Name { get; set; }
        }    
    }
}
Back to Top