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

/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/DeleteOneTest.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 56 lines | 37 code | 5 blank | 14 comment | 2 complexity | 7fb7b55ddd0e0308a74de4a7820c9afd 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;
  16. using System.Threading.Tasks;
  17. using FluentAssertions;
  18. using MongoDB.Bson;
  19. namespace MongoDB.Driver.Tests.Specifications.command_monitoring
  20. {
  21. public class DeleteOneTest : CrudOperationTestBase
  22. {
  23. private BsonDocument _filter;
  24. private WriteConcern _writeConcern = WriteConcern.Acknowledged;
  25. protected override void Execute(IMongoCollection<BsonDocument> collection, bool async)
  26. {
  27. var collectionWithWriteConcern = collection.WithWriteConcern(_writeConcern);
  28. if (async)
  29. {
  30. collectionWithWriteConcern.DeleteOneAsync(_filter).GetAwaiter().GetResult();
  31. }
  32. else
  33. {
  34. collectionWithWriteConcern.DeleteOne(_filter);
  35. }
  36. }
  37. protected override bool TrySetArgument(string name, BsonValue value)
  38. {
  39. switch (name)
  40. {
  41. case "filter":
  42. _filter = (BsonDocument)value;
  43. return true;
  44. case "writeConcern":
  45. _writeConcern = WriteConcern.FromBsonDocument((BsonDocument)value);
  46. return true;
  47. }
  48. return false;
  49. }
  50. }
  51. }