sharee.bike-App/SharedBusinessLogic.Tests/Model/Connector/TestConnector.cs
2024-04-09 12:53:23 +02:00

90 lines
2.6 KiB
C#

using System;
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Services.CopriApi;
using ShareeBike.Repository;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Connector
{
[TestFixture]
public class TestConnector
{
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestCommandFactory()
{
var l_oCopri = Substitute.For<ICachedCopriServer>();
// Construct not logged in version of connector.
var l_oCommand = new ShareeBike.Model.Connector.Connector(
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;
Assert.That(l_oCommand.GetType(), Is.EqualTo(typeof(Command)));
}
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestCommandFactory_LoggedIn()
{
var l_oCopri = Substitute.For<ICachedCopriServer>();
var l_oCommand = new ShareeBike.Model.Connector.Connector(
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;
Assert.That(l_oCommand.GetType(), Is.EqualTo(typeof(CommandLoggedIn)));
}
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestQueryFactory_CachedServer()
{
var l_oCopri = Substitute.For<ICachedCopriServer>();
var l_oQuery = new ShareeBike.Model.Connector.Connector(
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;
Assert.That(l_oQuery.GetType(), Is.EqualTo(typeof(CachedQuery)));
}
/// <summary>
/// Verifies that factory method returns correcty type depending on session cookie.
/// </summary>
[Test]
public void TestQueryFactory_LoggedIn()
{
var l_oCopri = Substitute.For<ICachedCopriServer>();
var l_oQuery = new ShareeBike.Model.Connector.Connector(
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;
Assert.That(l_oQuery.GetType(), Is.EqualTo(typeof(CachedQueryLoggedIn)));
}
}
}