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

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

http://github.com/mongodb/mongo-csharp-driver
C# | 64 lines | 45 code | 5 blank | 14 comment | 2 complexity | 77705403c80938526ae46e898ecf03ef 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 UpdateOneTest : CrudOperationTestBase
  22. {
  23. private BsonDocument _filter;
  24. private BsonDocument _update;
  25. private UpdateOptions _options = new UpdateOptions();
  26. private WriteConcern _writeConcern = WriteConcern.Acknowledged;
  27. protected override bool TrySetArgument(string name, BsonValue value)
  28. {
  29. switch (name)
  30. {
  31. case "filter":
  32. _filter = (BsonDocument)value;
  33. return true;
  34. case "update":
  35. _update = (BsonDocument)value;
  36. return true;
  37. case "upsert":
  38. _options.IsUpsert = value.ToBoolean();
  39. return true;
  40. case "writeConcern":
  41. _writeConcern = WriteConcern.FromBsonDocument((BsonDocument)value);
  42. return true;
  43. }
  44. return false;
  45. }
  46. protected override void Execute(IMongoCollection<BsonDocument> collection, bool async)
  47. {
  48. var collectionWithWriteConcern = collection.WithWriteConcern(_writeConcern);
  49. if (async)
  50. {
  51. collectionWithWriteConcern.UpdateOneAsync(_filter, _update, _options).GetAwaiter().GetResult();
  52. }
  53. else
  54. {
  55. collectionWithWriteConcern.UpdateOne(_filter, _update, _options);
  56. }
  57. }
  58. }
  59. }