|
19 | 19 | using MongoDB.Driver.Core.Misc;
|
20 | 20 | using Xunit;
|
21 | 21 |
|
22 |
| -namespace MongoDB.Driver.Tests |
| 22 | +namespace MongoDB.Driver.Tests; |
| 23 | + |
| 24 | +public class OperationContextExtensionsTests |
23 | 25 | {
|
24 |
| - public class OperationContextExtensionsTests |
| 26 | + [Fact] |
| 27 | + public void IsRootContextTimeoutConfigured_should_throw_on_null() |
25 | 28 | {
|
26 |
| - [Fact] |
27 |
| - public void IsRootContextTimeoutConfigured_should_throw_on_null() |
28 |
| - { |
29 |
| - OperationContext context = null; |
30 |
| - var exception = Record.Exception(() => context.IsRootContextTimeoutConfigured()); |
| 29 | + OperationContext context = null; |
| 30 | + var exception = Record.Exception(() => context.IsRootContextTimeoutConfigured()); |
31 | 31 |
|
32 |
| - exception.Should().BeOfType<ArgumentNullException>().Subject |
33 |
| - .ParamName.Should().Be("operationContext"); |
34 |
| - } |
| 32 | + exception.Should().BeOfType<ArgumentNullException>().Subject |
| 33 | + .ParamName.Should().Be("operationContext"); |
| 34 | + } |
35 | 35 |
|
36 |
| - [Theory] |
37 |
| - [InlineData(false, null)] |
38 |
| - [InlineData(true, 0)] |
39 |
| - [InlineData(true, Timeout.Infinite)] |
40 |
| - [InlineData(true, 5)] |
41 |
| - public void IsRootContextTimeoutConfigured_should_return_expected_result(bool expectedResult, int? timeoutMs) |
42 |
| - { |
43 |
| - TimeSpan? timeout = timeoutMs.HasValue ? TimeSpan.FromMilliseconds(timeoutMs.Value) : null; |
44 |
| - var subject = new OperationContext(timeout, CancellationToken.None); |
| 36 | + [Theory] |
| 37 | + [InlineData(false, null)] |
| 38 | + [InlineData(true, 0)] |
| 39 | + [InlineData(true, Timeout.Infinite)] |
| 40 | + [InlineData(true, 5)] |
| 41 | + public void IsRootContextTimeoutConfigured_should_return_expected_result(bool expectedResult, int? timeoutMs) |
| 42 | + { |
| 43 | + TimeSpan? timeout = timeoutMs.HasValue ? TimeSpan.FromMilliseconds(timeoutMs.Value) : null; |
| 44 | + var subject = new OperationContext(timeout, CancellationToken.None); |
45 | 45 |
|
46 |
| - var result = subject.IsRootContextTimeoutConfigured(); |
| 46 | + var result = subject.IsRootContextTimeoutConfigured(); |
47 | 47 |
|
48 |
| - result.Should().Be(expectedResult); |
49 |
| - } |
| 48 | + result.Should().Be(expectedResult); |
| 49 | + } |
50 | 50 |
|
51 |
| - [Fact] |
52 |
| - public void RemainingTimeoutOrDefault_should_throw_on_null() |
53 |
| - { |
54 |
| - OperationContext context = null; |
55 |
| - var exception = Record.Exception(() => context.RemainingTimeoutOrDefault(TimeSpan.Zero)); |
| 51 | + [Fact] |
| 52 | + public void RemainingTimeoutOrDefault_should_throw_on_null() |
| 53 | + { |
| 54 | + OperationContext context = null; |
| 55 | + var exception = Record.Exception(() => context.RemainingTimeoutOrDefault(TimeSpan.Zero)); |
56 | 56 |
|
57 |
| - exception.Should().BeOfType<ArgumentNullException>().Subject |
58 |
| - .ParamName.Should().Be("operationContext"); |
59 |
| - } |
| 57 | + exception.Should().BeOfType<ArgumentNullException>().Subject |
| 58 | + .ParamName.Should().Be("operationContext"); |
| 59 | + } |
60 | 60 |
|
61 |
| - [Theory] |
62 |
| - [InlineData(10, null, 10)] |
63 |
| - [InlineData(0, 0, 10)] |
64 |
| - [InlineData(Timeout.Infinite, Timeout.Infinite, 10)] |
65 |
| - [InlineData(5, 5, 10)] |
66 |
| - public void RemainingTimeoutOrDefault_should_return_expected_result(int expectedResultMs, int? timeoutMs, int defaultValueMs) |
67 |
| - { |
68 |
| - var clock = new FrozenClock(DateTime.UtcNow); |
69 |
| - TimeSpan? timeout = timeoutMs.HasValue ? TimeSpan.FromMilliseconds(timeoutMs.Value) : null; |
70 |
| - var defaultValue = TimeSpan.FromMilliseconds(defaultValueMs); |
71 |
| - var subject = new OperationContext(clock, timeout, CancellationToken.None); |
| 61 | + [Theory] |
| 62 | + [InlineData(10, null, 10)] |
| 63 | + [InlineData(0, 0, 10)] |
| 64 | + [InlineData(Timeout.Infinite, Timeout.Infinite, 10)] |
| 65 | + [InlineData(5, 5, 10)] |
| 66 | + public void RemainingTimeoutOrDefault_should_return_expected_result(int expectedResultMs, int? timeoutMs, int defaultValueMs) |
| 67 | + { |
| 68 | + var clock = new FrozenClock(DateTime.UtcNow); |
| 69 | + TimeSpan? timeout = timeoutMs.HasValue ? TimeSpan.FromMilliseconds(timeoutMs.Value) : null; |
| 70 | + var defaultValue = TimeSpan.FromMilliseconds(defaultValueMs); |
| 71 | + var subject = new OperationContext(clock, timeout, CancellationToken.None); |
72 | 72 |
|
73 |
| - var result = subject.RemainingTimeoutOrDefault(defaultValue); |
| 73 | + var result = subject.RemainingTimeoutOrDefault(defaultValue); |
74 | 74 |
|
75 |
| - result.Should().Be(TimeSpan.FromMilliseconds(expectedResultMs)); |
76 |
| - } |
| 75 | + result.Should().Be(TimeSpan.FromMilliseconds(expectedResultMs)); |
77 | 76 | }
|
78 | 77 | }
|
79 |
| - |
0 commit comments