Version 3.0.381

This commit is contained in:
Anja 2024-04-09 12:53:23 +02:00
parent f963c0a219
commit 3a363acf3a
1525 changed files with 60589 additions and 125098 deletions

View file

@ -0,0 +1,27 @@
using System;
using NUnit.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests
{
[TestFixture]
public class TestStateBookedInfo
{
[Test]
public void TestConstruct()
{
var l_oBookedInfo = new StateOccupiedInfo(new DateTime(2017, 09, 20, 23, 05, 0), "Heinz@mueller", "17 xxb");
Assert.That(
l_oBookedInfo.From, Is.EqualTo(new DateTime(2017, 09, 20, 23, 05, 0)));
Assert.That(
l_oBookedInfo.MailAddress, Is.EqualTo("Heinz@mueller"));
Assert.That(
l_oBookedInfo.Code, Is.EqualTo("17 xxb"));
}
}
}

View file

@ -0,0 +1,43 @@
using System;
using Newtonsoft.Json;
using NUnit.Framework;
using SharedBusinessLogic.Tests.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests.Fixtures.Bike
{
[TestFixture]
public class TestStateBookedInfoSerializeJSON
{
[Test]
public void TestSerializeJSON()
{
// Create object to test.
var l_oInfoSource = new StateOccupiedInfo(
new DateTime(2017, 09, 20, 23, 05, 0),
"Heinz@mueller",
"17 xxb");
// Serialize object and verify.
var l_oDetected = JsonConvert.SerializeObject(l_oInfoSource);
const string EXPECTED = @"
{
""From"":""2017 - 09 - 20T23: 05:00"",
""MailAddress"":""Heinz@mueller"",
""Code"":""17 xxb""
}";
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_oDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty))));
// Deserialize object and verify.
var l_oInfoTarget = JsonConvert.DeserializeObject<StateOccupiedInfo>(l_oDetected);
Assert.That(l_oInfoTarget.Value, Is.EqualTo(InUseStateEnum.Booked));
Assert.That(l_oInfoTarget.MailAddress, Is.EqualTo("Heinz@mueller"));
Assert.That(l_oInfoTarget.Code, Is.EqualTo("17 xxb"));
Assert.That(l_oInfoTarget.From, Is.EqualTo(new DateTime(2017, 9, 20, 23, 5, 0)));
}
}
}

View file

@ -0,0 +1,17 @@
using NUnit.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests
{
[TestFixture]
public class TestStateDisposableInfo
{
[Test]
public void TestConstruct()
{
Assert.That(new StateAvailableInfo().Value, Is.EqualTo(InUseStateEnum.Disposable));
}
}
}

View file

@ -0,0 +1,237 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests
{
[TestFixture]
public class TestStateInfo
{
[Test]
public void TestConstruct()
{
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 20, 23, 20, 0));
// Verify initial values of properties.
Assert.That(l_oInUseState.Value, Is.EqualTo(InUseStateEnum.Disposable), "Default state is available");
Assert.That(l_oInUseState.ToString(), Is.EqualTo("Disposable"));
Assert.That(l_oInUseState.RemainingTime, Is.Null);
Assert.That(l_oInUseState.From, Is.Null);
Assert.That(l_oInUseState.Code, Is.Null);
}
[Test]
public void TestConstructCopy()
{
// State is available.
var l_oSource = Substitute.For<IStateInfo>();
l_oSource.Value.Returns(InUseStateEnum.Disposable);
var l_oState = new StateInfoMutable(state: l_oSource);
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oState.RemainingTime, Is.Null);
Assert.That(l_oState.From, Is.Null);
Assert.That(l_oState.Code, Is.Null);
// State is requested.
l_oSource = Substitute.For<IStateInfo>();
l_oSource.Value.Returns(InUseStateEnum.Reserved);
l_oSource.From.Returns(new DateTime(2018, 1, 4, 17, 26, 0));
l_oSource.MailAddress.Returns("who@the");
l_oSource.Code.Returns("323");
l_oSource.MaxReservationTimeSpan.Returns(TimeSpan.FromMinutes(15));
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oState.RemainingTime, Is.EqualTo(new TimeSpan(0, 10, 59)));
Assert.That(l_oState.From, Is.EqualTo(new DateTime(2018, 1, 4, 17, 26, 0)));
Assert.That(l_oState.MailAddress, Is.EqualTo("who@the"));
Assert.That(l_oState.Code, Is.EqualTo("323"));
// State is booked.
l_oSource = Substitute.For<IStateInfo>();
l_oSource.Value.Returns(InUseStateEnum.Booked);
l_oSource.From.Returns(new DateTime(2018, 1, 4, 17, 00, 0));
l_oSource.MailAddress.Returns("who@the");
l_oSource.Code.Returns("323");
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Booked));
Assert.That(l_oState.RemainingTime, Is.Null);
Assert.That(l_oState.From, Is.EqualTo(new DateTime(2018, 1, 4, 17, 00, 0)));
Assert.That(l_oState.MailAddress, Is.EqualTo("who@the"));
Assert.That(l_oState.Code, Is.EqualTo("323"));
}
[Test]
public void TestDoUpdate()
{
var l_oReservedAt = new DateTime(2017, 09, 20, 22, 01, 00);
var l_oDateTimeMock = new DateTimeMocker(new List<DateTime> {
l_oReservedAt, // Booking time
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_oStateInfo = new StateInfoMutable(l_oDateTimeMock.GetDateTime);
// Update state from Copri.
l_oStateInfo.Load(
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
l_oDateTimeMock.GetDateTime(),
TimeSpan.FromMinutes(15),
"heiz@mustermann"); // Owner from Copri.
// Invoke first update (after simulated 4mns)
l_oStateInfo.UpdateOnTimeElapsed();
Assert.That(l_oStateInfo.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oStateInfo.RemainingTime.Value.Minutes, Is.EqualTo(11));
Assert.That(l_oStateInfo.From.Value, Is.EqualTo(new DateTime(2017, 09, 20, 22, 01, 00)));
Assert.That(l_oStateInfo.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oStateInfo.Code, Is.Null);
// Invoke second update (after simulated 16 mns)
l_oStateInfo.UpdateOnTimeElapsed();
Assert.That(l_oStateInfo.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oStateInfo.RemainingTime, Is.Null);
Assert.That(l_oStateInfo.From, Is.Null);
Assert.That(l_oStateInfo.MailAddress, Is.Null);
Assert.That(l_oStateInfo.Code, Is.Null);
}
[Test]
public void TestUpdateFromWebserver()
{
Func<DateTime> l_oNowMock = () => new DateTime(2017, 09, 21, 23, 40, 0);
var l_oStateInfo = new StateInfoMutable(l_oNowMock);
l_oStateInfo.Load(InUseStateEnum.Booked, new DateTime(2017, 09, 21, 23, 30, 0), TimeSpan.FromMinutes(15), "heiz@mustermann", "21");
Assert.That(l_oStateInfo.Value, Is.EqualTo(InUseStateEnum.Booked));
Assert.That(l_oStateInfo.ToString(), Is.EqualTo("Booked"));
Assert.That(l_oStateInfo.RemainingTime, Is.Null);
Assert.That(l_oStateInfo.From.Value, Is.EqualTo(new DateTime(2017, 09, 21, 23, 30, 0)));
Assert.That(l_oStateInfo.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oStateInfo.Code, Is.EqualTo("21"));
DateTime FROM = new DateTime(2017, 09, 21, 23, 35, 0);
l_oStateInfo.Load(InUseStateEnum.Reserved, FROM, TimeSpan.FromMinutes(15), "heiz@mustermann", "22");
// Verify initial values of properties.
Assert.That(l_oStateInfo.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oStateInfo.ToString(), Is.EqualTo("Reserved"));
Assert.That(l_oStateInfo.RemainingTime.Value.Minutes, Is.EqualTo(new TimeSpan(0, 15, 0).Subtract(l_oNowMock().Subtract(FROM)).Minutes));
Assert.That(l_oStateInfo.From, Is.EqualTo(FROM));
Assert.That(l_oStateInfo.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oStateInfo.Code, Is.EqualTo("22"));
l_oStateInfo.Load(InUseStateEnum.Disposable, new DateTime(1970, 1, 1, 0, 0, 0), TimeSpan.FromMinutes(15), "heiz@mustermann", "unused");
// Verify initial values of properties.
Assert.That(l_oStateInfo.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oStateInfo.ToString(), Is.EqualTo("Disposable"));
Assert.That(l_oStateInfo.RemainingTime, Is.Null);
Assert.That(l_oStateInfo.From, Is.Null);
Assert.That(l_oStateInfo.MailAddress, Is.Null);
Assert.That(l_oStateInfo.Code, Is.Null);
}
[Test]
public void TestLoad()
{
var l_oState = new StateInfoMutable(
() => new DateTime(2018, 01, 03, 21, 14, 0)); // Now
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oState.From, Is.Null);
Assert.That(l_oState.RemainingTime, Is.Null);
Assert.That(l_oState.MailAddress, Is.Null);
Assert.That(l_oState.Code, Is.Null);
// Construct requested state object.
var l_oSource = new StateInfo(
() => new DateTime(2018, 01, 03, 21, 53, 0),
new DateTime(2018, 01, 03, 21, 13, 0), // Requested from
TimeSpan.FromMinutes(15),
"a@b",
"123");
l_oState.Load(l_oSource);
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oState.From, Is.EqualTo(new DateTime(2018, 01, 03, 21, 13, 0)));
Assert.That(l_oState.RemainingTime.Value.Minutes, Is.EqualTo(14));
Assert.That(l_oState.MailAddress, Is.EqualTo("a@b"));
Assert.That(l_oState.Code, Is.EqualTo("123"));
// Construct booked state object.
l_oSource = new StateInfo(new DateTime(2018, 01, 03, 21, 37, 0), "a@b", "123");
l_oState.Load(l_oSource);
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Booked));
Assert.That(l_oState.From, Is.EqualTo(new DateTime(2018, 01, 03, 21, 37, 0)));
Assert.That(l_oState.RemainingTime, Is.Null);
Assert.That(l_oState.MailAddress, Is.EqualTo("a@b"));
Assert.That(l_oState.Code, Is.EqualTo("123"));
// Construct disposable object
l_oSource = new StateInfo();
l_oState.Load(l_oSource);
Assert.That(l_oState.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oState.From, Is.Null);
Assert.That(l_oState.RemainingTime, Is.Null);
Assert.That(l_oState.MailAddress, Is.Null);
Assert.That(l_oState.Code, Is.Null);
}
[Test]
public void TestLoadFromNull()
{
var state = new StateInfoMutable(
() => new DateTime(2018, 01, 03, 21, 14, 0));
state.Load(InUseStateEnum.Disposable,
null,
TimeSpan.FromMinutes(15));
Assert.That(
state.RemainingTime,
Is.Null);
}
[Test]
public void TestLoadReservationTimeSpanNull()
{
var state = new StateInfoMutable(
() => new DateTime(2018, 01, 03, 21, 14, 0));
state.Load(InUseStateEnum.Disposable,
DateTime.Now,
null);
Assert.That(
state.RemainingTime,
Is.Null);
}
[Test]
public void TestMaxReservationTimeSpanNullStateAvaialble()
=> Assert.That(new StateInfo().MaxReservationTimeSpan, Is.Null);
[Test]
public void TestMaxReservationTimeSpanNullStateFeedbackPending()
=> Assert.That(new StateInfo(true).MaxReservationTimeSpan, Is.Null);
[Test]
public void TestMaxReservationTimeSpanNullStateOccupied()
=> Assert.That(new StateInfo(new DateTime(2023, 5, 11), "a@b", "").MaxReservationTimeSpan, Is.Null);
[Test]
public void TestMaxReservationTimeSpan()
=> Assert.That(new StateInfo(() => DateTime.Now, new DateTime(2023, 5, 11), TimeSpan.FromMinutes(12), "a@b", "").MaxReservationTimeSpan, Is.EqualTo(TimeSpan.FromMinutes(12)));
}
}

View file

@ -0,0 +1,212 @@
using System;
using Newtonsoft.Json;
using NUnit.Framework;
using SharedBusinessLogic.Tests.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests.Fixtures.State
{
[TestFixture]
public class TestStateInfoSerializeJSON
{
[Test]
public void TestSerializeJSON_Disposable()
{
string l_strJSONDetected;
{
// Create object to test.
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 20, 23, 20, 0));
// Serialize object and verify json
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
const string EXPECTED = @"
{
""StateInfoObject"":
{
""$type"":""ShareeBike.Model.State.StateAvailableInfo, SharedBusinessLogic""
}
}";
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty))));
}
{
// Deserialize object
var l_oInUseStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.That(l_oInUseStateTarget.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oInUseStateTarget.ToString(), Is.EqualTo("Disposable"));
Assert.That(l_oInUseStateTarget.RemainingTime, Is.Null);
Assert.That(l_oInUseStateTarget.From, Is.Null);
Assert.That(l_oInUseStateTarget.MailAddress, Is.Null);
Assert.That(l_oInUseStateTarget.Code, Is.Null);
}
}
[Test]
public void TestSerializeJSON_Booked()
{
// Create object to test.
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 11, 18, 23, 20, 0) // Mocked time stamp returned when StateInfo- object is crated
);
l_oInUseState.Load(
InUseStateEnum.Booked,
new DateTime(2017, 11, 18, 23, 19, 0), // Time booked at
TimeSpan.FromMinutes(15),
"heiz@mustermann",
"173"); // Code
Assert.That(l_oInUseState.Value, Is.EqualTo(InUseStateEnum.Booked));
Assert.That(l_oInUseState.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oInUseState.From, Is.EqualTo(new DateTime(2017, 11, 18, 23, 19, 0)));
Assert.That(l_oInUseState.Code, Is.EqualTo("173"));
// Verify json
const string EXPECTED = @"
{
""StateInfoObject"":
{
""$type"":""ShareeBike.Model.State.StateOccupiedInfo, SharedBusinessLogic"",
""From"":""2017 - 11 - 18T23: 19:00"",
""MailAddress"":""heiz @mustermann"",""Code"":""173""
}
}";
var l_oDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_oDetected).Replace("\n", string.Empty).Replace("\r", string.Empty), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED).Replace("\n", string.Empty).Replace("\r", string.Empty)));
// Deserialize object an verify state.
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.That(l_oStateTarget.Value, Is.EqualTo(InUseStateEnum.Booked));
Assert.That(l_oInUseState.From, Is.EqualTo(new DateTime(2017, 11, 18, 23, 19, 0)));
Assert.That(l_oStateTarget.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oInUseState.Code, Is.EqualTo("173"));
}
[Test]
public void TestSerializeJSON_Reserved_NoCode()
{
string l_strJSONDetected;
{
// Create object to test.
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 21, 23, 20, 0));
l_oInUseState.Load(
InUseStateEnum.Reserved,
new DateTime(2017, 09, 21, 23, 20, 0),
TimeSpan.FromMinutes(15),
"heiz@mustermann");
Assert.That(l_oInUseState.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oInUseState.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oInUseState.From, Is.EqualTo(new DateTime(2017, 09, 21, 23, 20, 0)));
Assert.That(l_oInUseState.RemainingTime, Is.EqualTo(new TimeSpan(0, 15, 0)));
Assert.That(l_oInUseState.Code, Is.Null);
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
// Verify json
const string EXPECTED = @"
{
""StateInfoObject"":
{
""$type"":""ShareeBike.Model.State.StateRequestedInfo, SharedBusinessLogic"",
""From"":""2017 - 09 - 21T23: 20:00"",
""MailAddress"":""heiz @mustermann""
}
}";
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty))));
}
{
// Deserialize object an verify state.
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.That(l_oStateTarget.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oStateTarget.MailAddress, Is.EqualTo("heiz@mustermann"));
Assert.That(l_oStateTarget.From, Is.EqualTo(new DateTime(2017, 09, 21, 23, 20, 0)));
Assert.That(l_oStateTarget.RemainingTime, Is.Null, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
Assert.That(l_oStateTarget.Code, Is.Null);
}
}
[Test]
public void TestSerializeJSON_Reserved()
{
string l_strJSONDetected;
{
Func<DateTime> l_oNow = () => new DateTime(2017, 11, 18, 23, 18, 0);
// Create object to test.
var l_oInUseState = new StateInfoMutable(l_oNow);
DateTime l_oFrom = new DateTime(2017, 11, 18, 23, 18, 0);
l_oInUseState.Load(
InUseStateEnum.Reserved,
l_oFrom,
TimeSpan.FromMinutes(15),
"z@C",
"01815A");
Assert.That(l_oInUseState.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oInUseState.MailAddress, Is.EqualTo("z@C"));
Assert.That(l_oInUseState.From, Is.EqualTo(new DateTime(2017, 11, 18, 23, 18, 0)));
Assert.That(l_oInUseState.RemainingTime, Is.EqualTo((new TimeSpan(0, 15, 0)).Subtract(l_oNow().Subtract(l_oFrom))));
Assert.That(l_oInUseState.Code, Is.EqualTo("01815A"));
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
// Verify json
const string EXPECTED = @"
{
""StateInfoObject"":
{
""$type"":""ShareeBike.Model.State.StateRequestedInfo, SharedBusinessLogic"",
""From"":""2017 - 11 - 18T23: 18:00"",
""MailAddress"":""z @C"",
""Code"":""01815A""
}
}";
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty))));
}
{
// Deserialize object an verify state.
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.That(l_oStateTarget.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oStateTarget.MailAddress, Is.EqualTo("z@C"));
Assert.That(l_oStateTarget.From, Is.EqualTo(new DateTime(2017, 11, 18, 23, 18, 0)));
Assert.That(l_oStateTarget.RemainingTime, Is.Null, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
Assert.That(l_oStateTarget.Code, Is.EqualTo("01815A"));
}
}
}
}

View file

@ -0,0 +1,115 @@
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);
}
}

View file

@ -0,0 +1,44 @@
using System;
using Newtonsoft.Json;
using NUnit.Framework;
using SharedBusinessLogic.Tests.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests.Fixtures.State
{
[TestFixture]
public class TestStateReInquestedfoSerializeJSON
{
[Test]
public void TestSerializeJSON()
{
// Create object to test.
var l_oReservedInfo = new StateRequestedInfo(
() => new DateTime(2017, 09, 20),
new DateTime(2017, 09, 19),
TimeSpan.FromMinutes(15),
"ä@b",
"372");
// Serialize object
// Serialize object and verify.
var l_oDetected = JsonConvert.SerializeObject(l_oReservedInfo);
// Verify xml
const string EXPECTED = @"{""From"":""2017 - 09 - 19T00: 00:00"",""MailAddress"":""ä @b"",""Code"":""372""}";
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_oDetected), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED)));
// Deserialize object.
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
// Verify state.
Assert.That(l_oInfoTarge.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oInfoTarge.MailAddress, Is.EqualTo("ä@b"));
Assert.That(l_oInfoTarge.Code, Is.EqualTo("372"));
Assert.That(l_oInfoTarge.From, Is.EqualTo(new DateTime(2017, 9, 19, 0, 0, 0)));
}
}
}