-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathRollbarRateLimitFixture.cs
69 lines (61 loc) · 2.35 KB
/
RollbarRateLimitFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace UnitTest.Rollbar
{
using global::Rollbar;
using global::Rollbar.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;
using System.Text;
using System.Net.Http.Headers;
using Moq;
using System.Linq;
using global::Rollbar.Infrastructure;
/// <summary>
/// Defines test class RollbarRateLimitFixture.
/// </summary>
[TestClass]
[TestCategory(nameof(RollbarRateLimitFixture))]
public class RollbarRateLimitFixture
{
/// <summary>
/// Setups the fixture.
/// </summary>
[TestInitialize]
public void SetupFixture()
{
}
/// <summary>
/// Tears down fixture.
/// </summary>
[TestCleanup]
public void TearDownFixture()
{
}
/// <summary>
/// Defines the test method TestRollbarRateLimit.
/// </summary>
[TestMethod]
public void TestRollbarRateLimit()
{
var headersMock = new Mock<HttpHeaders>();
HttpHeaders headers = headersMock.Object;
var limitHeader = RollbarRateLimit.RollbarRateLimitHeaders.Limit;
var limitValue = 5000;
headers.Add(limitHeader, limitValue.ToString());
var remainingHeader = RollbarRateLimit.RollbarRateLimitHeaders.Remaining;
var remainingValue = 4992;
headers.Add(remainingHeader, remainingValue.ToString());
var resetHeader = RollbarRateLimit.RollbarRateLimitHeaders.Reset;
var resetValue = 1554828920;
headers.Add(resetHeader, resetValue.ToString());
var remainingSecondsHeader = RollbarRateLimit.RollbarRateLimitHeaders.RemainingSeconds;
var remainingSecondsValue = 60;
headers.Add(remainingSecondsHeader, remainingSecondsValue.ToString());
RollbarRateLimit rollbarRateLimit = new RollbarRateLimit(headers);
Assert.AreEqual(remainingValue, rollbarRateLimit.WindowRemaining);
Assert.AreEqual(limitValue, rollbarRateLimit.WindowLimit);
Assert.AreEqual(TimeSpan.FromSeconds(remainingSecondsValue), rollbarRateLimit.WindowRemainingTimeSpan);
Assert.AreEqual(DateTimeUtil.ConvertFromUnixTimestampInSeconds(resetValue), rollbarRateLimit.WindowEnd);
}
}
}