|
18 | 18 | using System.Linq;
|
19 | 19 | using FluentAssertions;
|
20 | 20 | using MongoDB.Bson;
|
| 21 | +using MongoDB.Bson.Serialization; |
21 | 22 | using MongoDB.Bson.TestHelpers.XunitExtensions;
|
22 | 23 | using MongoDB.Driver.Core.Clusters;
|
23 | 24 | using MongoDB.Driver.Core.Misc;
|
24 | 25 | using MongoDB.Driver.Core.TestHelpers;
|
25 | 26 | using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
|
| 27 | +using MongoDB.Driver.Core.WireProtocol.Messages.Encoders; |
26 | 28 | using Xunit;
|
27 | 29 |
|
28 | 30 | namespace MongoDB.Driver.Core.Operations
|
@@ -70,6 +72,22 @@ public void Constructor_with_collectionNamespace_should_create_a_valid_instance(
|
70 | 72 | subject.WriteConcern.Should().BeNull();
|
71 | 73 | }
|
72 | 74 |
|
| 75 | + [Theory] |
| 76 | + [InlineData("{ $out : 'collection' }", "{ $out : 'collection' }")] |
| 77 | + [InlineData("{ $out : { db : 'database', coll : 'collection' } }", "{ $out : 'collection' }")] |
| 78 | + [InlineData("{ $out : { db : 'differentdatabase', coll : 'collection' } }", "{ $out : { db : 'differentdatabase', coll : 'collection' } }")] |
| 79 | + [InlineData("{ $out : { s3 : { } } }", "{ $out : { s3 : { } } }")] |
| 80 | + public void Constructor_should_simplify_out_stage_when_possible(string outStageJson, string expectedOutStageJson) |
| 81 | + { |
| 82 | + var databaseNamespace = new DatabaseNamespace("database"); |
| 83 | + var pipeline = new[] { BsonDocument.Parse(outStageJson) }; |
| 84 | + var messageEncoderSettings = new MessageEncoderSettings(); |
| 85 | + |
| 86 | + var subject = new AggregateToCollectionOperation(databaseNamespace, pipeline, messageEncoderSettings); |
| 87 | + |
| 88 | + subject.Pipeline.Last().Should().Be(BsonDocument.Parse(expectedOutStageJson)); |
| 89 | + } |
| 90 | + |
73 | 91 | [Fact]
|
74 | 92 | public void Constructor_should_throw_when_databaseNamespace_is_null()
|
75 | 93 | {
|
|
0 commit comments