PageRenderTime 60ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 68 lines | 45 code | 9 blank | 14 comment | 0 complexity | fa49321d0453909de933f2443352f0dc 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. #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 MongoConfigurationExceptionTests
  25. {
  26. private Exception _innerException = new Exception("inner");
  27. private string _message = "message";
  28. [Fact]
  29. public void constructor_should_initialize_subject()
  30. {
  31. var subject = new MongoConfigurationException(_message);
  32. subject.Message.Should().BeSameAs(_message);
  33. subject.InnerException.Should().BeNull();
  34. }
  35. [Fact]
  36. public void constructor_with_innerException_should_initialize_subject()
  37. {
  38. var subject = new MongoConfigurationException(_message, _innerException);
  39. subject.Message.Should().BeSameAs(_message);
  40. subject.InnerException.Should().BeSameAs(_innerException);
  41. }
  42. #if NET452
  43. [Fact]
  44. public void Serialization_should_work()
  45. {
  46. var subject = new MongoConfigurationException(_message, _innerException);
  47. var formatter = new BinaryFormatter();
  48. using (var stream = new MemoryStream())
  49. {
  50. formatter.Serialize(stream, subject);
  51. stream.Position = 0;
  52. var rehydrated = (MongoConfigurationException)formatter.Deserialize(stream);
  53. rehydrated.Message.Should().Be(subject.Message);
  54. rehydrated.InnerException.Message.Should().Be(subject.InnerException.Message); // Exception does not override Equals
  55. }
  56. }
  57. #endif
  58. }
  59. }