OSDN Git Service

media_idsの連結をstring.Join()を使った処理に書き換え
[opentween/open-tween.git] / OpenTween.Tests / ToolStripAPIGaugeTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System;
23 using System.Collections.Generic;
24 using System.Drawing;
25 using System.Linq;
26 using System.Text;
27 using OpenTween.Api;
28 using Xunit;
29 using Xunit.Extensions;
30
31 namespace OpenTween
32 {
33     public class ToolStripAPIGaugeTest
34     {
35         [Fact]
36         public void GaugeHeightTest()
37         {
38             using (var toolStrip = new ToolStripAPIGauge())
39             {
40                 toolStrip.AutoSize = false;
41                 toolStrip.Size = new Size(100, 10);
42                 toolStrip.ApiLimit = new ApiLimit(150, 150, DateTime.MaxValue);
43
44                 toolStrip.GaugeHeight = 5;
45
46                 Assert.Equal(new Rectangle(0, 0, 100, 5), toolStrip.apiGaugeBounds);
47                 Assert.Equal(new Rectangle(0, 5, 100, 5), toolStrip.timeGaugeBounds);
48
49                 toolStrip.GaugeHeight = 3;
50
51                 Assert.Equal(new Rectangle(0, 2, 100, 3), toolStrip.apiGaugeBounds);
52                 Assert.Equal(new Rectangle(0, 5, 100, 3), toolStrip.timeGaugeBounds);
53
54                 toolStrip.GaugeHeight = 0;
55
56                 Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds);
57                 Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds);
58             }
59         }
60
61         [Fact]
62         public void TextTest()
63         {
64             using (var toolStrip = new ToolStripAPIGauge())
65             {
66                 // toolStrip.ApiLimit の初期値は null
67
68                 Assert.Equal("API ???/???", toolStrip.Text);
69                 Assert.Equal("API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)", toolStrip.ToolTipText);
70
71                 toolStrip.ApiLimit = new ApiLimit(15, 14, DateTime.Now.AddMinutes(15));
72
73                 Assert.Equal("API 14/15", toolStrip.Text);
74                 Assert.Equal("API rest 14/15" + Environment.NewLine + "(reset after 15 minutes)", toolStrip.ToolTipText);
75
76                 toolStrip.ApiLimit = null;
77
78                 Assert.Equal("API ???/???", toolStrip.Text);
79                 Assert.Equal("API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)", toolStrip.ToolTipText);
80             }
81         }
82
83         class TestToolStripAPIGauge : ToolStripAPIGauge
84         {
85             protected override void UpdateRemainMinutes()
86             {
87                 if (this.ApiLimit != null)
88                     // DateTime の代わりに Clock.Now を使用することで FreezeClock 属性の影響を受けるようになる
89                     this.remainMinutes = (this.ApiLimit.AccessLimitResetDate - Clock.Now).TotalMinutes;
90                 else
91                     this.remainMinutes = -1;
92             }
93         }
94
95         [Fact]
96         [FreezeClock]
97         public void GaugeBoundsTest()
98         {
99             using (var toolStrip = new TestToolStripAPIGauge())
100             {
101                 toolStrip.AutoSize = false;
102                 toolStrip.Size = new Size(100, 10);
103                 toolStrip.GaugeHeight = 5;
104
105                 // toolStrip.ApiLimit の初期値は null
106
107                 Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds);
108                 Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds);
109
110                 toolStrip.ApiLimit = new ApiLimit(150, 60, Clock.Now.AddMinutes(15));
111
112                 Assert.Equal(new Rectangle(0, 0, 40, 5), toolStrip.apiGaugeBounds); // 40% (60/150)
113                 Assert.Equal(new Rectangle(0, 5, 25, 5), toolStrip.timeGaugeBounds); // 25% (15/60)
114
115                 toolStrip.ApiLimit = null;
116
117                 Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds);
118                 Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds);
119             }
120         }
121     }
122 }