OSDN Git Service

連合艦隊表示のときに連合の種類を表示する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer.Test / AkashiTimerTest.cs
1 // Copyright (C) 2018 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System;\r
16 using System.Linq;\r
17 using ExpressionToCodeLib;\r
18 using KancolleSniffer.Model;\r
19 using Microsoft.VisualStudio.TestTools.UnitTesting;\r
20 \r
21 namespace KancolleSniffer.Test\r
22 {\r
23     [TestClass]\r
24     public class AkashiTimerTest\r
25     {\r
26         private TimeProvider _timeProvider;\r
27         private ShipInventory _shipInventory;\r
28         private ShipInfo _shipInfo;\r
29         private AkashiTimer _akashiTimer;\r
30         private ShipStatus[] _ships;\r
31 \r
32         private class TimeProvider\r
33         {\r
34             public DateTime DateTime { set; private get; }\r
35 \r
36             public DateTime GetTime() => DateTime;\r
37         }\r
38 \r
39         [TestInitialize]\r
40         public void Initialize()\r
41         {\r
42             _timeProvider = new TimeProvider();\r
43             _shipInventory = new ShipInventory();\r
44             _shipInfo = new ShipInfo(null, _shipInventory, new ItemInventory());\r
45             _akashiTimer = new AkashiTimer(_shipInfo, new DockInfo(null, null), null, _timeProvider.GetTime);\r
46             SetupFleet();\r
47         }\r
48 \r
49         public void SetupFleet()\r
50         {\r
51             _ships = new[]\r
52             {\r
53                 new ShipStatus\r
54                 {\r
55                     Id = 17160,\r
56                     Spec = new ShipSpec {Id = 187, Name = "明石改", ShipType = 19},\r
57                     NowHp = 45,\r
58                     MaxHp = 45,\r
59                     Slot = new[] {26181, 26501, 37732, 28338}\r
60                         .Select(id => new ItemStatus(id) {Spec = new ItemSpec {Id = 86, Type = 31}})\r
61                         .Concat(new[] {new ItemStatus()}).ToArray()\r
62                 },\r
63                 new ShipStatus\r
64                 {\r
65                     Id = 1,\r
66                     Spec = new ShipSpec {Id = 237, Name = "電改", ShipType = 2},\r
67                     MaxHp = 30,\r
68                     NowHp = 30,\r
69                     Slot = Enumerable.Repeat(new ItemStatus(), 5).ToArray()\r
70                 }\r
71             };\r
72             foreach (var ship in _ships)\r
73                 _shipInventory[ship.Id] = ship;\r
74             _shipInfo.Fleets[0].Deck = new[] {17160, 1, -1, -1, -1, -1};\r
75         }\r
76 \r
77         /// <summary>\r
78         /// 母港\r
79         /// </summary>\r
80         public void Port()\r
81         {\r
82             _timeProvider.DateTime = new DateTime(2018, 1, 1, 0, 0, 0);\r
83             _akashiTimer.Port();\r
84             PAssert.That(\r
85                 () => _akashiTimer.GetPresetDeckTimer(new DateTime(2018, 1, 1, 0, 1, 0)) == TimeSpan.FromMinutes(19),\r
86                 "母港で開始");\r
87         }\r
88 \r
89         /// <summary>\r
90         /// 二番艦を外してリセット\r
91         /// </summary>\r
92         [TestMethod]\r
93         public void WithdrawShip()\r
94         {\r
95             Port();\r
96             _timeProvider.DateTime = new DateTime(2018, 1, 1, 0, 2, 0);\r
97             _shipInfo.Fleets[0].Deck = new[] {17160, -1, -1, -1, -1, -1};\r
98             _akashiTimer.InspectChange("api_id=1&api_ship_idx=0&api_ship_id=-1");\r
99             PAssert.That(\r
100                 () => _akashiTimer.GetPresetDeckTimer(new DateTime(2018, 1, 1, 0, 3, 0)) == TimeSpan.FromMinutes(19));\r
101         }\r
102 \r
103         /// <summary>\r
104         /// 随伴艦一括解除でリセットしない\r
105         /// </summary>\r
106         [TestMethod]\r
107         public void WithdrawAccompanyingShips()\r
108         {\r
109             Port();\r
110             _timeProvider.DateTime = new DateTime(2018, 1, 1, 0, 2, 0);\r
111             _shipInfo.Fleets[0].Deck = new[] {17160, -1, -1, -1, -1, -1};\r
112             _akashiTimer.InspectChange("api_id=1&api_ship_idx=0&api_ship_id=-2");\r
113             PAssert.That(\r
114                 () => _akashiTimer.GetPresetDeckTimer(new DateTime(2018, 1, 1, 0, 3, 0)) == TimeSpan.FromMinutes(17));\r
115         }\r
116     }\r
117 }