PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 74 lines | 53 code | 7 blank | 14 comment | 0 complexity | 38ea39c14b71dc524c88b1bb1f6adce3 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.Bson;
  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 MongoCursorNotFoundExceptionTests
  29. {
  30. private readonly ConnectionId _connectionId = new ConnectionId(new ServerId(new ClusterId(1), new DnsEndPoint("localhost", 27017)), 1).WithServerValue(2);
  31. private readonly long _cursorId = 1;
  32. private readonly BsonDocument _query = new BsonDocument("query", 1);
  33. [Fact]
  34. public void constructor_should_initalize_subject()
  35. {
  36. var subject = new MongoCursorNotFoundException(_connectionId, _cursorId, _query);
  37. subject.ConnectionId.Should().BeSameAs(_connectionId);
  38. subject.CursorId.Should().Be(_cursorId);
  39. subject.InnerException.Should().BeNull();
  40. subject.Message.Should().StartWith("Cursor 1 not found");
  41. subject.Message.Should().Contain("server localhost:27017");
  42. subject.Message.Should().Contain("connection 2");
  43. subject.Query.Should().BeSameAs(_query);
  44. subject.QueryResult.Should().BeNull();
  45. }
  46. #if NET452
  47. [Fact]
  48. public void Serialization_should_work()
  49. {
  50. var subject = new MongoCursorNotFoundException(_connectionId, _cursorId, _query);
  51. var formatter = new BinaryFormatter();
  52. using (var stream = new MemoryStream())
  53. {
  54. formatter.Serialize(stream, subject);
  55. stream.Position = 0;
  56. var rehydrated = (MongoCursorNotFoundException)formatter.Deserialize(stream);
  57. rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
  58. rehydrated.CursorId.Should().Be(subject.CursorId);
  59. rehydrated.InnerException.Should().BeNull();
  60. rehydrated.Message.Should().Be(subject.Message);
  61. rehydrated.Query.Should().Be(subject.Query);
  62. rehydrated.QueryResult.Should().Be(subject.QueryResult);
  63. }
  64. }
  65. #endif
  66. }
  67. }