mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 07:36:31 +01:00
87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
|
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>());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|