mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 15:16:34 +01:00
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using NSubstitute;
|
|
using NSubstitute.ReceivedExtensions;
|
|
using NUnit.Framework;
|
|
using TINK.Model.Connector;
|
|
using TINK.Repository;
|
|
using TINK.Repository.Exception;
|
|
using TINK.Repository.Response;
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|
{
|
|
[TestFixture]
|
|
public class TestCommandLoggedIn
|
|
{
|
|
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
|
[Test]
|
|
public void TestDoLogout()
|
|
{
|
|
var l_oServer = Substitute.For<ICopriServer>();
|
|
|
|
l_oServer.DoAuthoutAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<AuthorizationoutResponse>("{ \"response_state\" : \"OK\", \"authcookie\" : \"1\"}")));
|
|
|
|
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
|
|
|
LoginStateChangedEventArgs l_oEventArgs = null;
|
|
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
|
|
|
l_oCmd.DoLogout().Wait();
|
|
|
|
|
|
l_oServer.Received().DoAuthoutAsync();
|
|
Assert.IsNotNull(l_oEventArgs);
|
|
}
|
|
|
|
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
|
[Test]
|
|
public void TestDoLogout_AuthcookieNotDefined()
|
|
{
|
|
var l_oServer = Substitute.For<ICopriServer>();
|
|
|
|
l_oServer.When(x => x.DoAuthoutAsync()).Throw(new AuthcookieNotDefinedException("Testing action", JsonConvert.DeserializeObject<ResponseBase>(@"{ ""response_state"" : ""Some inner error description""}")));
|
|
|
|
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
|
|
|
LoginStateChangedEventArgs l_oEventArgs = null;
|
|
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
|
|
|
l_oCmd.DoLogout().Wait();
|
|
|
|
l_oServer.Received().DoAuthoutAsync();
|
|
Assert.IsNotNull(l_oEventArgs);
|
|
}
|
|
|
|
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
|
[Test]
|
|
public void TestDoLogout_Exception()
|
|
{
|
|
var l_oServer = Substitute.For<ICopriServer>();
|
|
|
|
l_oServer.When(x => x.DoAuthoutAsync()).Throw(new System.Exception("Sometheing went wrong."));
|
|
|
|
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
|
|
|
LoginStateChangedEventArgs l_oEventArgs = null;
|
|
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
|
|
|
Assert.Throws<AggregateException>(() => l_oCmd.DoLogout().Wait());
|
|
|
|
l_oServer.Received().DoAuthoutAsync();
|
|
Assert.IsNull(l_oEventArgs);
|
|
}
|
|
}
|
|
}
|