PageRenderTime 46ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 64 lines | 43 code | 7 blank | 14 comment | 0 complexity | 98c0996b67cb3f808a22ded91208e3cc 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 System.IO;
  17. using System.Net;
  18. #if NET452
  19. using System.Runtime.Serialization.Formatters.Binary;
  20. #endif
  21. using FluentAssertions;
  22. using MongoDB.Driver.Core.Clusters;
  23. using MongoDB.Driver.Core.Connections;
  24. using MongoDB.Driver.Core.Servers;
  25. using Xunit;
  26. namespace MongoDB.Driver
  27. {
  28. public class MongoConnectionFailedExceptionTests
  29. {
  30. private readonly ConnectionId _connectionId = new ConnectionId(new ServerId(new ClusterId(1), new DnsEndPoint("localhost", 27017)), 2).WithServerValue(3);
  31. [Fact]
  32. public void constructor_should_initialize_subject()
  33. {
  34. var subject = new MongoConnectionClosedException(_connectionId);
  35. subject.ConnectionId.Should().BeSameAs(_connectionId);
  36. subject.InnerException.Should().BeNull();
  37. subject.Message.Should().BeSameAs("The connection was closed while we were waiting our turn to use it.");
  38. }
  39. #if NET452
  40. [Fact]
  41. public void Serialization_should_work()
  42. {
  43. var subject = new MongoConnectionClosedException(_connectionId);
  44. var formatter = new BinaryFormatter();
  45. using (var stream = new MemoryStream())
  46. {
  47. formatter.Serialize(stream, subject);
  48. stream.Position = 0;
  49. var rehydrated = (MongoConnectionClosedException)formatter.Deserialize(stream);
  50. rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
  51. rehydrated.InnerException.Should().BeNull();
  52. rehydrated.Message.Should().Be(subject.Message);
  53. }
  54. }
  55. #endif
  56. }
  57. }