PageRenderTime 35ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/WireProtocol/Messages/GetMoreMessageTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 70 lines | 48 code | 8 blank | 14 comment | 0 complexity | 799f4d0090058d48fc9383045392fa80 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-present MongoDB 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. using System;
  16. using FluentAssertions;
  17. using MongoDB.Bson;
  18. using MongoDB.Driver.Core.WireProtocol.Messages;
  19. using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
  20. using Moq;
  21. using Xunit;
  22. namespace MongoDB.Driver.Core.WireProtocol.Messages
  23. {
  24. public class GetMoreMessageTests
  25. {
  26. private readonly int _batchSize = 1;
  27. private readonly CollectionNamespace _collectionNamespace = new CollectionNamespace("database", "collection");
  28. private readonly long _cursorId = 2;
  29. private readonly int _requestId = 3;
  30. [Fact]
  31. public void Constructor_should_initialize_instance()
  32. {
  33. var subject = new GetMoreMessage(_requestId, _collectionNamespace, _cursorId, _batchSize);
  34. subject.BatchSize.Should().Be(_batchSize);
  35. subject.CursorId.Should().Be(_cursorId);
  36. subject.CollectionNamespace.Should().Be(_collectionNamespace);
  37. subject.RequestId.Should().Be(_requestId);
  38. }
  39. [Fact]
  40. public void Constructor_with_negative_batchSize_should_throw()
  41. {
  42. Action action = () => new GetMoreMessage(_requestId, _collectionNamespace, _cursorId, -1);
  43. action.ShouldThrow<ArgumentOutOfRangeException>();
  44. }
  45. [Fact]
  46. public void Constructor_with_null_collectionNamespace_should_throw()
  47. {
  48. Action action = () => new GetMoreMessage(_requestId, null, _cursorId, _batchSize);
  49. action.ShouldThrow<ArgumentNullException>();
  50. }
  51. [Fact]
  52. public void GetEncoder_should_return_encoder()
  53. {
  54. var subject = new GetMoreMessage(_requestId, _collectionNamespace, _cursorId, _batchSize);
  55. var mockEncoderFactory = new Mock<IMessageEncoderFactory>();
  56. var encoder = new Mock<IMessageEncoder>().Object;
  57. mockEncoderFactory.Setup(f => f.GetGetMoreMessageEncoder()).Returns(encoder);
  58. var result = subject.GetEncoder(mockEncoderFactory.Object);
  59. result.Should().BeSameAs(encoder);
  60. }
  61. }
  62. }