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

/tests/MongoDB.Driver.Tests/Specifications/crud/DeleteManyTest.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 67 lines | 46 code | 7 blank | 14 comment | 2 complexity | 99b405f86c6cc423e752318e48a7a9d3 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2010-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.Threading.Tasks;
  16. using FluentAssertions;
  17. using MongoDB.Bson;
  18. namespace MongoDB.Driver.Tests.Specifications.crud
  19. {
  20. public class DeleteManyTest : CrudOperationWithResultTestBase<DeleteResult>
  21. {
  22. private BsonDocument _filter;
  23. private DeleteOptions _options = new DeleteOptions();
  24. protected override bool TrySetArgument(string name, BsonValue value)
  25. {
  26. switch (name)
  27. {
  28. case "filter":
  29. _filter = (BsonDocument)value;
  30. return true;
  31. case "collation":
  32. _options.Collation = Collation.FromBsonDocument(value.AsBsonDocument);
  33. return true;
  34. case "hint":
  35. _options.Hint = value;
  36. return true;
  37. }
  38. return false;
  39. }
  40. protected override DeleteResult ConvertExpectedResult(BsonValue expectedResult)
  41. {
  42. return new DeleteResult.Acknowledged(expectedResult["deletedCount"].ToInt64());
  43. }
  44. protected override DeleteResult ExecuteAndGetResult(IMongoDatabase database, IMongoCollection<BsonDocument> collection, bool async)
  45. {
  46. if (async)
  47. {
  48. return collection.DeleteManyAsync(_filter, _options).GetAwaiter().GetResult();
  49. }
  50. else
  51. {
  52. return collection.DeleteMany(_filter, _options);
  53. }
  54. }
  55. protected override void VerifyResult(DeleteResult actualResult, DeleteResult expectedResult)
  56. {
  57. actualResult.DeletedCount.Should().Be(expectedResult.DeletedCount);
  58. }
  59. }
  60. }