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

46 lines
1.4 KiB
C#
Raw Normal View History

2021-05-13 20:09:46 +02:00
using Newtonsoft.Json;
using NUnit.Framework;
using System;
2021-11-14 23:27:29 +01:00
using TestFramework;
2022-01-22 18:28:01 +01:00
using TestShareeLib;
2021-05-13 20:09:46 +02:00
using TINK.Model.State;
2022-01-22 18:16:10 +01:00
namespace TestTINKLib.Fixtures.State
2021-05-13 20:09:46 +02:00
{
2022-01-22 18:16:10 +01:00
2021-05-13 20:09:46 +02:00
[TestFixture]
2022-01-22 18:16:10 +01:00
public class TestStateReInquestedfoSerializeJSON
2021-05-13 20:09:46 +02:00
{
[Test]
public void TestSerializeJSON()
{
// Create object to test.
2022-01-22 18:16:10 +01:00
var l_oReservedInfo = new StateRequestedInfo(
() => new DateTime(2017, 09, 20),
new DateTime(2017, 09, 19),
"a@b",
"372");
2021-05-13 20:09:46 +02:00
2022-01-22 18:16:10 +01:00
// Serialize object
2021-05-13 20:09:46 +02:00
// Serialize object and verify.
2022-01-22 18:16:10 +01:00
var l_oDetected = JsonConvert.SerializeObject(l_oReservedInfo);
// Verify xml
const string EXPECTED = @"{""From"":""2017 - 09 - 19T00: 00:00"",""MailAddress"":""a @b"",""Code"":""372""}";
2021-05-13 20:09:46 +02:00
Assert.AreEqual(
2022-01-22 18:16:10 +01:00
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
// Deserialize object.
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
2021-05-13 20:09:46 +02:00
2022-01-22 18:16:10 +01:00
// 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);
2021-05-13 20:09:46 +02:00
}
2022-01-22 18:16:10 +01:00
2021-05-13 20:09:46 +02:00
}
}