PageRenderTime 34ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 76 lines | 53 code | 9 blank | 14 comment | 0 complexity | c25560b5ac63517e6e8dd4425ce6824d 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 MongoExecutionTimeoutExceptionTests
  29. {
  30. private readonly ConnectionId _connectionId = new ConnectionId(new ServerId(new ClusterId(1), new DnsEndPoint("localhost", 27017)), 2).WithServerValue(3);
  31. private Exception _innerException = new Exception("inner");
  32. private string _message = "message";
  33. [Fact]
  34. public void constructor_should_initialize_subject()
  35. {
  36. var subject = new MongoExecutionTimeoutException(_connectionId, _message);
  37. subject.ConnectionId.Should().BeSameAs(_connectionId);
  38. subject.InnerException.Should().BeNull();
  39. subject.Message.Should().BeSameAs(_message);
  40. }
  41. [Fact]
  42. public void constructor_with_innerException_should_initialize_subject()
  43. {
  44. var subject = new MongoExecutionTimeoutException(_connectionId, _message, _innerException);
  45. subject.ConnectionId.Should().BeSameAs(_connectionId);
  46. subject.InnerException.Should().BeSameAs(_innerException);
  47. subject.Message.Should().BeSameAs(_message);
  48. }
  49. #if NET452
  50. [Fact]
  51. public void Serialization_should_work()
  52. {
  53. var subject = new MongoExecutionTimeoutException(_connectionId, _message, _innerException);
  54. var formatter = new BinaryFormatter();
  55. using (var stream = new MemoryStream())
  56. {
  57. formatter.Serialize(stream, subject);
  58. stream.Position = 0;
  59. var rehydrated = (MongoExecutionTimeoutException)formatter.Deserialize(stream);
  60. rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
  61. rehydrated.Message.Should().Be(subject.Message);
  62. rehydrated.InnerException.Message.Should().Be(subject.InnerException.Message); // Exception does not override Equals
  63. }
  64. }
  65. #endif
  66. }
  67. }