public void CreateFindCommandOperation_should_return_expected_result()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                AllowPartialResults = true,
                BatchSize           = 1,
                Collation           = new Collation("en_US"),
                Comment             = "comment",
                CursorType          = CursorType.Tailable,
                Filter          = new BsonDocument("filter", 1),
                FirstBatchSize  = 2,
                Hint            = "x_1",
                Limit           = 3,
                Max             = new BsonDocument("max", 1),
                MaxAwaitTime    = TimeSpan.FromSeconds(2),
                MaxScan         = 4,
                MaxTime         = TimeSpan.FromSeconds(1),
                Min             = new BsonDocument("min", 1),
                NoCursorTimeout = true,
                OplogReplay     = true,
                Projection      = new BsonDocument("projection", 1),
                ReadConcern     = ReadConcern.Local,
                ReturnKey       = true,
                ShowRecordId    = true,
                SingleBatch     = true,
                Skip            = 6,
                Snapshot        = true,
                Sort            = new BsonDocument("sort", 1)
            };

            var result = subject.CreateFindCommandOperation();

            result.AllowPartialResults.Should().Be(subject.AllowPartialResults);
            result.BatchSize.Should().Be(subject.BatchSize);
            result.Collation.Should().BeSameAs(subject.Collation);
            result.CollectionNamespace.Should().BeSameAs(subject.CollectionNamespace);
            result.Comment.Should().BeSameAs(subject.Comment);
            result.CursorType.Should().Be(subject.CursorType);
            result.Filter.Should().BeSameAs(subject.Filter);
            result.FirstBatchSize.Should().Be(subject.FirstBatchSize);
            result.Hint.Should().BeSameAs(subject.Hint);
            result.Limit.Should().Be(subject.Limit);
            result.Max.Should().BeSameAs(subject.Max);
            result.MaxAwaitTime.Should().Be(subject.MaxAwaitTime);
            result.MaxScan.Should().Be(subject.MaxScan);
            result.MaxTime.Should().Be(subject.MaxTime);
            result.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
            result.Min.Should().BeSameAs(subject.Min);
            result.NoCursorTimeout.Should().Be(subject.NoCursorTimeout);
            result.OplogReplay.Should().Be(subject.OplogReplay);
            result.Projection.Should().BeSameAs(subject.Projection);
            result.ReadConcern.Should().BeSameAs(subject.ReadConcern);
            result.ResultSerializer.Should().BeSameAs(subject.ResultSerializer);
            result.ReturnKey.Should().Be(subject.ReturnKey);
            result.ShowRecordId.Should().Be(subject.ShowRecordId);
            result.SingleBatch.Should().Be(subject.SingleBatch);
            result.Skip.Should().Be(subject.Skip);
            result.Snapshot.Should().Be(subject.Snapshot);
            result.Sort.Should().BeSameAs(subject.Sort);
        }
        public void CreateFindCommandOperation_should_return_expected_result_when_modifiers_are_provided()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                ReadConcern = ReadConcern.Majority
            };

            subject.Modifiers = new BsonDocument
            {
                { "$hint", "x_1" },
                { "$max", new BsonDocument("max", 1) },
                { "$maxScan", 1 },
                { "$maxTimeMS", 2000 },
                { "$min", new BsonDocument("min", 1) },
                { "$orderby", new BsonDocument("sort", 1) },
                { "$showDiskLoc", true },
                { "$snapshot", true }
            };

            var result = subject.CreateFindCommandOperation();

            result.Hint.Should().Be(subject.Modifiers["$hint"]);
            result.Max.Should().Be(subject.Modifiers["$max"].AsBsonDocument);
            result.MaxScan.Should().Be(subject.Modifiers["$maxScan"].AsInt32);
            result.MaxTime.Should().Be(TimeSpan.FromMilliseconds(subject.Modifiers["$maxTimeMS"].AsInt32));
            result.Min.Should().Be(subject.Modifiers["$min"].AsBsonDocument);
            result.ReadConcern.Should().Be(subject.ReadConcern);
            result.ShowRecordId.Should().Be(subject.Modifiers["$showDiskLoc"].AsBoolean);
            result.Snapshot.Should().Be(subject.Modifiers["$snapshot"].AsBoolean);
            result.Sort.Should().Be(subject.Modifiers["$orderby"].AsBsonDocument);
        }
示例#3
0
        public void CreateFindCommandOperation_should_prefer_top_level_fields_over_modifiers()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Hint = "x_2",
                Max  = new BsonDocument("max", 5),
#pragma warning disable 618
                MaxScan = 7,
#pragma warning restore 618
                Min          = new BsonDocument("min", 3),
                ReturnKey    = true,
                ShowRecordId = true,
#pragma warning disable 618
                Snapshot = true,
#pragma warning restore 618
#pragma warning disable 618
                Modifiers = new BsonDocument
                {
                    { "$hint", "x_1" },
                    { "$max", new BsonDocument("max", 1) },
                    { "$maxScan", 1 },
                    { "$min", new BsonDocument("min", 1) },
                    { "$returnKey", false },
                    { "$showDiskLoc", false },
                    { "$snapshot", false }
                }
#pragma warning restore 618
            };

            var result = subject.CreateFindCommandOperation();

            result.Hint.Should().Be(subject.Hint);
            result.Max.Should().Be(subject.Max);
#pragma warning disable 618
            result.MaxScan.Should().Be(subject.MaxScan);
#pragma warning restore 618
            result.Min.Should().Be(subject.Min);
            result.ReturnKey.Should().Be(subject.ReturnKey);
            result.ShowRecordId.Should().Be(subject.ShowRecordId);
#pragma warning disable 618
            result.Snapshot.Should().Be(subject.Snapshot);
#pragma warning restore 618
        }