sharee.bike-App/SharedBusinessLogic.Tests/Services/CopriApi/TestPolling.cs

106 lines
2.6 KiB
C#
Raw Normal View History

2023-02-22 14:03:35 +01:00
using NSubstitute;
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.CopriLock;
using ShareeBike.Model.Services.CopriApi;
using ShareeBike.Services.CopriApi;
using ShareeBike.Repository.Request;
2023-02-22 14:03:35 +01:00
using System.Threading.Tasks;
2024-04-09 12:53:23 +02:00
using ShareeBike.Repository.Response;
using ShareeBike.Repository;
2023-02-22 14:03:35 +01:00
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Services.CopriApi
2023-02-22 14:03:35 +01:00
{
[TestFixture]
public class TestPolling
{
[Test]
public async Task TestOpenAyncLockStateUnknownDisconnected()
{
var server = Substitute.For<ICachedCopriServer>();
var bike = Substitute.For<IBikeInfoMutable>();
bike.Id.Returns("XY19");
bike.OperatorUri.Returns(new System.Uri("https://1.2.3.4"));
await Polling.OpenAync(server, bike);
Received.InOrder(
() =>
{
server.UpdateLockingStateAsync(
"XY19",
lock_state.unlocking,
new System.Uri("https://1.2.3.4"));
bike.LockInfo.State = LockingState.UnknownDisconnected;
});
}
[Test]
public async Task TestOpenAyncLock()
{
var server = Substitute.For<ICachedCopriServer>();
var bike = Substitute.For<IBikeInfoMutable>();
bike.Id.Returns("XY19");
bike.OperatorUri.Returns(new System.Uri("https://1.2.3.4"));
server.GetBikesOccupied(false).Returns(
new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsHttps),
JsonConvertRethrow.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": {
""FR1005"": {
""lock_state"": ""occupied"",
""system"": ""Sigo"",
""state"": ""occupied"",
""bike"": ""XY19"",
""station"": ""REN0"",
""lock_state"" : ""locked""
}
},
""copri_version"": ""4.1.12.5"",
}"),
new GeneralData()),
new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsHttps),
JsonConvertRethrow.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": {
""FR1005"": {
""lock_state"": ""occupied"",
""system"": ""Sigo"",
""state"": ""occupied"",
""bike"": ""XY19"",
""station"": ""REN0"",
""lock_state"" : ""unlocked""
}
},
""copri_version"": ""4.1.12.5"",
}"),
new GeneralData()));
await Polling.OpenAync(server, bike);
Received.InOrder(
() =>
{
server.UpdateLockingStateAsync(
"XY19",
lock_state.unlocking,
new System.Uri("https://1.2.3.4"));
server.GetBikesOccupied(false);
server.GetBikesOccupied(false);
bike.LockInfo.State = LockingState.Open;
});
}
}
}