PageRenderTime 78ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Misc/InterlockedInt32Tests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 67 lines | 47 code | 6 blank | 14 comment | 0 complexity | 272ac68e82d29aeaf2571bc7ed0d5e23 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-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 FluentAssertions;
  17. using MongoDB.Driver.Core.Misc;
  18. using Xunit;
  19. namespace MongoDB.Driver.Core.Misc
  20. {
  21. public class InterlockedInt32Tests
  22. {
  23. [Fact]
  24. public void Value_should_return_initial_value_after_construction()
  25. {
  26. var subject = new InterlockedInt32(3);
  27. subject.Value.Should().Be(3);
  28. }
  29. [Theory]
  30. [InlineData(0, 0, 0, false)]
  31. [InlineData(0, 1, 1, true)]
  32. [InlineData(1, 0, 0, true)]
  33. [InlineData(1, 1, 1, false)]
  34. public void TryChange_with_one_parameter(int initialValue, int toValue, int expectedValue, bool expectedResult)
  35. {
  36. var subject = new InterlockedInt32(initialValue);
  37. var result = subject.TryChange(toValue);
  38. subject.Value.Should().Be(expectedValue);
  39. result.Should().Be(expectedResult);
  40. }
  41. [Theory]
  42. [InlineData(0, 0, 1, 1, true)]
  43. [InlineData(0, 1, 2, 0, false)]
  44. [InlineData(1, 0, 1, 1, false)]
  45. [InlineData(1, 1, 2, 2, true)]
  46. public void TryChange_with_two_parameters(int startingValue, int fromValue, int toValue, int expectedValue, bool expectedResult)
  47. {
  48. var subject = new InterlockedInt32(startingValue);
  49. var result = subject.TryChange(fromValue, toValue);
  50. subject.Value.Should().Be(expectedValue);
  51. result.Should().Be(expectedResult);
  52. }
  53. [Fact]
  54. public void TryChange_with_two_parameters_should_throw_if_values_are_equal()
  55. {
  56. var subject = new InterlockedInt32(0);
  57. Action action = () => subject.TryChange(1, 1);
  58. action.ShouldThrow<ArgumentException>();
  59. }
  60. }
  61. }