|
| 1 | +/* Copyright 2010-2013 10gen Inc. |
| 2 | +* |
| 3 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +* you may not use this file except in compliance with the License. |
| 5 | +* You may obtain a copy of the License at |
| 6 | +* |
| 7 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +* |
| 9 | +* Unless required by applicable law or agreed to in writing, software |
| 10 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +* See the License for the specific language governing permissions and |
| 13 | +* limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +using System; |
| 17 | +using MongoDB.Bson; |
| 18 | +using MongoDB.Driver; |
| 19 | +using NUnit.Framework; |
| 20 | + |
| 21 | +namespace MongoDB.DriverUnitTests.CommandResults |
| 22 | +{ |
| 23 | + [TestFixture] |
| 24 | + public class IsMasterResultTests |
| 25 | + { |
| 26 | + [Test] |
| 27 | + public void TestMaxMessageLengthWhenServerSupplied() |
| 28 | + { |
| 29 | + var command = new CommandDocument("ismaster", 1); |
| 30 | + var document = new BsonDocument |
| 31 | + { |
| 32 | + { "ok", 1 }, |
| 33 | + { "maxMessageSizeBytes", 1000 }, |
| 34 | + { "maxBsonObjectSize", 1000 } |
| 35 | + }; |
| 36 | + var result = new IsMasterResult(); |
| 37 | + result.Initialize(command, document); |
| 38 | + |
| 39 | + Assert.AreEqual(1000, result.MaxMessageLength); |
| 40 | + } |
| 41 | + |
| 42 | + [Test] |
| 43 | + public void TestMaxMessageLengthWhenNotServerSuppliedUsesMongoDefaultsWhenLargerThanMaxBsonObjectSize() |
| 44 | + { |
| 45 | + var command = new CommandDocument("ismaster", 1); |
| 46 | + var document = new BsonDocument |
| 47 | + { |
| 48 | + { "ok", 1 }, |
| 49 | + { "maxBsonObjectSize", MongoDefaults.MaxMessageLength - 2048 } |
| 50 | + }; |
| 51 | + var result = new IsMasterResult(); |
| 52 | + result.Initialize(command, document); |
| 53 | + |
| 54 | + Assert.AreEqual(MongoDefaults.MaxMessageLength, result.MaxMessageLength); |
| 55 | + } |
| 56 | + |
| 57 | + [Test] |
| 58 | + public void TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults() |
| 59 | + { |
| 60 | + var command = new CommandDocument("ismaster", 1); |
| 61 | + var document = new BsonDocument |
| 62 | + { |
| 63 | + { "ok", 1 }, |
| 64 | + { "maxBsonObjectSize", MongoDefaults.MaxMessageLength } |
| 65 | + }; |
| 66 | + var result = new IsMasterResult(); |
| 67 | + result.Initialize(command, document); |
| 68 | + |
| 69 | + Assert.AreEqual(MongoDefaults.MaxMessageLength + 1024, result.MaxMessageLength); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments