mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-07-03 10:26:31 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model.Services.CopriApi.ServerUris;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriServerUriList
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oUri = new CopriServerUriList();
|
||||
|
||||
Assert.That(l_oUri.Uris.Count, Is.GreaterThan(0), "There must be at least one uri");
|
||||
Assert.That(l_oUri.ActiveUri, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_AryStringString()
|
||||
{
|
||||
var l_oUri = new CopriServerUriList(
|
||||
(new List<Uri> { new Uri("http://1.2.3.4"), new Uri("http://2.3.4.5"), new Uri("http://3.4.5.6") }).ToArray(),
|
||||
new Uri("http://2.3.4.5"));
|
||||
|
||||
Assert.That(l_oUri.Uris.Count, Is.EqualTo(3));
|
||||
Assert.That(l_oUri.ActiveUri, Is.EqualTo(new Uri("http://2.3.4.5")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_AryStringString_NullList()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
|
||||
null,
|
||||
new Uri("http://2.3.4.5")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_AryStringString_InvalidList()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
|
||||
(new List<Uri>()).ToArray(),
|
||||
new Uri("http://2.3.4.5")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_AryStringString_InvalidActiveUri()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
|
||||
(new List<Uri> { new Uri("http://1.2.3.4"), new Uri("http://2.3.4.5"), new Uri("http://3.4.5.6") }).ToArray(),
|
||||
new Uri("http://9.9.9.9")));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestDefaultActiveUri()
|
||||
{
|
||||
Assert.That(
|
||||
CopriServerUriList.DefaultActiveUri.AbsoluteUri, Is.EqualTo("https://shareeapp-primary.copri.eu/APIjsonserver"),
|
||||
"In production environment, server address must always be app.tink-konstanz.de/APIjsonserver.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model;
|
||||
using ShareeBike.Model.Map;
|
||||
using ShareeBike.Services.CopriApi;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.Services.CopriApi
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestGeneralData
|
||||
{
|
||||
[Test]
|
||||
public void TestCtor()
|
||||
{
|
||||
Assert.That(
|
||||
new GeneralData().MerchantMessage,
|
||||
Is.EqualTo(""));
|
||||
|
||||
Assert.That(
|
||||
new GeneralData().ApiVersion,
|
||||
Is.EqualTo(new Version(0, 0)));
|
||||
|
||||
Assert.That(
|
||||
new GeneralData().InitialMapSpan?.IsValid,
|
||||
Is.False,
|
||||
"Object not not be null but invalid.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMessage()
|
||||
{
|
||||
Assert.That(
|
||||
new GeneralData(
|
||||
MapSpanFactory.Create(),
|
||||
"Hello",
|
||||
null,
|
||||
new ResourceUrls()).MerchantMessage,
|
||||
Is.EqualTo("Hello"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestVersion()
|
||||
{
|
||||
Assert.That(
|
||||
new GeneralData(
|
||||
MapSpanFactory.Create(),
|
||||
null,
|
||||
new Version(1, 2),
|
||||
new ResourceUrls()).ApiVersion,
|
||||
Is.EqualTo(new Version(1, 2)));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestInitialMapSpan()
|
||||
{
|
||||
Assert.That(
|
||||
new GeneralData(
|
||||
MapSpanFactory.Create(PositionFactory.Create(0, 8), 15),
|
||||
null,
|
||||
new Version(1, 2),
|
||||
new ResourceUrls()).InitialMapSpan.Center.Longitude,
|
||||
Is.EqualTo(8));
|
||||
|
||||
Assert.That(
|
||||
new GeneralData(
|
||||
MapSpanFactory.Create(PositionFactory.Create(0, 8), 15),
|
||||
null,
|
||||
new Version(1, 2),
|
||||
new ResourceUrls()).InitialMapSpan.Radius,
|
||||
Is.EqualTo(15));
|
||||
}
|
||||
}
|
||||
}
|
105
SharedBusinessLogic.Tests/Services/CopriApi/TestPolling.cs
Normal file
105
SharedBusinessLogic.Tests/Services/CopriApi/TestPolling.cs
Normal file
|
@ -0,0 +1,105 @@
|
|||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.CopriLock;
|
||||
using ShareeBike.Model.Services.CopriApi;
|
||||
using ShareeBike.Services.CopriApi;
|
||||
using ShareeBike.Repository.Request;
|
||||
using System.Threading.Tasks;
|
||||
using ShareeBike.Repository.Response;
|
||||
using ShareeBike.Repository;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.Services.CopriApi
|
||||
{
|
||||
[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;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
SharedBusinessLogic.Tests/Services/CopriApi/TestResult.cs
Normal file
33
SharedBusinessLogic.Tests/Services/CopriApi/TestResult.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model;
|
||||
using ShareeBike.Model.Map;
|
||||
using ShareeBike.Model.Services.CopriApi;
|
||||
using ShareeBike.Services.CopriApi;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.Services.CopriApi
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestResult
|
||||
{
|
||||
[Test]
|
||||
public void TestCtor()
|
||||
{
|
||||
Assert.That(
|
||||
new Result<object>(typeof(TestResult), new TestResult(), null).GeneralData,
|
||||
Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGeneralData()
|
||||
{
|
||||
Assert.That(
|
||||
new Result<object>(typeof(TestResult), new TestResult(), new GeneralData(
|
||||
MapSpanFactory.Create(),
|
||||
"Hello",
|
||||
new Version(0, 0),
|
||||
new ResourceUrls())).GeneralData.MerchantMessage,
|
||||
Is.EqualTo("Hello"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue