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

74 lines
2.8 KiB
C#
Raw Normal View History

2021-07-12 21:31:46 +02:00
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);
}
}
}