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

91 lines
2.6 KiB
C#
Raw Normal View History

2023-04-05 15:02:10 +02:00
using System;
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.Model.Services.CopriApi;
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 TestConnector
{
/// <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<ICachedCopriServer>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Construct not logged in version of connector.
2024-04-09 12:53:23 +02:00
var l_oCommand = new ShareeBike.Model.Connector.Connector(
2022-09-06 16:08:19 +02:00
new System.Uri("http://1.2.3.4"),
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
"", // Not logged in
"",
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<ICachedCopriServer>();
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
var l_oCommand = new ShareeBike.Model.Connector.Connector(
2022-09-06 16:08:19 +02:00
new System.Uri("http://1.2.3.4"),
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
"123", // Logged in
"a@b",
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<ICachedCopriServer>();
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
var l_oQuery = new ShareeBike.Model.Connector.Connector(
2022-09-06 16:08:19 +02:00
new Uri("http://1.2.3.4"),
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
"",
"",
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(CachedQuery)));
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<ICachedCopriServer>();
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
var l_oQuery = new ShareeBike.Model.Connector.Connector(
2022-09-06 16:08:19 +02:00
new System.Uri("http://1.2.3.4"),
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
"123",
"a@b",
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(CachedQueryLoggedIn)));
2022-09-06 16:08:19 +02:00
}
}
2021-07-12 21:31:46 +02:00
}