Skip to content

Commit 63d5ac2

Browse files
vaughanrJamesNK
authored andcommitted
Added test for GrpcProtocol timeout parsing (#727)
1 parent 444ff1b commit 63d5ac2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/Grpc.AspNetCore.Server.Tests/GrpcProtocolHelpersTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#endregion
1818

19+
using System;
1920
using System.Linq;
2021
using System.Security.Cryptography.X509Certificates;
2122
using Grpc.AspNetCore.Server.Internal;
@@ -76,5 +77,28 @@ public void CreateAuthContext_CertWithCommonName_UseCommonNameAsPeerIdentity()
7677
var allProperties = authContext.Properties.ToList();
7778
Assert.AreEqual(1, allProperties.Count);
7879
}
80+
81+
[TestCase("1H", 36000000000, true)]
82+
[TestCase("1M", 600000000, true)]
83+
[TestCase("1S", 10000000, true)]
84+
[TestCase("1m", 10000, true)]
85+
[TestCase("1u", 10, true)]
86+
[TestCase("100n", 1, true)]
87+
[TestCase("0S", 0, true)]
88+
[TestCase("", 0, false)]
89+
[TestCase("5", 0, false)]
90+
[TestCase("M", 0, false)]
91+
public void TryDecodeTimeout_WithVariousUnits_ShouldMatchExpected(string timeout, long expectedTicks, bool expectedSuccesfullyDecoded)
92+
{
93+
// Arrange
94+
var expectedTimespan = new TimeSpan(expectedTicks);
95+
96+
// Act
97+
var successfullyDecoded = GrpcProtocolHelpers.TryDecodeTimeout(timeout, out var timeSpan);
98+
99+
// Assert
100+
Assert.AreEqual(expectedSuccesfullyDecoded, successfullyDecoded);
101+
Assert.AreEqual(expectedTimespan, timeSpan);
102+
}
79103
}
80104
}

0 commit comments

Comments
 (0)