PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/MongoDB.Driver.Core.Tests/Core/Bindings/SplitReadWriteBindingTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 108 lines | 72 code | 22 blank | 14 comment | 0 complexity | 72003726a56e570a684a0c087435a5f6 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-2014 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.Threading;
  17. using FluentAssertions;
  18. using MongoDB.Driver.Core.Bindings;
  19. using MongoDB.Driver.Core.Clusters;
  20. using NSubstitute;
  21. using NUnit.Framework;
  22. namespace MongoDB.Driver.Core.Bindings
  23. {
  24. [TestFixture]
  25. public class SplitReadWriteBindingTests
  26. {
  27. private IReadBinding _readBinding;
  28. private IWriteBinding _writeBinding;
  29. [SetUp]
  30. public void Setup()
  31. {
  32. _readBinding = Substitute.For<IReadBinding>();
  33. _writeBinding = Substitute.For<IWriteBinding>();
  34. }
  35. [Test]
  36. public void Constructor_should_throw_if_readBinding_is_null()
  37. {
  38. Action act = () => new SplitReadWriteBinding(null, _writeBinding);
  39. act.ShouldThrow<ArgumentNullException>();
  40. }
  41. [Test]
  42. public void Constructor_should_throw_if_readPreference_is_null()
  43. {
  44. Action act = () => new SplitReadWriteBinding(_readBinding, null);
  45. act.ShouldThrow<ArgumentNullException>();
  46. }
  47. [Test]
  48. public void GetReadChannelSourceAsync_should_throw_if_disposed()
  49. {
  50. var subject = new SplitReadWriteBinding(_readBinding, _writeBinding);
  51. subject.Dispose();
  52. Action act = () => subject.GetReadChannelSourceAsync(CancellationToken.None);
  53. act.ShouldThrow<ObjectDisposedException>();
  54. }
  55. [Test]
  56. public void GetReadChannelSourceAsync_should_get_the_connection_source_from_the_read_binding()
  57. {
  58. var subject = new SplitReadWriteBinding(_readBinding, _writeBinding);
  59. subject.GetReadChannelSourceAsync(CancellationToken.None);
  60. _readBinding.Received().GetReadChannelSourceAsync(CancellationToken.None);
  61. }
  62. [Test]
  63. public void GetWriteChannelSourceAsync_should_throw_if_disposed()
  64. {
  65. var subject = new SplitReadWriteBinding(_readBinding, _writeBinding);
  66. subject.Dispose();
  67. Action act = () => subject.GetWriteChannelSourceAsync(CancellationToken.None);
  68. act.ShouldThrow<ObjectDisposedException>();
  69. }
  70. [Test]
  71. public void GetWriteChannelSourceAsync_should_get_the_connection_source_from_the_write_binding()
  72. {
  73. var subject = new SplitReadWriteBinding(_readBinding, _writeBinding);
  74. subject.GetWriteChannelSourceAsync(CancellationToken.None);
  75. _writeBinding.Received().GetWriteChannelSourceAsync(CancellationToken.None);
  76. }
  77. [Test]
  78. public void Dispose_should_call_dispose_on_read_binding_and_write_binding()
  79. {
  80. var subject = new SplitReadWriteBinding(_readBinding, _writeBinding);
  81. subject.Dispose();
  82. _readBinding.Received().Dispose();
  83. _writeBinding.Received().Dispose();
  84. }
  85. }
  86. }