sharee.bike-App/SharedBusinessLogic.Tests/Model/State/TestStateBookedInfoSerializeJSON.cs
2024-04-09 12:53:23 +02:00

43 lines
1.4 KiB
C#

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)));
}
}
}