sharee.bike-App/TestShareeLib/Model/State/TestStateRequestedInfoSerializeJSON.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2023-01-18 14:22:51 +01:00
using System;
2022-08-30 15:42:25 +02:00
using Newtonsoft.Json;
2021-07-12 21:31:46 +02:00
using NUnit.Framework;
2023-03-08 13:18:54 +01:00
using TestFramework;
2021-07-12 21:31:46 +02:00
using TINK.Model.State;
namespace TestTINKLib.Fixtures.State
{
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[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),
2023-06-06 12:00:24 +02:00
TimeSpan.FromMinutes(15),
2023-01-18 14:22:51 +01:00
"ä@b",
2022-09-06 16:08:19 +02:00
"372");
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Serialize object
// Serialize object and verify.
var l_oDetected = JsonConvert.SerializeObject(l_oReservedInfo);
// Verify xml
2023-01-18 14:22:51 +01:00
const string EXPECTED = @"{""From"":""2017 - 09 - 19T00: 00:00"",""MailAddress"":""ä @b"",""Code"":""372""}";
2022-09-06 16:08:19 +02:00
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Deserialize object.
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify state.
Assert.AreEqual(InUseStateEnum.Reserved, l_oInfoTarge.Value);
2023-01-18 14:22:51 +01:00
Assert.AreEqual("ä@b", l_oInfoTarge.MailAddress);
2022-09-06 16:08:19 +02:00
Assert.AreEqual("372", l_oInfoTarge.Code);
Assert.AreEqual(new DateTime(2017, 9, 19, 0, 0, 0), l_oInfoTarge.From);
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
}