PageRenderTime 54ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Bson.Tests/IO/ByteBufferFactoryTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 91 lines | 62 code | 15 blank | 14 comment | 0 complexity | 3b71a282b72e0a6cdc617bc6e33625bb MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2010-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 System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using FluentAssertions;
  21. using MongoDB.Bson.IO;
  22. using MongoDB.Bson.TestHelpers.XunitExtensions;
  23. using Moq;
  24. using Xunit;
  25. namespace MongoDB.Bson.Tests.IO
  26. {
  27. public class ByteBufferFactoryTests
  28. {
  29. [Theory]
  30. [ParameterAttributeData]
  31. public void Create_should_return_expected_result(
  32. [Values(1, 63, 64, 65, 128)]
  33. int minimumCapacity)
  34. {
  35. var chunkSource = new BsonChunkPool(1, 64);
  36. var result = ByteBufferFactory.Create(chunkSource, minimumCapacity);
  37. result.Capacity.Should().BeGreaterOrEqualTo(minimumCapacity);
  38. }
  39. [Theory]
  40. [ParameterAttributeData]
  41. public void Create_should_return_SingleChunkBuffer_when_a_single_chunk_is_sufficient(
  42. [Values(1, 63, 64)]
  43. int minimumCapacity)
  44. {
  45. var chunkSource = new BsonChunkPool(1, 64);
  46. var result = ByteBufferFactory.Create(chunkSource, minimumCapacity);
  47. result.Should().BeOfType<SingleChunkBuffer>();
  48. }
  49. [Theory]
  50. [ParameterAttributeData]
  51. public void Create_should_return_MultiChunkBuffer_when_multiple_chunks_are_required(
  52. [Values(65, 128)]
  53. int minimumCapacity)
  54. {
  55. var chunkSource = new BsonChunkPool(1, 64);
  56. var result = ByteBufferFactory.Create(chunkSource, minimumCapacity);
  57. result.Should().BeOfType<MultiChunkBuffer>();
  58. }
  59. [Fact]
  60. public void Create_should_throw_when_chunkSource_is_null()
  61. {
  62. Action action = () => ByteBufferFactory.Create(null, 0);
  63. action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("chunkSource");
  64. }
  65. [Theory]
  66. [ParameterAttributeData]
  67. public void Create_should_throw_when_minimumCapacity_is_invalid(
  68. [Values(-1, 0)]
  69. int minimumCapacity)
  70. {
  71. var mockChunkSource = new Mock<IBsonChunkSource>();
  72. Action action = () => ByteBufferFactory.Create(mockChunkSource.Object, minimumCapacity);
  73. action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("minimumCapacity");
  74. }
  75. }
  76. }