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

44 lines
1.3 KiB
C#

using System;
using Newtonsoft.Json;
using NUnit.Framework;
using SharedBusinessLogic.Tests.Framework;
using ShareeBike.Model.State;
namespace SharedBusinessLogic.Tests.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),
TimeSpan.FromMinutes(15),
"ä@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"":""ä @b"",""Code"":""372""}";
Assert.That(
TestHelper.PrepareXmlForStringCompare(l_oDetected), Is.EqualTo(TestHelper.PrepareXmlForStringCompare(EXPECTED)));
// Deserialize object.
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
// Verify state.
Assert.That(l_oInfoTarge.Value, Is.EqualTo(InUseStateEnum.Reserved));
Assert.That(l_oInfoTarge.MailAddress, Is.EqualTo("ä@b"));
Assert.That(l_oInfoTarge.Code, Is.EqualTo("372"));
Assert.That(l_oInfoTarge.From, Is.EqualTo(new DateTime(2017, 9, 19, 0, 0, 0)));
}
}
}