Esempio n. 1
0
        public void CreateFindOpcodeOperation_should_return_expected_result()
        {
#pragma warning disable 618
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                AllowPartialResults = true,
                BatchSize           = 1,
                Comment             = "comment",
                CursorType          = CursorType.Tailable,
                Filter          = new BsonDocument("filter", 1),
                FirstBatchSize  = 2,
                Hint            = "x_1",
                Limit           = 3,
                Max             = new BsonDocument("max", 1),
                MaxScan         = 4,
                MaxTime         = TimeSpan.FromSeconds(1),
                Min             = new BsonDocument("min", 1),
                Modifiers       = new BsonDocument("modifiers", 1),
                NoCursorTimeout = true,
                OplogReplay     = true,
                Projection      = new BsonDocument("projection", 1),
                ReturnKey       = true,
                ShowRecordId    = true,
                SingleBatch     = false,
                Skip            = 6,
                Snapshot        = true,
                Sort            = new BsonDocument("sort", 1)
            };
#pragma warning restore

            var result = subject.CreateFindOpcodeOperation();

            result.AllowPartialResults.Should().Be(subject.AllowPartialResults);
            result.BatchSize.Should().Be(subject.BatchSize);
            result.CollectionNamespace.Should().Be(subject.CollectionNamespace);
            result.Comment.Should().Be(subject.Comment);
            result.CursorType.Should().Be(subject.CursorType);
            result.Filter.Should().Be(subject.Filter);
            result.FirstBatchSize.Should().Be(subject.FirstBatchSize);
            result.Hint.Should().Be(subject.Hint);
            result.Limit.Should().Be(subject.Limit);
            result.Max.Should().Be(subject.Max);
#pragma warning disable 618
            result.MaxScan.Should().Be(subject.MaxScan);
#pragma warning restore
            result.MaxTime.Should().Be(subject.MaxTime);
            result.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
            result.Min.Should().Be(subject.Min);
            result.Modifiers.Should().Be(subject.Modifiers);
            result.NoCursorTimeout.Should().Be(subject.NoCursorTimeout);
            result.OplogReplay.Should().Be(subject.OplogReplay);
            result.Projection.Should().Be(subject.Projection);
            result.ResultSerializer.Should().Be(subject.ResultSerializer);
            result.ShowRecordId.Should().Be(subject.ShowRecordId);
            result.Skip.Should().Be(subject.Skip);
#pragma warning disable 618
            result.Snapshot.Should().Be(subject.Snapshot);
#pragma warning restore
            result.Sort.Should().Be(subject.Sort);
        }
        public void CreateFindOpcodeOperation_should_return_expected_result_when_singleBatch_is_true()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.Limit       = 1;
            subject.SingleBatch = true;

            var result = subject.CreateFindOpcodeOperation();

            result.Limit.Should().Be(-subject.Limit);
        }
        public void CreateFindOpcodeOperation_should_throw_when_ReadConcern_is_not_server_default()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                ReadConcern = new ReadConcern(ReadConcernLevel.Local)
            };

            var exception = Record.Exception(() => { subject.CreateFindOpcodeOperation(); });

            exception.Should().BeOfType <MongoClientException>();
        }
        public void CreateFindOpcodeOperation_should_throw_when_Collation_is_set()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Collation = new Collation("en_US")
            };

            var exception = Record.Exception(() => { subject.CreateFindOpcodeOperation(); });

            exception.Should().BeOfType <NotSupportedException>();
        }
        public void CreateFindOpcodeOperation_should_return_expected_result()
        {
            var subject = new FindOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.AllowPartialResults = true;
            subject.BatchSize           = 1;
            subject.Comment             = "comment";
            subject.CursorType          = CursorType.Tailable;
            subject.Filter          = new BsonDocument("filter", 1);
            subject.FirstBatchSize  = 2;
            subject.Hint            = "x_1";
            subject.Limit           = 3;
            subject.Max             = new BsonDocument("max", 1);
            subject.MaxScan         = 4;
            subject.MaxTime         = TimeSpan.FromSeconds(1);
            subject.Min             = new BsonDocument("min", 1);
            subject.NoCursorTimeout = true;
            subject.OplogReplay     = true;
            subject.Projection      = new BsonDocument("projection", 1);
            subject.ReadConcern     = ReadConcern.Local;
            subject.ReturnKey       = true;
            subject.ShowRecordId    = true;
            subject.SingleBatch     = false;
            subject.Skip            = 6;
            subject.Snapshot        = true;
            subject.Sort            = new BsonDocument("sort", 1);

            var result = subject.CreateFindOpcodeOperation();

            result.AllowPartialResults.Should().Be(subject.AllowPartialResults);
            result.BatchSize.Should().Be(subject.BatchSize);
            result.CollectionNamespace.Should().Be(subject.CollectionNamespace);
            result.Comment.Should().Be(subject.Comment);
            result.CursorType.Should().Be(subject.CursorType);
            result.Filter.Should().Be(subject.Filter);
            result.FirstBatchSize.Should().Be(subject.FirstBatchSize);
            result.Hint.Should().Be(subject.Hint);
            result.Limit.Should().Be(subject.Limit);
            result.Max.Should().Be(subject.Max);
            result.MaxScan.Should().Be(subject.MaxScan);
            result.MaxTime.Should().Be(subject.MaxTime);
            result.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
            result.Min.Should().Be(subject.Min);
            result.Modifiers.Should().Be(subject.Modifiers);
            result.NoCursorTimeout.Should().Be(subject.NoCursorTimeout);
            result.OplogReplay.Should().Be(subject.OplogReplay);
            result.Projection.Should().Be(subject.Projection);
            result.ResultSerializer.Should().Be(subject.ResultSerializer);
            result.ShowRecordId.Should().Be(subject.ShowRecordId);
            result.Skip.Should().Be(subject.Skip);
            result.Snapshot.Should().Be(subject.Snapshot);
            result.Sort.Should().Be(subject.Sort);
        }