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

46 lines
1.5 KiB
C#
Raw Permalink 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;
namespace TestTINKLib.Fixtures.Bike
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]
public class TestStateBookedInfoSerializeJSON
2021-05-13 20:09:46 +02:00
{
[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");
2021-05-13 20:09:46 +02:00
// 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""
}";
2021-05-13 20:09:46 +02:00
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)));
2022-01-22 18:16:10 +01:00
// Deserialize object and verify.
var l_oInfoTarget = JsonConvert.DeserializeObject<StateOccupiedInfo>(l_oDetected);
Assert.AreEqual(InUseStateEnum.Booked, l_oInfoTarget.Value);
Assert.AreEqual("Heinz@mueller", l_oInfoTarget.MailAddress);
Assert.AreEqual("17 xxb", l_oInfoTarget.Code);
Assert.AreEqual(new DateTime(2017, 9, 20, 23, 5, 0), l_oInfoTarget.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
}
}