PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 71 lines | 50 code | 7 blank | 14 comment | 0 complexity | d6359d7b74ebdfb21066ad560bbc5eca MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-2014 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. using System.Runtime.Serialization.Formatters.Binary;
  18. using FluentAssertions;
  19. using MongoDB.Bson;
  20. using MongoDB.Driver.Core.Clusters;
  21. using MongoDB.Driver.Core.Connections;
  22. using MongoDB.Driver.Core.Servers;
  23. using NUnit.Framework;
  24. namespace MongoDB.Driver
  25. {
  26. [TestFixture]
  27. public class MongoCursorNotFoundExceptionTests
  28. {
  29. private readonly ConnectionId _connectionId = new ConnectionId(new ServerId(new ClusterId(1), new DnsEndPoint("localhost", 27017)), 1).WithServerValue(2);
  30. private readonly long _cursorId = 1;
  31. private readonly BsonDocument _query = new BsonDocument("query", 1);
  32. [Test]
  33. public void constructor_should_initalize_subject()
  34. {
  35. var subject = new MongoCursorNotFoundException(_connectionId, _cursorId, _query);
  36. subject.ConnectionId.Should().BeSameAs(_connectionId);
  37. subject.CursorId.Should().Be(_cursorId);
  38. subject.InnerException.Should().BeNull();
  39. subject.Message.Should().StartWith("Cursor 1 not found");
  40. subject.Message.Should().Contain("server localhost:27017");
  41. subject.Message.Should().Contain("connection 2");
  42. subject.Query.Should().BeSameAs(_query);
  43. subject.QueryResult.Should().BeNull();
  44. }
  45. [Test]
  46. public void Serialization_should_work()
  47. {
  48. var subject = new MongoCursorNotFoundException(_connectionId, _cursorId, _query);
  49. var formatter = new BinaryFormatter();
  50. using (var stream = new MemoryStream())
  51. {
  52. formatter.Serialize(stream, subject);
  53. stream.Position = 0;
  54. var rehydrated = (MongoCursorNotFoundException)formatter.Deserialize(stream);
  55. rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
  56. rehydrated.CursorId.Should().Be(subject.CursorId);
  57. rehydrated.InnerException.Should().BeNull();
  58. rehydrated.Message.Should().Be(subject.Message);
  59. rehydrated.Query.Should().Be(subject.Query);
  60. rehydrated.QueryResult.Should().Be(subject.QueryResult);
  61. }
  62. }
  63. }
  64. }