|
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
|
@@ -818,6 +821,36 @@ public void CreateCommand_should_return_the_expected_result_when_using_causal_co
|
818 | 821 | result.Should().Be(expectedResult);
|
819 | 822 | }
|
820 | 823 |
|
| 824 | + [SkippableFact] |
| 825 | + public void CreateCursor_should_use_ns_field_instead_of_namespace_passed_in_constructor() |
| 826 | + { |
| 827 | + var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings); |
| 828 | + var firstBatchSlice = new ByteArrayBuffer(new byte[] { 5, 0, 0, 0, 0 }, isReadOnly: true); |
| 829 | + var cursorCollectionNamespace = CollectionNamespace.FromFullName("cursors.lkajlkasdf-3980238d908sdf"); |
| 830 | + var cursorDocument = new BsonDocument |
| 831 | + { |
| 832 | + { "id", 0 }, |
| 833 | + { "firstBatch", new RawBsonArray(firstBatchSlice) }, |
| 834 | + { "ns", cursorCollectionNamespace.FullName } |
| 835 | + }; |
| 836 | + var commandResult = new BsonDocument |
| 837 | + { |
| 838 | + { "ok", 1 }, |
| 839 | + { "cursor", cursorDocument } |
| 840 | + }; |
| 841 | + var mockServer = new Mock<IServer>(); |
| 842 | + var mockSession = new Mock<ICoreSessionHandle>(); |
| 843 | + var mockSessionFork = new Mock<ICoreSessionHandle>(); |
| 844 | + mockSession.Setup(x => x.Fork()).Returns(mockSessionFork.Object); |
| 845 | + var mockChannelSource = new Mock<IChannelSourceHandle>(); |
| 846 | + mockChannelSource.Setup(x => x.Server).Returns(mockServer.Object); |
| 847 | + mockChannelSource.Setup(x => x.Session).Returns(mockSession.Object); |
| 848 | + |
| 849 | + var cursor = subject.CreateCursor(mockChannelSource.Object, commandResult); |
| 850 | + |
| 851 | + cursor._collectionNamespace().Should().Be(cursorCollectionNamespace); |
| 852 | + } |
| 853 | + |
821 | 854 | [Theory]
|
822 | 855 | [ParameterAttributeData]
|
823 | 856 | public void CursorType_get_and_set_should_work(
|
@@ -1353,4 +1386,15 @@ private void EnsureTestData()
|
1353 | 1386 | });
|
1354 | 1387 | }
|
1355 | 1388 | }
|
| 1389 | + |
| 1390 | + public static class FindCommandOperationReflector |
| 1391 | + { |
| 1392 | + public static AsyncCursor<BsonDocument> CreateCursor( |
| 1393 | + this FindCommandOperation<BsonDocument> obj, |
| 1394 | + IChannelSourceHandle channelSource, |
| 1395 | + BsonDocument commandResult) |
| 1396 | + { |
| 1397 | + return (AsyncCursor<BsonDocument>)Reflector.Invoke(obj, nameof(CreateCursor), channelSource, commandResult); |
| 1398 | + } |
| 1399 | + } |
1356 | 1400 | }
|
0 commit comments