sharee.bike-App/SharedBusinessLogic.Tests/Model/Connector/TestConnectorCache.cs

86 lines
2.2 KiB
C#
Raw Normal View History

2023-02-22 14:03:35 +01:00
using System;
2023-04-05 15:02:10 +02:00
using NSubstitute;
2022-08-30 15:42:25 +02:00
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Connector;
using ShareeBike.Repository;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Connector
2021-07-12 21:31:46 +02:00
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestConnectorCache
{
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestCommandFactory()
{
2023-04-05 15:02:10 +02:00
var l_oCopri = Substitute.For<ICopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Construct not logged in version of connector.
var l_oCommand = new ConnectorCache(
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
null /*UI language */,
"", // Not logged in
"",
2023-02-22 14:03:35 +01:00
server: l_oCopri).Command;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(l_oCommand.GetType(), Is.EqualTo(typeof(Command)));
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestCommandFactory_LoggedIn()
{
2023-04-05 15:02:10 +02:00
var l_oCopri = Substitute.For<ICopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oCommand = new ConnectorCache(
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
null /*UI language */,
"123", // Logged in
"a@b",
2023-02-22 14:03:35 +01:00
server: l_oCopri).Command;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(l_oCommand.GetType(), Is.EqualTo(typeof(CommandLoggedIn)));
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestQueryFactory_CachedServer()
{
2023-04-05 15:02:10 +02:00
var l_oCopri = Substitute.For<ICopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oQuery = new ConnectorCache(
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
null /*UI language */,
"",
"",
2023-02-22 14:03:35 +01:00
server: l_oCopri).Query;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(l_oQuery.GetType(), Is.EqualTo(typeof(ShareeBike.Model.Connector.Query)));
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestQueryFactory_LoggedIn()
{
2023-04-05 15:02:10 +02:00
var l_oCopri = Substitute.For<ICopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oQuery = new ConnectorCache(
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
null /*UI language */,
"123",
"a@b",
2023-02-22 14:03:35 +01:00
server: l_oCopri).Query;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(l_oQuery.GetType(), Is.EqualTo(typeof(QueryLoggedIn)));
2022-09-06 16:08:19 +02:00
}
}
2021-07-12 21:31:46 +02:00
}