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

/tests/MongoDB.Driver.Core.Tests/Core/WireProtocol/Messages/DeleteMessageTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 70 lines | 48 code | 8 blank | 14 comment | 0 complexity | 84eb7a715b88e14a9f28b63493286dae 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 FluentAssertions;
  17. using MongoDB.Bson;
  18. using MongoDB.Driver.Core.WireProtocol.Messages;
  19. using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
  20. using Moq;
  21. using Xunit;
  22. namespace MongoDB.Driver.Core.WireProtocol.Messages
  23. {
  24. public class DeleteMessageTests
  25. {
  26. private readonly CollectionNamespace _collectionNamespace = new CollectionNamespace("database", "collection");
  27. private readonly bool _isMulti = true;
  28. private readonly BsonDocument _query = new BsonDocument("x", 1);
  29. private readonly int _requestId = 1;
  30. [Fact]
  31. public void Constructor_should_initialize_instance()
  32. {
  33. var subject = new DeleteMessage(_requestId, _collectionNamespace, _query, _isMulti);
  34. subject.CollectionNamespace.Should().Be(_collectionNamespace);
  35. subject.IsMulti.Should().Be(_isMulti);
  36. subject.Query.Should().Be(_query);
  37. subject.RequestId.Should().Be(_requestId);
  38. }
  39. [Fact]
  40. public void Constructor_with_null_collectionName_should_throw()
  41. {
  42. Action action = () => new DeleteMessage(_requestId, null, _query, _isMulti);
  43. action.ShouldThrow<ArgumentNullException>();
  44. }
  45. [Fact]
  46. public void Constructor_with_null_query_should_throw()
  47. {
  48. Action action = () => new DeleteMessage(_requestId, _collectionNamespace, null, _isMulti);
  49. action.ShouldThrow<ArgumentNullException>();
  50. }
  51. [Fact]
  52. public void GetEncoder_should_return_encoder()
  53. {
  54. var subject = new DeleteMessage(1, _collectionNamespace, new BsonDocument("x", 1), true);
  55. var mockEncoderFactory = new Mock<IMessageEncoderFactory>();
  56. var encoder = new Mock<IMessageEncoder>().Object;
  57. mockEncoderFactory.Setup(f => f.GetDeleteMessageEncoder()).Returns(encoder);
  58. var result = subject.GetEncoder(mockEncoderFactory.Object);
  59. result.Should().BeSameAs(encoder);
  60. }
  61. }
  62. }