sharee.bike-App/SharedBusinessLogic.Tests_old/Fixtures/ObjectTests/Connector/TestFilter.cs

105 lines
4.5 KiB
C#
Raw Normal View History

2023-02-22 14:03:35 +01:00
using System;
2021-07-12 21:31:46 +02:00
using System.Collections.Generic;
using System.Linq;
2022-01-22 18:16:10 +01:00
using NSubstitute;
2022-08-30 15:42:25 +02:00
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
using SharedBusinessLogic.Tests.Framework.Repository;
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
/// <summary> Tests filter object. </summary>
[TestFixture]
public class TestFilter
{
/// <summary> Tests all stations. </summary>
[Test]
public void TestGetStationsAll()
{
2023-04-19 12:14:14 +02:00
var appContextInfo = new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2));
2022-09-06 16:08:19 +02:00
var connector = new ConnectorCache(
2023-04-19 12:14:14 +02:00
appContextInfo,
2022-09-06 16:08:19 +02:00
null /*UI language */,
string.Empty,
string.Empty,
2023-04-19 12:14:14 +02:00
server: new CopriCallsMemory001(merchantId: appContextInfo.MerchantId));
2022-09-06 16:08:19 +02:00
var filter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE, FilterHelper.CITYBIKE }, connector);
var stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(stations.StationsAll.Count(), Is.EqualTo(41)); // Count of stations was 9 before switching to data provider CopriCallsMemory(CopriCallsMemory.SampleSets.Set2, 1)
2022-09-06 16:08:19 +02:00
filter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE }, connector);
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(stations.StationsAll.Count(), Is.EqualTo(27));
2022-09-06 16:08:19 +02:00
filter = new FilteredConnector(new List<string> { FilterHelper.CITYBIKE }, connector);
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(stations.StationsAll.Count(), Is.EqualTo(21));
2022-09-06 16:08:19 +02:00
filter = new FilteredConnector(new List<string> { "AGroupNamedNonsensDoesNotExist" }, connector);
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(stations.StationsAll.Count(), Is.EqualTo(0));
2022-09-06 16:08:19 +02:00
filter = new FilteredConnector(new List<string>(), connector);
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(stations.StationsAll.Count(), Is.EqualTo(41));
2022-09-06 16:08:19 +02:00
filter = new FilteredConnector(null, connector);
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(stations.StationsAll.Count(), Is.EqualTo(41), "Null means filter none.");
2022-09-06 16:08:19 +02:00
}
/// <summary> Tests all stations. </summary>
[Test]
public void TestGetBikesAll()
{
2023-04-19 12:14:14 +02:00
var appContextInfo = new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2));
2022-09-06 16:08:19 +02:00
var l_oConnector = new ConnectorCache(
2023-04-19 12:14:14 +02:00
appContextInfo,
2022-09-06 16:08:19 +02:00
null /*UI language */,
string.Empty,
string.Empty,
2023-04-19 12:14:14 +02:00
server: new CopriCallsMemory001(merchantId: appContextInfo.MerchantId));
2022-09-06 16:08:19 +02:00
var l_oFilter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE, FilterHelper.CITYBIKE }, l_oConnector);
var l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(l_oBikes.Count(), Is.EqualTo(8)); // Count of stations was 12 CopriCallsMemory(CopriCallsMemory.SampleSets.Set2, 1)
2022-09-06 16:08:19 +02:00
l_oFilter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE }, l_oConnector);
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(l_oBikes.Count(), Is.EqualTo(3)); // Was 11
2022-09-06 16:08:19 +02:00
l_oFilter = new FilteredConnector(new List<string> { FilterHelper.CITYBIKE }, l_oConnector);
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(l_oBikes.Count(), Is.EqualTo(5)); // Was 1
2022-09-06 16:08:19 +02:00
l_oFilter = new FilteredConnector(new List<string> { "AGroupNamedNonsensDoesNotExist" }, l_oConnector);
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(l_oBikes.Count(), Is.EqualTo(0));
2022-09-06 16:08:19 +02:00
l_oFilter = new FilteredConnector(new List<string>(), l_oConnector);
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(l_oBikes.Count(), Is.EqualTo(8), "List with zero element means filter all."); // Was 12
2022-09-06 16:08:19 +02:00
l_oFilter = new FilteredConnector(null, l_oConnector);
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
2024-04-09 12:53:23 +02:00
Assert.That(l_oBikes.Count(), Is.EqualTo(8), "Null means filter none.");
2022-09-06 16:08:19 +02:00
}
[Test]
public void TestIsConnected()
{
var connector = Substitute.For<IConnector>();
connector.IsConnected.Returns(true);
2024-04-09 12:53:23 +02:00
Assert.That(new FilteredConnector(new List<string>(), connector).IsConnected, Is.True);
2022-09-06 16:08:19 +02:00
var dummy = connector.Received().IsConnected;
connector = Substitute.For<IConnector>();
connector.IsConnected.Returns(false);
2024-04-09 12:53:23 +02:00
Assert.That(new FilteredConnector(new List<string>(), connector).IsConnected, Is.False);
2022-09-06 16:08:19 +02:00
dummy = connector.Received().IsConnected;
}
}
2021-07-12 21:31:46 +02:00
}