Version 3.0.338

This commit is contained in:
Anja Müller-Meißner 2022-09-06 16:08:19 +02:00 committed by Anja
parent 573fe77e12
commit 0468955d49
751 changed files with 62747 additions and 60672 deletions

View file

@ -6,25 +6,25 @@ using TINK.Model.State;
namespace TestTINKLib
{
[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");
[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.AreEqual(
new DateTime(2017, 09, 20, 23, 05, 0),
l_oBookedInfo.From);
Assert.AreEqual(
new DateTime(2017, 09, 20, 23, 05, 0),
l_oBookedInfo.From);
Assert.AreEqual(
"Heinz@mueller",
l_oBookedInfo.MailAddress);
Assert.AreEqual(
"Heinz@mueller",
l_oBookedInfo.MailAddress);
Assert.AreEqual(
"17 xxb",
l_oBookedInfo.Code);
}
}
Assert.AreEqual(
"17 xxb",
l_oBookedInfo.Code);
}
}
}

View file

@ -5,13 +5,13 @@ using TINK.Model.State;
namespace TestTINKLib
{
[TestFixture]
public class TestStateDisposableInfo
{
[Test]
public void TestConstruct()
{
Assert.AreEqual(InUseStateEnum.Disposable, new StateAvailableInfo().Value);
}
}
[TestFixture]
public class TestStateDisposableInfo
{
[Test]
public void TestConstruct()
{
Assert.AreEqual(InUseStateEnum.Disposable, new StateAvailableInfo().Value);
}
}
}

View file

@ -8,181 +8,181 @@ using TINK.Model.State;
namespace TestTINKLib
{
[TestFixture]
public class TestStateInfo
{
[Test]
public void TestConstruct()
{
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 20, 23, 20, 0));
[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.AreEqual(InUseStateEnum.Disposable, l_oInUseState.Value, "Default state is available");
Assert.AreEqual("Disposable", l_oInUseState.ToString());
Assert.IsNull(l_oInUseState.RemainingTime);
Assert.IsNull(l_oInUseState.From);
Assert.IsNull(l_oInUseState.Code);
}
// Verify initial values of properties.
Assert.AreEqual(InUseStateEnum.Disposable, l_oInUseState.Value, "Default state is available");
Assert.AreEqual("Disposable", l_oInUseState.ToString());
Assert.IsNull(l_oInUseState.RemainingTime);
Assert.IsNull(l_oInUseState.From);
Assert.IsNull(l_oInUseState.Code);
}
[Test]
public void TestConstructCopy()
{
// State is available.
var l_oSource = MockRepository.GenerateStub<IStateInfo>();
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Disposable);
[Test]
public void TestConstructCopy()
{
// State is available.
var l_oSource = MockRepository.GenerateStub<IStateInfo>();
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Disposable);
var l_oState = new StateInfoMutable(state: l_oSource);
var l_oState = new StateInfoMutable(state: l_oSource);
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
Assert.IsNull(l_oState.RemainingTime);
Assert.IsNull(l_oState.From);
Assert.IsNull(l_oState.Code);
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
Assert.IsNull(l_oState.RemainingTime);
Assert.IsNull(l_oState.From);
Assert.IsNull(l_oState.Code);
// State is requested.
l_oSource = MockRepository.GenerateStub<IStateInfo>();
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Reserved);
l_oSource.Stub(x => x.From).Return(new DateTime(2018, 1, 4, 17, 26, 0));
l_oSource.Stub(x => x.MailAddress).Return("who@the");
l_oSource.Stub(x => x.Code).Return("323");
// State is requested.
l_oSource = MockRepository.GenerateStub<IStateInfo>();
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Reserved);
l_oSource.Stub(x => x.From).Return(new DateTime(2018, 1, 4, 17, 26, 0));
l_oSource.Stub(x => x.MailAddress).Return("who@the");
l_oSource.Stub(x => x.Code).Return("323");
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
Assert.AreEqual(InUseStateEnum.Reserved, l_oState.Value);
Assert.AreEqual(new TimeSpan(0, 10, 59), l_oState.RemainingTime);
Assert.AreEqual(new DateTime(2018, 1, 4, 17, 26, 0), l_oState.From);
Assert.AreEqual("who@the", l_oState.MailAddress);
Assert.AreEqual("323", l_oState.Code);
Assert.AreEqual(InUseStateEnum.Reserved, l_oState.Value);
Assert.AreEqual(new TimeSpan(0, 10, 59), l_oState.RemainingTime);
Assert.AreEqual(new DateTime(2018, 1, 4, 17, 26, 0), l_oState.From);
Assert.AreEqual("who@the", l_oState.MailAddress);
Assert.AreEqual("323", l_oState.Code);
// State is booked.
l_oSource = MockRepository.GenerateStub<IStateInfo>();
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Booked);
l_oSource.Stub(x => x.From).Return(new DateTime(2018, 1, 4, 17, 00, 0));
l_oSource.Stub(x => x.MailAddress).Return("who@the");
l_oSource.Stub(x => x.Code).Return("323");
// State is booked.
l_oSource = MockRepository.GenerateStub<IStateInfo>();
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Booked);
l_oSource.Stub(x => x.From).Return(new DateTime(2018, 1, 4, 17, 00, 0));
l_oSource.Stub(x => x.MailAddress).Return("who@the");
l_oSource.Stub(x => x.Code).Return("323");
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
Assert.AreEqual(InUseStateEnum.Booked, l_oState.Value);
Assert.IsNull(l_oState.RemainingTime);
Assert.AreEqual(new DateTime(2018, 1, 4, 17, 00, 0), l_oState.From);
Assert.AreEqual("who@the", l_oState.MailAddress);
Assert.AreEqual("323", l_oState.Code);
}
Assert.AreEqual(InUseStateEnum.Booked, l_oState.Value);
Assert.IsNull(l_oState.RemainingTime);
Assert.AreEqual(new DateTime(2018, 1, 4, 17, 00, 0), l_oState.From);
Assert.AreEqual("who@the", l_oState.MailAddress);
Assert.AreEqual("323", l_oState.Code);
}
[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
[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);
var l_oStateInfo = new StateInfoMutable(l_oDateTimeMock.GetDateTime);
// Update state from Copri.
l_oStateInfo.Load(
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
l_oDateTimeMock.GetDateTime(),
"heiz@mustermann"); // Owner from Copri.
// Update state from Copri.
l_oStateInfo.Load(
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
l_oDateTimeMock.GetDateTime(),
"heiz@mustermann"); // Owner from Copri.
// Invoke first update (after simulated 4mns)
l_oStateInfo.UpdateOnTimeElapsed();
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateInfo.Value);
Assert.AreEqual(11, l_oStateInfo.RemainingTime.Value.Minutes);
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oStateInfo.From.Value);
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
Assert.IsNull(l_oStateInfo.Code);
// Invoke first update (after simulated 4mns)
l_oStateInfo.UpdateOnTimeElapsed();
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateInfo.Value);
Assert.AreEqual(11, l_oStateInfo.RemainingTime.Value.Minutes);
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oStateInfo.From.Value);
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
Assert.IsNull(l_oStateInfo.Code);
// Invoke second update (after simulated 16 mns)
l_oStateInfo.UpdateOnTimeElapsed();
Assert.AreEqual(InUseStateEnum.Disposable, l_oStateInfo.Value);
Assert.IsNull(l_oStateInfo.RemainingTime);
Assert.IsNull(l_oStateInfo.From);
Assert.IsNull(l_oStateInfo.MailAddress);
Assert.IsNull(l_oStateInfo.Code);
}
// Invoke second update (after simulated 16 mns)
l_oStateInfo.UpdateOnTimeElapsed();
Assert.AreEqual(InUseStateEnum.Disposable, l_oStateInfo.Value);
Assert.IsNull(l_oStateInfo.RemainingTime);
Assert.IsNull(l_oStateInfo.From);
Assert.IsNull(l_oStateInfo.MailAddress);
Assert.IsNull(l_oStateInfo.Code);
}
[Test]
public void TestUpdateFromWebserver()
{
Func<DateTime> l_oNowMock = () => new DateTime(2017, 09, 21, 23, 40, 0);
var l_oStateInfo = new StateInfoMutable(l_oNowMock);
[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), "heiz@mustermann", "21");
l_oStateInfo.Load(InUseStateEnum.Booked, new DateTime(2017, 09, 21, 23, 30, 0), "heiz@mustermann", "21");
Assert.AreEqual(InUseStateEnum.Booked, l_oStateInfo.Value);
Assert.AreEqual("Booked", l_oStateInfo.ToString());
Assert.IsNull(l_oStateInfo.RemainingTime);
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 30, 0), l_oStateInfo.From.Value);
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
Assert.AreEqual("21", l_oStateInfo.Code);
Assert.AreEqual(InUseStateEnum.Booked, l_oStateInfo.Value);
Assert.AreEqual("Booked", l_oStateInfo.ToString());
Assert.IsNull(l_oStateInfo.RemainingTime);
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 30, 0), l_oStateInfo.From.Value);
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
Assert.AreEqual("21", l_oStateInfo.Code);
DateTime FROM = new DateTime(2017, 09, 21, 23, 35, 0);
l_oStateInfo.Load(InUseStateEnum.Reserved, FROM, "heiz@mustermann", "22");
DateTime FROM = new DateTime(2017, 09, 21, 23, 35, 0);
l_oStateInfo.Load(InUseStateEnum.Reserved, FROM, "heiz@mustermann", "22");
// Verify initial values of properties.
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateInfo.Value);
Assert.AreEqual("Reserved", l_oStateInfo.ToString());
Assert.AreEqual(new TimeSpan(0, 15, 0).Subtract(l_oNowMock().Subtract(FROM)).Minutes, l_oStateInfo.RemainingTime.Value.Minutes);
Assert.AreEqual(FROM, l_oStateInfo.From);
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
Assert.AreEqual("22", l_oStateInfo.Code);
// Verify initial values of properties.
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateInfo.Value);
Assert.AreEqual("Reserved", l_oStateInfo.ToString());
Assert.AreEqual(new TimeSpan(0, 15, 0).Subtract(l_oNowMock().Subtract(FROM)).Minutes, l_oStateInfo.RemainingTime.Value.Minutes);
Assert.AreEqual(FROM, l_oStateInfo.From);
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
Assert.AreEqual("22", l_oStateInfo.Code);
l_oStateInfo.Load(InUseStateEnum.Disposable, new DateTime(1970, 1, 1, 0, 0, 0), "heiz@mustermann", "unused");
l_oStateInfo.Load(InUseStateEnum.Disposable, new DateTime(1970, 1, 1, 0, 0, 0), "heiz@mustermann", "unused");
// Verify initial values of properties.
Assert.AreEqual(InUseStateEnum.Disposable, l_oStateInfo.Value);
Assert.AreEqual("Disposable", l_oStateInfo.ToString());
Assert.IsNull(l_oStateInfo.RemainingTime);
Assert.IsNull(l_oStateInfo.From);
Assert.IsNull(l_oStateInfo.MailAddress);
Assert.IsNull(l_oStateInfo.Code);
}
// Verify initial values of properties.
Assert.AreEqual(InUseStateEnum.Disposable, l_oStateInfo.Value);
Assert.AreEqual("Disposable", l_oStateInfo.ToString());
Assert.IsNull(l_oStateInfo.RemainingTime);
Assert.IsNull(l_oStateInfo.From);
Assert.IsNull(l_oStateInfo.MailAddress);
Assert.IsNull(l_oStateInfo.Code);
}
[Test]
public void TestLoad()
{
var l_oState = new StateInfoMutable(
() => new DateTime(2018, 01, 03, 21, 14, 0)); // Now
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
Assert.IsNull(l_oState.From);
Assert.IsNull(l_oState.RemainingTime);
Assert.IsNull(l_oState.MailAddress);
Assert.IsNull(l_oState.Code);
[Test]
public void TestLoad()
{
var l_oState = new StateInfoMutable(
() => new DateTime(2018, 01, 03, 21, 14, 0)); // Now
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
Assert.IsNull(l_oState.From);
Assert.IsNull(l_oState.RemainingTime);
Assert.IsNull(l_oState.MailAddress);
Assert.IsNull(l_oState.Code);
// 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
"a@b",
"123");
l_oState.Load(l_oSource);
Assert.AreEqual(InUseStateEnum.Reserved, l_oState.Value);
Assert.AreEqual(new DateTime(2018, 01, 03, 21, 13, 0), l_oState.From);
Assert.AreEqual(14, l_oState.RemainingTime.Value.Minutes);
Assert.AreEqual("a@b", l_oState.MailAddress);
Assert.AreEqual("123", l_oState.Code);
// 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
"a@b",
"123");
l_oState.Load(l_oSource);
Assert.AreEqual(InUseStateEnum.Reserved, l_oState.Value);
Assert.AreEqual(new DateTime(2018, 01, 03, 21, 13, 0), l_oState.From);
Assert.AreEqual(14, l_oState.RemainingTime.Value.Minutes);
Assert.AreEqual("a@b", l_oState.MailAddress);
Assert.AreEqual("123", l_oState.Code);
// 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.AreEqual(InUseStateEnum.Booked, l_oState.Value);
Assert.AreEqual(new DateTime(2018, 01, 03, 21, 37, 0), l_oState.From);
Assert.IsNull(l_oState.RemainingTime);
Assert.AreEqual("a@b", l_oState.MailAddress);
Assert.AreEqual("123", l_oState.Code);
// 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.AreEqual(InUseStateEnum.Booked, l_oState.Value);
Assert.AreEqual(new DateTime(2018, 01, 03, 21, 37, 0), l_oState.From);
Assert.IsNull(l_oState.RemainingTime);
Assert.AreEqual("a@b", l_oState.MailAddress);
Assert.AreEqual("123", l_oState.Code);
// Construct disposable object
l_oSource = new StateInfo();
l_oState.Load(l_oSource);
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
Assert.IsNull(l_oState.From);
Assert.IsNull(l_oState.RemainingTime);
Assert.IsNull(l_oState.MailAddress);
Assert.IsNull(l_oState.Code);
}
}
// Construct disposable object
l_oSource = new StateInfo();
l_oState.Load(l_oSource);
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
Assert.IsNull(l_oState.From);
Assert.IsNull(l_oState.RemainingTime);
Assert.IsNull(l_oState.MailAddress);
Assert.IsNull(l_oState.Code);
}
}
}

View file

@ -7,70 +7,70 @@ using TINK.Model.State;
namespace TestTINKLib.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));
[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,
});
// Serialize object and verify json
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
const string EXPECTED = @"
const string EXPECTED = @"
{
""StateInfoObject"":
{
""$type"":""TINK.Model.State.StateAvailableInfo, TINKLib""
}
}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
}
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
}
{
// Deserialize object
var l_oInUseStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
{
// Deserialize object
var l_oInUseStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(InUseStateEnum.Disposable, l_oInUseStateTarget.Value);
Assert.AreEqual("Disposable", l_oInUseStateTarget.ToString());
Assert.IsNull(l_oInUseStateTarget.RemainingTime);
Assert.IsNull(l_oInUseStateTarget.From);
Assert.IsNull(l_oInUseStateTarget.MailAddress);
Assert.IsNull(l_oInUseStateTarget.Code);
}
}
[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
);
// Verify state.
Assert.AreEqual(InUseStateEnum.Disposable, l_oInUseStateTarget.Value);
Assert.AreEqual("Disposable", l_oInUseStateTarget.ToString());
Assert.IsNull(l_oInUseStateTarget.RemainingTime);
Assert.IsNull(l_oInUseStateTarget.From);
Assert.IsNull(l_oInUseStateTarget.MailAddress);
Assert.IsNull(l_oInUseStateTarget.Code);
}
}
[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
"heiz@mustermann",
"173"); // Code
l_oInUseState.Load(
InUseStateEnum.Booked,
new DateTime(2017, 11, 18, 23, 19, 0), // Time booked at
"heiz@mustermann",
"173"); // Code
Assert.AreEqual(InUseStateEnum.Booked, l_oInUseState.Value);
Assert.AreEqual("heiz@mustermann", l_oInUseState.MailAddress);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 19, 0), l_oInUseState.From);
Assert.AreEqual("173", l_oInUseState.Code);
Assert.AreEqual(InUseStateEnum.Booked, l_oInUseState.Value);
Assert.AreEqual("heiz@mustermann", l_oInUseState.MailAddress);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 19, 0), l_oInUseState.From);
Assert.AreEqual("173", l_oInUseState.Code);
// Verify json
const string EXPECTED = @"
// Verify json
const string EXPECTED = @"
{
""StateInfoObject"":
{
@ -80,52 +80,52 @@ namespace TestTINKLib.Fixtures.State
}
}";
var l_oDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
var l_oDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED).Replace("\n", string.Empty).Replace("\r", string.Empty),
TestHelper.PrepareXmlForStringCompare(l_oDetected).Replace("\n", string.Empty).Replace("\r", string.Empty));
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED).Replace("\n", string.Empty).Replace("\r", string.Empty),
TestHelper.PrepareXmlForStringCompare(l_oDetected).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.AreEqual(InUseStateEnum.Booked, l_oStateTarget.Value);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 19, 0), l_oInUseState.From);
Assert.AreEqual("heiz@mustermann", l_oStateTarget.MailAddress);
Assert.AreEqual("173", l_oInUseState.Code);
}
// Deserialize object an verify state.
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(InUseStateEnum.Booked, l_oStateTarget.Value);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 19, 0), l_oInUseState.From);
Assert.AreEqual("heiz@mustermann", l_oStateTarget.MailAddress);
Assert.AreEqual("173", l_oInUseState.Code);
}
[Test]
public void TestSerializeJSON_Reserved_NoCode()
{
string l_strJSONDetected;
[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),
"heiz@mustermann");
{
// 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),
"heiz@mustermann");
Assert.AreEqual(InUseStateEnum.Reserved, l_oInUseState.Value);
Assert.AreEqual("heiz@mustermann", l_oInUseState.MailAddress);
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 20, 0), l_oInUseState.From);
Assert.AreEqual(new TimeSpan(0, 15, 0), l_oInUseState.RemainingTime);
Assert.IsNull(l_oInUseState.Code);
Assert.AreEqual(InUseStateEnum.Reserved, l_oInUseState.Value);
Assert.AreEqual("heiz@mustermann", l_oInUseState.MailAddress);
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 20, 0), l_oInUseState.From);
Assert.AreEqual(new TimeSpan(0, 15, 0), l_oInUseState.RemainingTime);
Assert.IsNull(l_oInUseState.Code);
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
// Verify json
const string EXPECTED = @"
// Verify json
const string EXPECTED = @"
{
""StateInfoObject"":
{
@ -135,54 +135,54 @@ namespace TestTINKLib.Fixtures.State
}
}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
}
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.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.AreEqual(InUseStateEnum.Reserved, l_oStateTarget.Value);
Assert.AreEqual("heiz@mustermann", l_oStateTarget.MailAddress);
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 20, 0), l_oStateTarget.From);
Assert.IsNull(l_oStateTarget.RemainingTime, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
Assert.IsNull(l_oStateTarget.Code);
}
}
{
// Deserialize object an verify state.
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateTarget.Value);
Assert.AreEqual("heiz@mustermann", l_oStateTarget.MailAddress);
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 20, 0), l_oStateTarget.From);
Assert.IsNull(l_oStateTarget.RemainingTime, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
Assert.IsNull(l_oStateTarget.Code);
}
}
[Test]
public void TestSerializeJSON_Reserved()
{
string l_strJSONDetected;
[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);
{
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,
"z@C",
"01815A");
DateTime l_oFrom = new DateTime(2017, 11, 18, 23, 18, 0);
l_oInUseState.Load(
InUseStateEnum.Reserved,
l_oFrom,
"z@C",
"01815A");
Assert.AreEqual(InUseStateEnum.Reserved, l_oInUseState.Value);
Assert.AreEqual("z@C", l_oInUseState.MailAddress);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 18, 0), l_oInUseState.From);
Assert.AreEqual((new TimeSpan(0, 15, 0)).Subtract(l_oNow().Subtract(l_oFrom)), l_oInUseState.RemainingTime);
Assert.AreEqual("01815A", l_oInUseState.Code);
Assert.AreEqual(InUseStateEnum.Reserved, l_oInUseState.Value);
Assert.AreEqual("z@C", l_oInUseState.MailAddress);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 18, 0), l_oInUseState.From);
Assert.AreEqual((new TimeSpan(0, 15, 0)).Subtract(l_oNow().Subtract(l_oFrom)), l_oInUseState.RemainingTime);
Assert.AreEqual("01815A", l_oInUseState.Code);
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
NullValueHandling = NullValueHandling.Ignore,
});
// Verify json
const string EXPECTED = @"
// Verify json
const string EXPECTED = @"
{
""StateInfoObject"":
{
@ -193,21 +193,21 @@ namespace TestTINKLib.Fixtures.State
}
}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
}
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.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.AreEqual(InUseStateEnum.Reserved, l_oStateTarget.Value);
Assert.AreEqual("z@C", l_oStateTarget.MailAddress);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 18, 0), l_oStateTarget.From);
Assert.IsNull(l_oStateTarget.RemainingTime, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
Assert.AreEqual("01815A", l_oStateTarget.Code);
}
}
}
{
// Deserialize object an verify state.
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateTarget.Value);
Assert.AreEqual("z@C", l_oStateTarget.MailAddress);
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 18, 0), l_oStateTarget.From);
Assert.IsNull(l_oStateTarget.RemainingTime, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
Assert.AreEqual("01815A", l_oStateTarget.Code);
}
}
}
}

View file

@ -7,84 +7,84 @@ 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);
[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.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.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.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.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);
}
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);
[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(
"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(
"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.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.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);
}
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
[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");
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 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");
}
}
// 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");
}
}
}

View file

@ -7,37 +7,37 @@ using TINK.Model.State;
namespace TestTINKLib.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),
"a@b",
"372");
[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),
"a@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"":""a @b"",""Code"":""372""}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
// 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"":""a @b"",""Code"":""372""}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
// Deserialize object.
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
// Deserialize object.
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
// Verify state.
Assert.AreEqual(InUseStateEnum.Reserved, l_oInfoTarge.Value);
Assert.AreEqual("a@b", l_oInfoTarge.MailAddress);
Assert.AreEqual("372", l_oInfoTarge.Code);
Assert.AreEqual(new DateTime(2017, 9, 19, 0, 0, 0), l_oInfoTarge.From);
}
// Verify state.
Assert.AreEqual(InUseStateEnum.Reserved, l_oInfoTarge.Value);
Assert.AreEqual("a@b", l_oInfoTarge.MailAddress);
Assert.AreEqual("372", l_oInfoTarge.Code);
Assert.AreEqual(new DateTime(2017, 9, 19, 0, 0, 0), l_oInfoTarge.From);
}
}
}
}