public void GaugeBoundsTest() { using (var toolStrip = new TestToolStripAPIGauge()) { toolStrip.AutoSize = false; toolStrip.Size = new Size(100, 10); toolStrip.GaugeHeight = 5; // 現在時刻を偽装 toolStrip.Now = new DateTime(2013, 1, 1, 0, 0, 0); // toolStrip.ApiLimit の初期値は null Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(Rectangle.Empty)); Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(Rectangle.Empty)); toolStrip.ApiLimit = new ApiLimit(150, 60, toolStrip.Now.AddMinutes(15)); Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(new Rectangle(0, 0, 40, 5))); // 40% (60/150) Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(new Rectangle(0, 5, 25, 5))); // 25% (15/60) toolStrip.ApiLimit = null; Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(Rectangle.Empty)); Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(Rectangle.Empty)); } }
public void OneBillionTest() { using var toolStrip = new TestToolStripAPIGauge(); var now = new DateTimeUtc(2020, 2, 25, 19, 0, 0); toolStrip.DateTimeNow = now; toolStrip.AutoSize = false; toolStrip.Size = new Size(100, 10); toolStrip.GaugeHeight = 5; MyCommon.TwitterApiInfo.AccessLimit["/statuses/user_timeline"] = new ApiLimit( limitCount: 1_000_000_000, limitRemain: 999_999_999, resetDate: now + TimeSpan.FromMinutes(15) ); toolStrip.ApiEndpoint = "/statuses/user_timeline"; Assert.Equal(new Rectangle(0, 0, 99, 5), toolStrip.apiGaugeBounds); // 99% (999999999/1000000000) Assert.Equal(new Rectangle(0, 5, 100, 5), toolStrip.timeGaugeBounds); // 100% (15/15) Assert.Equal("API 999999999/1000000000", toolStrip.Text); Assert.Equal("API rest /statuses/user_timeline 999999999/1000000000" + Environment.NewLine + "(reset after 15 minutes)", toolStrip.ToolTipText); MyCommon.TwitterApiInfo.AccessLimit.Clear(); }
public void GaugeBoundsTest() { using (var toolStrip = new TestToolStripAPIGauge()) { var now = DateTimeUtc.Now; toolStrip.DateTimeNow = now; toolStrip.AutoSize = false; toolStrip.Size = new Size(100, 10); toolStrip.GaugeHeight = 5; // toolStrip.ApiEndpoint の初期値は null Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds); Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds); MyCommon.TwitterApiInfo.AccessLimit["endpoint"] = new ApiLimit(150, 60, now + TimeSpan.FromMinutes(3)); toolStrip.ApiEndpoint = "endpoint"; Assert.Equal(new Rectangle(0, 0, 40, 5), toolStrip.apiGaugeBounds); // 40% (60/150) Assert.Equal(new Rectangle(0, 5, 20, 5), toolStrip.timeGaugeBounds); // 20% (3/15) toolStrip.ApiEndpoint = ""; Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds); Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds); MyCommon.TwitterApiInfo.AccessLimit.Clear(); } }
public void ApiEndpointTest() { using (var toolStrip = new TestToolStripAPIGauge()) { var now = DateTimeUtc.Now; toolStrip.DateTimeNow = now; MyCommon.TwitterApiInfo.AccessLimit["endpoint1"] = new ApiLimit(15, 15, now + TimeSpan.FromMinutes(15)); MyCommon.TwitterApiInfo.AccessLimit["endpoint2"] = new ApiLimit(180, 18, now + TimeSpan.FromMinutes(5)); // toolStrip.ApiEndpoint の初期値は null Assert.Null(toolStrip.ApiEndpoint); Assert.Null(toolStrip.ApiLimit); toolStrip.ApiEndpoint = "endpoint1"; Assert.Equal("endpoint1", toolStrip.ApiEndpoint); Assert.Equal(new ApiLimit(15, 15, now + TimeSpan.FromMinutes(15)), toolStrip.ApiLimit); toolStrip.ApiEndpoint = "endpoint2"; Assert.Equal("endpoint2", toolStrip.ApiEndpoint); Assert.Equal(new ApiLimit(180, 18, now + TimeSpan.FromMinutes(5)), toolStrip.ApiLimit); MyCommon.TwitterApiInfo.AccessLimit["endpoint2"] = new ApiLimit(180, 17, now + TimeSpan.FromMinutes(5)); toolStrip.ApiEndpoint = "endpoint2"; Assert.Equal("endpoint2", toolStrip.ApiEndpoint); Assert.Equal(new ApiLimit(180, 17, now + TimeSpan.FromMinutes(5)), toolStrip.ApiLimit); toolStrip.ApiEndpoint = "hoge"; Assert.Equal("hoge", toolStrip.ApiEndpoint); Assert.Null(toolStrip.ApiLimit); toolStrip.ApiEndpoint = ""; Assert.Null(toolStrip.ApiEndpoint); Assert.Null(toolStrip.ApiLimit); MyCommon.TwitterApiInfo.AccessLimit.Clear(); } }
public void ApiEndpointTest() { using (var toolStrip = new TestToolStripAPIGauge()) { var now = DateTime.Now; toolStrip.DateTimeNow = now; MyCommon.TwitterApiInfo.AccessLimit["endpoint1"] = new ApiLimit(15, 15, now.AddMinutes(15)); MyCommon.TwitterApiInfo.AccessLimit["endpoint2"] = new ApiLimit(180, 18, now.AddMinutes(5)); // toolStrip.ApiEndpoint の初期値は null Assert.Equal(null, toolStrip.ApiEndpoint); Assert.Equal(null, toolStrip.ApiLimit); toolStrip.ApiEndpoint = "endpoint1"; Assert.Equal("endpoint1", toolStrip.ApiEndpoint); Assert.Equal(new ApiLimit(15, 15, now.AddMinutes(15)), toolStrip.ApiLimit); toolStrip.ApiEndpoint = "endpoint2"; Assert.Equal("endpoint2", toolStrip.ApiEndpoint); Assert.Equal(new ApiLimit(180, 18, now.AddMinutes(5)), toolStrip.ApiLimit); MyCommon.TwitterApiInfo.AccessLimit["endpoint2"] = new ApiLimit(180, 17, now.AddMinutes(5)); toolStrip.ApiEndpoint = "endpoint2"; Assert.Equal("endpoint2", toolStrip.ApiEndpoint); Assert.Equal(new ApiLimit(180, 17, now.AddMinutes(5)), toolStrip.ApiLimit); toolStrip.ApiEndpoint = "hoge"; Assert.Equal("hoge", toolStrip.ApiEndpoint); Assert.Equal(null, toolStrip.ApiLimit); toolStrip.ApiEndpoint = ""; Assert.Equal(null, toolStrip.ApiEndpoint); Assert.Equal(null, toolStrip.ApiLimit); MyCommon.TwitterApiInfo.AccessLimit.Clear(); } }
public void GaugeBoundsTest() { using (var toolStrip = new TestToolStripAPIGauge()) { toolStrip.AutoSize = false; toolStrip.Size = new Size(100, 10); toolStrip.GaugeHeight = 5; // toolStrip.ApiEndpoint の初期値は null Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds); Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds); MyCommon.TwitterApiInfo.AccessLimit["endpoint"] = new ApiLimit(150, 60, Clock.Now.AddMinutes(3)); toolStrip.ApiEndpoint = "endpoint"; Assert.Equal(new Rectangle(0, 0, 40, 5), toolStrip.apiGaugeBounds); // 40% (60/150) Assert.Equal(new Rectangle(0, 5, 20, 5), toolStrip.timeGaugeBounds); // 20% (3/15) toolStrip.ApiEndpoint = ""; Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds); Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds); MyCommon.TwitterApiInfo.AccessLimit.Clear(); } }
public void GaugeBoundsTest() { using (var toolStrip = new TestToolStripAPIGauge()) { toolStrip.AutoSize = false; toolStrip.Size = new Size(100, 10); toolStrip.GaugeHeight = 5; // toolStrip.ApiLimit の初期値は null Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds); Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds); toolStrip.ApiLimit = new ApiLimit(150, 60, Clock.Now.AddMinutes(15)); Assert.Equal(new Rectangle(0, 0, 40, 5), toolStrip.apiGaugeBounds); // 40% (60/150) Assert.Equal(new Rectangle(0, 5, 25, 5), toolStrip.timeGaugeBounds); // 25% (15/60) toolStrip.ApiLimit = null; Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds); Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds); } }