mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 02:56:32 +01:00
74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
|
using Newtonsoft.Json;
|
|||
|
using NUnit.Framework;
|
|||
|
using Rhino.Mocks;
|
|||
|
using System;
|
|||
|
using System.Threading.Tasks;
|
|||
|
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 = MockRepository.GenerateStub<ICopriServer>();
|
|||
|
|
|||
|
l_oServer.Stub(x => x.DoAuthoutAsync()).Return(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.AssertWasCalled(x => x.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 = MockRepository.GenerateStub<ICopriServer>();
|
|||
|
|
|||
|
l_oServer.Stub(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.AssertWasCalled(x => x.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 = MockRepository.GenerateStub<ICopriServer>();
|
|||
|
|
|||
|
l_oServer.Stub(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.AssertWasCalled(x => x.DoAuthoutAsync());
|
|||
|
Assert.IsNull(l_oEventArgs);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|