PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 73 lines | 51 code | 8 blank | 14 comment | 0 complexity | 6349e4d64b507f4f196fad9193772fbc 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 MongoDB.Driver.Core.Clusters;
  22. using MongoDB.Driver.Core.Misc;
  23. using MongoDB.Driver.Core.Servers;
  24. using Xunit;
  25. namespace MongoDB.Driver
  26. {
  27. public class MongoIncompatibleDriverExceptionTests
  28. {
  29. private ClusterDescription _clusterDescription;
  30. public MongoIncompatibleDriverExceptionTests()
  31. {
  32. var clusterId = new ClusterId(1);
  33. var connectionMode = ClusterConnectionMode.Standalone;
  34. var clusterType = ClusterType.Standalone;
  35. var endPoint = new DnsEndPoint("localhost", 27017);
  36. var serverId = new ServerId(clusterId, endPoint);
  37. var server = new ServerDescription(serverId, endPoint, wireVersionRange: new Range<int>(0, 0), type: ServerType.Standalone);
  38. var servers = new[] { server };
  39. _clusterDescription = new ClusterDescription(clusterId, connectionMode, clusterType, servers);
  40. }
  41. [Fact]
  42. public void constructor_should_initalize_subject()
  43. {
  44. var subject = new MongoIncompatibleDriverException(_clusterDescription);
  45. subject.Message.Should().StartWith("Server at localhost:27017 reports wire version 0");
  46. subject.InnerException.Should().BeNull();
  47. }
  48. #if NET452
  49. [Fact]
  50. public void Serialization_should_work()
  51. {
  52. var subject = new MongoIncompatibleDriverException(_clusterDescription);
  53. var formatter = new BinaryFormatter();
  54. using (var stream = new MemoryStream())
  55. {
  56. formatter.Serialize(stream, subject);
  57. stream.Position = 0;
  58. var rehydrated = (MongoIncompatibleDriverException)formatter.Deserialize(stream);
  59. rehydrated.Message.Should().Be(subject.Message);
  60. rehydrated.InnerException.Should().BeNull();
  61. }
  62. }
  63. #endif
  64. }
  65. }