using System; using System.Collections.Generic; using NUnit.Framework; using TINK.Model.State; namespace TestTINKLib { [TestFixture] public class TestStateRequestedInfo { [Test] public void TestConstruct_FromApp() { Assert.AreEqual( InUseStateEnum.Reserved, new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).Value); Assert.AreEqual( "a@b", new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).MailAddress); Assert.IsNull( new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).Code); Assert.AreEqual( new DateTime(2017, 09, 20, 12, 0, 0), new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).From); Assert.IsTrue( new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).GetIsStillReserved(out TimeSpan? remainingTime)); Assert.AreEqual( 14, remainingTime.Value.Minutes); } [Test] public void TestConstruct_FromWebserver() { Assert.AreEqual( InUseStateEnum.Reserved, new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").Value); Assert.AreEqual( "a@b", new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").MailAddress); Assert.AreEqual( "372", new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").Code); Assert.AreEqual( new DateTime(2017, 09, 19), new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").From); Assert.IsTrue( new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 12, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", "372").GetIsStillReserved(out TimeSpan? remainingTime)); Assert.AreEqual( 3, remainingTime.Value.Minutes); } [Test] public void TestTryUpdateOnTimeElapsed() { var l_oReservedAt = new DateTime(2017, 09, 20, 22, 01, 00); var l_oDateTimeMock = new DateTimeMocker(new List { l_oReservedAt.Add(new TimeSpan(0, 4, 0)), // Reserved for 4 mns l_oReservedAt.Add(new TimeSpan(0, 16, 0)) // Time elapsed since booking 16 mns }); var l_oReservedInfo = new StateRequestedInfo(l_oDateTimeMock.GetDateTime, l_oReservedAt, "a@b", null); Assert.AreEqual("a@b", l_oReservedInfo.MailAddress); Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b"); // Invoke first update (after simulated 4mns) Assert.IsTrue(l_oReservedInfo.GetIsStillReserved(out TimeSpan? remainingTime)); Assert.AreEqual(11, remainingTime.Value.Minutes); Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b"); // Invoke second update (after simulated 16 mns) Assert.IsFalse(l_oReservedInfo.GetIsStillReserved(out remainingTime)); Assert.IsNull(remainingTime); Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b"); } } }