PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/MongoWaitQueueFullExceptionTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 73 lines | 49 code | 10 blank | 14 comment | 0 complexity | 245796b1e625776275987897ccbc0cba 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.IO;
  16. using System.Net;
  17. #if NET452
  18. using System.Runtime.Serialization.Formatters.Binary;
  19. #endif
  20. using FluentAssertions;
  21. using Xunit;
  22. namespace MongoDB.Driver
  23. {
  24. public class MongoWaitQueueFullExceptionTests
  25. {
  26. [Fact]
  27. public void constructor_should_initalize_subject()
  28. {
  29. var subject = new MongoWaitQueueFullException("message");
  30. subject.Message.Should().Be("message");
  31. subject.InnerException.Should().BeNull();
  32. }
  33. [Fact]
  34. public void ForConnectionPool_should_create_expected_message()
  35. {
  36. var endPoint = new DnsEndPoint("localhost", 27017);
  37. var subject = MongoWaitQueueFullException.ForConnectionPool(endPoint);
  38. subject.Message.Should().Be("The wait queue for acquiring a connection to server localhost:27017 is full.");
  39. }
  40. [Fact]
  41. public void ForServerSelection_should_create_expected_message()
  42. {
  43. var subject = MongoWaitQueueFullException.ForServerSelection();
  44. subject.Message.Should().Be("The wait queue for server selection is full.");
  45. }
  46. #if NET452
  47. [Fact]
  48. public void Serialization_should_work()
  49. {
  50. var subject = new MongoWaitQueueFullException("message");
  51. var formatter = new BinaryFormatter();
  52. using (var stream = new MemoryStream())
  53. {
  54. formatter.Serialize(stream, subject);
  55. stream.Position = 0;
  56. var rehydrated = (MongoWaitQueueFullException)formatter.Deserialize(stream);
  57. rehydrated.Message.Should().Be(subject.Message);
  58. rehydrated.InnerException.Should().BeNull();
  59. }
  60. }
  61. #endif
  62. }
  63. }