--- /dev/null
+// Copyright (C) 2018 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using System;\r
+using System.Linq;\r
+using ExpressionToCodeLib;\r
+using KancolleSniffer.Model;\r
+using Microsoft.VisualStudio.TestTools.UnitTesting;\r
+\r
+namespace KancolleSniffer.Test\r
+{\r
+ [TestClass]\r
+ public class AkashiTimerTest\r
+ {\r
+ private TimeProvider _timeProvider;\r
+ private ShipInventry _shipInventry;\r
+ private ShipInfo _shipInfo;\r
+ private AkashiTimer _akashiTimer;\r
+ private ShipStatus[] _ships;\r
+\r
+ private class TimeProvider\r
+ {\r
+ public DateTime DateTime { set; private get; }\r
+\r
+ public DateTime GetTime() => DateTime;\r
+ }\r
+\r
+ [TestInitialize]\r
+ public void Initialize()\r
+ {\r
+ _timeProvider = new TimeProvider();\r
+ _shipInventry = new ShipInventry();\r
+ _shipInfo = new ShipInfo(null, _shipInventry, new ItemInventry());\r
+ _akashiTimer = new AkashiTimer(_shipInfo, new DockInfo(null, null), null, _timeProvider.GetTime);\r
+ SetupFleet();\r
+ }\r
+\r
+ public void SetupFleet()\r
+ {\r
+ _ships = new[]\r
+ {\r
+ new ShipStatus\r
+ {\r
+ Id = 17160,\r
+ Spec = new ShipSpec {Id = 187, Name = "明石改", ShipType = 19},\r
+ NowHp = 45,\r
+ MaxHp = 45,\r
+ Slot = new[] {26181, 26501, 37732, 28338}\r
+ .Select(id => new ItemStatus(id) {Spec = new ItemSpec {Id = 86, Type = 31}})\r
+ .Concat(new[] {new ItemStatus()}).ToArray()\r
+ },\r
+ new ShipStatus\r
+ {\r
+ Id = 1,\r
+ Spec = new ShipSpec {Id = 237, Name = "電改", ShipType = 2},\r
+ MaxHp = 30,\r
+ NowHp = 30,\r
+ Slot = Enumerable.Repeat(new ItemStatus(), 5).ToArray()\r
+ }\r
+ };\r
+ foreach (var ship in _ships)\r
+ _shipInventry[ship.Id] = ship;\r
+ _shipInfo.Fleets[0].Deck = new[] {17160, 1, -1, -1, -1, -1};\r
+ }\r
+\r
+ /// <summary>\r
+ /// 母港\r
+ /// </summary>\r
+ public void Port()\r
+ {\r
+ _timeProvider.DateTime = new DateTime(2018, 1, 1, 0, 0, 0);\r
+ _akashiTimer.Port();\r
+ PAssert.That(\r
+ () => _akashiTimer.GetPresetDeckTimer(new DateTime(2018, 1, 1, 0, 1, 0)) == TimeSpan.FromMinutes(19),\r
+ "母港で開始");\r
+ }\r
+\r
+ /// <summary>\r
+ /// 二番艦を外してリセット\r
+ /// </summary>\r
+ [TestMethod]\r
+ public void WithdrawShip()\r
+ {\r
+ Port();\r
+ _timeProvider.DateTime = new DateTime(2018, 1, 1, 0, 2, 0);\r
+ _shipInfo.Fleets[0].Deck = new[] {17160, -1, -1, -1, -1, -1};\r
+ _akashiTimer.InspectChange("api_id=1&api_ship_idx=0&api_ship_id=-1");\r
+ PAssert.That(\r
+ () => _akashiTimer.GetPresetDeckTimer(new DateTime(2018, 1, 1, 0, 3, 0)) == TimeSpan.FromMinutes(19));\r
+ }\r
+\r
+ /// <summary>\r
+ /// 随伴艦一括解除でリセットしない\r
+ /// </summary>\r
+ [TestMethod]\r
+ public void WithdrawAccompanyingShips()\r
+ {\r
+ Port();\r
+ _timeProvider.DateTime = new DateTime(2018, 1, 1, 0, 2, 0);\r
+ _shipInfo.Fleets[0].Deck = new[] {17160, -1, -1, -1, -1, -1};\r
+ _akashiTimer.InspectChange("api_id=1&api_ship_idx=0&api_ship_id=-2");\r
+ PAssert.That(\r
+ () => _akashiTimer.GetPresetDeckTimer(new DateTime(2018, 1, 1, 0, 3, 0)) == TimeSpan.FromMinutes(17));\r
+ }\r
+ }\r
+}
\ No newline at end of file