sharee.bike-App/TestShareeLib/Repository/TestCopriCallsStatic.cs

87 lines
2.5 KiB
C#
Raw Normal View History

2021-06-26 20:57:55 +02:00
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Repository.Response;
using TINK.Repository;
namespace TestShareeLib.Repository
{
[TestFixture]
public class TestCopriCallsStatic
{
[Test]
public void TestDeserializeResponse_Factory_SupportedVersion()
{
var response = @"
{
""shareejson"" :
{
""copri_version"" : ""4.1.5.7""
}
}";
Assert.That(
response.DeserializeResponse(version => new ResponseBase()).copri_version,
Is.EqualTo("4.1.5.7"));
}
[Test]
public void TestDeserializeResponse_Factory_UnspportedVersion()
{
// Future version
var response = @"
{
""shareejson"" :
{
""copri_version"" : ""4.2.5.7""
}
}";
var factoryObject = JsonConvert.DeserializeObject<ResponseContainer<ResponseBase>>(
@"{
""shareejson"" :
{
""copri_version"" : ""9.9.9.9""
}
}");
Assert.That(
response.DeserializeResponse(version => factoryObject).shareejson.copri_version,
Is.EqualTo("9.9.9.9"));
}
[Test]
public void TestDeserializeResponse_Exception_SupportedVersion()
{
// Future version
var response = @"
{
""shareejson"" :
{
""copri_version"" : ""4.1.5.7""
}
}";
Assert.That(
response.DeserializeResponse<ResponseBase>(version => new System.Exception("hello")).copri_version,
Is.EqualTo("4.1.5.7"),
"No exception must be thrown because version 4.1.x is supported.");
}
[Test]
public void TestDeserializeResponse_Exception_UnspportedVersion()
{
var response = @"
{
""shareejson"" :
{
""copri_version"" : ""4.2.5.7""
}
}";
Assert.That(
() => response.DeserializeResponse<ResponseBase>(version => new System.Exception("Ho")).copri_version,
Throws.InstanceOf<System.Exception>());
}
}
}