|
16 | 16 | using System;
|
17 | 17 | using FluentAssertions;
|
18 | 18 | using MongoDB.Bson;
|
| 19 | +using MongoDB.Bson.IO; |
19 | 20 | using MongoDB.Bson.Serialization.Serializers;
|
| 21 | +using MongoDB.Bson.TestHelpers; |
20 | 22 | using MongoDB.Bson.TestHelpers.XunitExtensions;
|
21 | 23 | using MongoDB.Driver.Core.Bindings;
|
22 | 24 | using MongoDB.Driver.Core.Clusters;
|
23 | 25 | using MongoDB.Driver.Core.Misc;
|
24 | 26 | using MongoDB.Driver.Core.Servers;
|
25 | 27 | using MongoDB.Driver.Core.TestHelpers;
|
26 | 28 | using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
|
| 29 | +using Moq; |
27 | 30 | using Xunit;
|
28 | 31 |
|
29 | 32 | namespace MongoDB.Driver.Core.Operations
|
@@ -773,6 +776,36 @@ public void CreateCommand_should_return_the_expected_result_when_using_causal_co
|
773 | 776 | result.Should().Be(expectedResult);
|
774 | 777 | }
|
775 | 778 |
|
| 779 | + [SkippableFact] |
| 780 | + public void CreateCursor_should_use_ns_field_instead_of_namespace_passed_in_constructor() |
| 781 | + { |
| 782 | + var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings); |
| 783 | + var firstBatchSlice = new ByteArrayBuffer(new byte[] { 5, 0, 0, 0, 0 }, isReadOnly: true); |
| 784 | + var cursorCollectionNamespace = CollectionNamespace.FromFullName("cursors.lkajlkasdf-3980238d908sdf"); |
| 785 | + var cursorDocument = new BsonDocument |
| 786 | + { |
| 787 | + { "id", 0 }, |
| 788 | + { "firstBatch", new RawBsonArray(firstBatchSlice) }, |
| 789 | + { "ns", cursorCollectionNamespace.FullName } |
| 790 | + }; |
| 791 | + var commandResult = new BsonDocument |
| 792 | + { |
| 793 | + { "ok", 1 }, |
| 794 | + { "cursor", cursorDocument } |
| 795 | + }; |
| 796 | + var mockServer = new Mock<IServer>(); |
| 797 | + var mockSession = new Mock<ICoreSessionHandle>(); |
| 798 | + var mockSessionFork = new Mock<ICoreSessionHandle>(); |
| 799 | + mockSession.Setup(x => x.Fork()).Returns(mockSessionFork.Object); |
| 800 | + var mockChannelSource = new Mock<IChannelSourceHandle>(); |
| 801 | + mockChannelSource.Setup(x => x.Server).Returns(mockServer.Object); |
| 802 | + mockChannelSource.Setup(x => x.Session).Returns(mockSession.Object); |
| 803 | + |
| 804 | + var cursor = subject.CreateCursor(mockChannelSource.Object, commandResult); |
| 805 | + |
| 806 | + cursor._collectionNamespace().Should().Be(cursorCollectionNamespace); |
| 807 | + } |
| 808 | + |
776 | 809 | [Theory]
|
777 | 810 | [ParameterAttributeData]
|
778 | 811 | public void CursorType_get_and_set_should_work(
|
@@ -1306,4 +1339,15 @@ private void EnsureTestData()
|
1306 | 1339 | });
|
1307 | 1340 | }
|
1308 | 1341 | }
|
| 1342 | + |
| 1343 | + public static class FindCommandOperationReflector |
| 1344 | + { |
| 1345 | + public static AsyncCursor<BsonDocument> CreateCursor( |
| 1346 | + this FindCommandOperation<BsonDocument> obj, |
| 1347 | + IChannelSourceHandle channelSource, |
| 1348 | + BsonDocument commandResult) |
| 1349 | + { |
| 1350 | + return (AsyncCursor<BsonDocument>)Reflector.Invoke(obj, nameof(CreateCursor), channelSource, commandResult); |
| 1351 | + } |
| 1352 | + } |
1309 | 1353 | }
|
0 commit comments