mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
115 lines
4.7 KiB
C#
115 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using ShareeBike.Model.State;
|
|
|
|
|
|
namespace SharedBusinessLogic.Tests
|
|
{
|
|
|
|
[TestFixture]
|
|
public class TestStateRequestedInfo
|
|
{
|
|
[Test]
|
|
public void TestConstruct_FromApp()
|
|
{
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), TimeSpan.FromMinutes(15), "a@b", null).Value, Is.EqualTo(InUseStateEnum.Reserved));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), TimeSpan.FromMinutes(15), "a@b", null).MailAddress, Is.EqualTo("a@b"));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), TimeSpan.FromMinutes(15), "a@b", null).Code, Is.Null);
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), TimeSpan.FromMinutes(15), "a@b", null).From, Is.EqualTo(new DateTime(2017, 09, 20, 12, 0, 0)));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), TimeSpan.FromMinutes(15), "a@b", null).GetIsStillReserved(out TimeSpan? l_oRemainigTime), Is.True);
|
|
|
|
Assert.That(
|
|
l_oRemainigTime.Value.Minutes, Is.EqualTo(14));
|
|
}
|
|
|
|
[Test]
|
|
public void TestConstruct_FromWebserver()
|
|
{
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), TimeSpan.FromMinutes(15), "a@b", "372").Value, Is.EqualTo(InUseStateEnum.Reserved));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), TimeSpan.FromMinutes(15), "a@b", "372").MailAddress, Is.EqualTo("a@b"));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), TimeSpan.FromMinutes(15), "a@b", "372").Code, Is.EqualTo("372"));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), TimeSpan.FromMinutes(15), "a@b", "372").From, Is.EqualTo(new DateTime(2017, 09, 19)));
|
|
|
|
Assert.That(
|
|
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 12, 0), new DateTime(2017, 09, 20, 12, 0, 0), TimeSpan.FromMinutes(15), "a@b", "372").GetIsStillReserved(out TimeSpan? remainingTime), Is.True);
|
|
|
|
Assert.That(
|
|
remainingTime.Value.Minutes, Is.EqualTo(3));
|
|
}
|
|
|
|
[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, TimeSpan.FromMinutes(15), "a@b", null);
|
|
Assert.That(l_oReservedInfo.MailAddress, Is.EqualTo("a@b"));
|
|
Assert.That(l_oReservedInfo.From, Is.EqualTo(new DateTime(2017, 09, 20, 22, 01, 00)), "a@b");
|
|
|
|
// Invoke first update (after simulated 4mns)
|
|
Assert.That(l_oReservedInfo.GetIsStillReserved(out TimeSpan? remainingTime), Is.True);
|
|
Assert.That(remainingTime.Value.Minutes, Is.EqualTo(11));
|
|
Assert.That(l_oReservedInfo.From, Is.EqualTo(new DateTime(2017, 09, 20, 22, 01, 00)), "a@b");
|
|
|
|
// Invoke second update (after simulated 16 mns)
|
|
Assert.That(l_oReservedInfo.GetIsStillReserved(out remainingTime), Is.False);
|
|
Assert.That(remainingTime, Is.Null);
|
|
Assert.That(l_oReservedInfo.From, Is.EqualTo(new DateTime(2017, 09, 20, 22, 01, 00)), "a@b");
|
|
}
|
|
|
|
[Test]
|
|
public void TestReservationTimeSpanCtor() =>
|
|
Assert.That(new StateRequestedInfo().MaxReservationTimeSpan, Is.EqualTo(TimeSpan.Zero));
|
|
|
|
[Test]
|
|
public void TestGetIsStillReserved() =>
|
|
Assert.That(new StateRequestedInfo(
|
|
() => new DateTime(2023, 5, 11, 14, 42, 0, 100), // one hundred millisecond after bike was reserved
|
|
new DateTime(2023, 5, 11, 14, 42, 0, 0),
|
|
TimeSpan.FromSeconds(1),
|
|
"a@b",
|
|
"").GetIsStillReserved(out _),
|
|
Is.True);
|
|
|
|
[Test]
|
|
public void TestGetIsStillReservedExpired() =>
|
|
Assert.That(new StateRequestedInfo(
|
|
() => new DateTime(2023, 5, 11, 14, 42, 0, 100), // one hundred millisecond after bike was reserved
|
|
new DateTime(2023, 5, 11, 14, 42, 0, 0),
|
|
TimeSpan.FromMilliseconds(50),
|
|
"a@b",
|
|
"").GetIsStillReserved(out _),
|
|
Is.False);
|
|
|
|
[Test]
|
|
public void TestGetIsStillReservedInvalidMaxReservationTimeSpan() =>
|
|
Assert.That(new StateRequestedInfo(
|
|
() => new DateTime(2023, 5, 11, 14, 42, 0, 1), // one hundred millisecond after bike was reserved
|
|
new DateTime(2023, 5, 11, 14, 42, 0, 0),
|
|
TimeSpan.Zero,
|
|
"a@b",
|
|
"").GetIsStillReserved(out _),
|
|
Is.False);
|
|
}
|
|
}
|