PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Tests/Linq/Translators/ProjectedObjectTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 91 lines | 58 code | 19 blank | 14 comment | 0 complexity | 8ea5b88050f4a50c318a694ea3cd0c75 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 FluentAssertions;
  16. using MongoDB.Driver.Linq.Translators;
  17. using Xunit;
  18. namespace MongoDB.Driver.Tests.Linq.Translators
  19. {
  20. public class ProjectedObjectTests
  21. {
  22. [Fact]
  23. public void Should_retrieve_scalar_value_from_top_level()
  24. {
  25. var subject = CreateSubject();
  26. var a = subject.GetValue<int>("a", 10);
  27. a.Should().Be(1);
  28. }
  29. [Fact]
  30. public void Should_retrieve_dotted_value_from_top_level()
  31. {
  32. var subject = CreateSubject();
  33. var c = subject.GetValue<int>("b.c", 10);
  34. c.Should().Be(2);
  35. }
  36. [Fact]
  37. public void Should_retrieve_value_from_nested_level()
  38. {
  39. var subject = CreateSubject();
  40. var g = subject.GetValue<string>("d.e", "not");
  41. g.Should().Be("funny");
  42. }
  43. [Fact]
  44. public void Should_retrieve_dotted_value_from_nested_level()
  45. {
  46. var subject = CreateSubject();
  47. var g = subject.GetValue<int>("d.f.g", 20);
  48. g.Should().Be(10);
  49. }
  50. [Fact]
  51. public void Should_retrieve_dotted_value_from_dotted_nested_level()
  52. {
  53. var subject = CreateSubject();
  54. var g = subject.GetValue<int>("h.i.j.k", 10);
  55. g.Should().Be(30);
  56. }
  57. private ProjectedObject CreateSubject()
  58. {
  59. var root = new ProjectedObject();
  60. root.Add("a", 1);
  61. root.Add("b.c", 2);
  62. var d = new ProjectedObject();
  63. root.Add("d", d);
  64. d.Add("e", "funny");
  65. d.Add("f.g", 10);
  66. var h = new ProjectedObject();
  67. root.Add("h.i", h);
  68. h.Add("j.k", 30);
  69. return root;
  70. }
  71. }
  72. }