PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Bson.Tests/ObjectModel/BsonStringTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 88 lines | 61 code | 13 blank | 14 comment | 0 complexity | f547493e78719f5b252ad473535a45ca MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2015-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.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using FluentAssertions;
  21. using MongoDB.Bson.TestHelpers.XunitExtensions;
  22. using Xunit;
  23. namespace MongoDB.Bson.Tests.ObjectModel
  24. {
  25. public class BsonStringTests
  26. {
  27. [Theory]
  28. [ParameterAttributeData]
  29. public void implicit_conversion_from_string_should_return_new_instance(
  30. [Values("x")]
  31. string value)
  32. {
  33. var result1 = (BsonString)value;
  34. var result2 = (BsonString)value;
  35. result2.Should().NotBeSameAs(result1);
  36. }
  37. [Theory]
  38. [ParameterAttributeData]
  39. public void implicit_conversion_from_string_should_return_precreated_instance(
  40. [Values("")]
  41. string value)
  42. {
  43. var result1 = (BsonString)value;
  44. var result2 = (BsonString)value;
  45. result2.Should().BeSameAs(result1);
  46. }
  47. [Theory]
  48. [ParameterAttributeData]
  49. public void precreated_instances_should_have_the_expected_value(
  50. [Values("")]
  51. string value)
  52. {
  53. var result = (BsonString)value;
  54. result.Value.Should().Be(value);
  55. }
  56. [Theory]
  57. [InlineData("-1")]
  58. [InlineData("1")]
  59. public void ToDecimal_should_return_expected_result(string stringValue)
  60. {
  61. var subject = new BsonString(stringValue);
  62. var result = subject.ToDecimal();
  63. result.Should().Be(decimal.Parse(stringValue));
  64. }
  65. [Theory]
  66. [InlineData("-1")]
  67. [InlineData("1")]
  68. public void ToDecimal128_should_return_expected_result(string stringValue)
  69. {
  70. var subject = new BsonString(stringValue);
  71. var result = subject.ToDecimal128();
  72. result.Should().Be(Decimal128.Parse(stringValue));
  73. }
  74. }
  75. }