sharee.bike-App/TestTINKLib/Fixtures/ObjectTests/Connector/TestCommandLoggedIn.cs

74 lines
2.5 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
2021-07-12 21:31:46 +02:00
using NUnit.Framework;
using Rhino.Mocks;
using TINK.Model.Connector;
using TINK.Repository;
using TINK.Repository.Exception;
using TINK.Repository.Response;
namespace TestTINKLib.Fixtures.ObjectTests.Connector
{
2022-09-06 16:08:19 +02:00
[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>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oServer.Stub(x => x.DoAuthoutAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<AuthorizationoutResponse>("{ \"response_state\" : \"OK\", \"authcookie\" : \"1\"}")));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
LoginStateChangedEventArgs l_oEventArgs = null;
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oCmd.DoLogout().Wait();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
Assert.IsNotNull(l_oEventArgs);
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
[Test]
public void TestDoLogout_AuthcookieNotDefined()
{
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oServer.Stub(x => x.DoAuthoutAsync()).Throw(new AuthcookieNotDefinedException("Testing action", JsonConvert.DeserializeObject<ResponseBase>(@"{ ""response_state"" : ""Some inner error description""}")));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
LoginStateChangedEventArgs l_oEventArgs = null;
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oCmd.DoLogout().Wait();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
Assert.IsNotNull(l_oEventArgs);
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
[Test]
public void TestDoLogout_Exception()
{
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oServer.Stub(x => x.DoAuthoutAsync()).Throw(new System.Exception("Sometheing went wrong."));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
LoginStateChangedEventArgs l_oEventArgs = null;
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.Throws<AggregateException>(() => l_oCmd.DoLogout().Wait());
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
Assert.IsNull(l_oEventArgs);
}
}
2021-07-12 21:31:46 +02:00
}