mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-25 00:26:27 +01:00
91 lines
3.8 KiB
C#
91 lines
3.8 KiB
C#
|
using NUnit.Framework;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
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? l_oRemainigTime));
|
|||
|
|
|||
|
Assert.AreEqual(
|
|||
|
14,
|
|||
|
l_oRemainigTime.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? l_oRemainigTime));
|
|||
|
|
|||
|
Assert.AreEqual(
|
|||
|
3,
|
|||
|
l_oRemainigTime.Value.Minutes);
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void TestTryUpdateOnTimeElapsed()
|
|||
|
{
|
|||
|
var l_oReservedAt = new DateTime(2017, 09, 20, 22, 01, 00);
|
|||
|
var l_oDateTimeMock = new DateTimeMocker( new List<DateTime> {
|
|||
|
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? l_oRemainigTime));
|
|||
|
Assert.AreEqual(11, l_oRemainigTime.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 l_oRemainigTime));
|
|||
|
Assert.IsNull(l_oRemainigTime);
|
|||
|
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|