mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Version 3.0.361
This commit is contained in:
parent
faf68061f4
commit
cba4da9357
88 changed files with 1119 additions and 1502 deletions
40
TestShareeLib/Model/Connector/Filter/TestIntersectFilter.cs
Normal file
40
TestShareeLib/Model/Connector/Filter/TestIntersectFilter.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Connector.Filter;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Filter
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestIntersectFilter
|
||||
{
|
||||
[Test]
|
||||
public void TestDoFilter_Null()
|
||||
{
|
||||
var filter = new IntersectGroupFilter(new List<string> { "Tonk" });
|
||||
|
||||
Assert.AreEqual(1, filter.DoFilter(null).Count());
|
||||
Assert.AreEqual(
|
||||
"Tonk",
|
||||
filter.DoFilter(null).ToArray()[0],
|
||||
"Do not apply filtering when null is passed as argement (null-filter).");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoFilter_Empty()
|
||||
{
|
||||
var filter = new IntersectGroupFilter(new List<string> { "Tonk" });
|
||||
|
||||
Assert.AreEqual(0, filter.DoFilter(new List<string>()).Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoFilter()
|
||||
{
|
||||
var filter = new IntersectGroupFilter(new List<string> { "FR_001", "FR_009" });
|
||||
|
||||
Assert.AreEqual(1, filter.DoFilter(new List<string> { "FR_001", "FR_007" }).Count());
|
||||
Assert.AreEqual("FR_001", filter.DoFilter(new List<string> { "FR_001", "FR_007" }).ToArray()[0]);
|
||||
}
|
||||
}
|
||||
}
|
20
TestShareeLib/Model/Connector/Filter/TestNullFilter.cs
Normal file
20
TestShareeLib/Model/Connector/Filter/TestNullFilter.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Connector.Filter;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Filter
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestNullFilter
|
||||
{
|
||||
[Test]
|
||||
public void TestDoFilter()
|
||||
{
|
||||
var filter = new NullGroupFilter();
|
||||
Assert.IsNull(filter.DoFilter(null));
|
||||
Assert.AreEqual(0, filter.DoFilter(new List<string>()).Count());
|
||||
Assert.AreEqual(1, filter.DoFilter(new List<string> { "Hello" }).Count());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -188,7 +188,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
https.GetBikesAvailableAsync().Returns<BikesAvailableResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
https.GetBikesAvailableAsync().Returns<BikesAvailableResponse>(x => { throw new WebConnectFailureException("Bang...", new System.Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
|
@ -288,7 +288,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
https.GetBikesOccupiedAsync().Returns<BikesReservedOccupiedResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
https.GetBikesOccupiedAsync().Returns<BikesReservedOccupiedResponse>(x => { throw new WebConnectFailureException("Bang...", new System.Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
|
@ -387,7 +387,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL)));
|
||||
https.GetStationsAsync().Returns<StationsAvailableResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
https.GetStationsAsync().Returns<StationsAvailableResponse>(x => { throw new WebConnectFailureException("Bang...", new System.Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
|
@ -424,7 +424,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<StationsAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL), new GeneralData(), new Exception("Bang...")));
|
||||
provider.AddToCache(new Result<StationsAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL), new GeneralData(), new System.Exception("Bang...")));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
|
@ -464,7 +464,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE), new GeneralData(), new Exception("Bang...")));
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE), new GeneralData(), new System.Exception("Bang...")));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
|
@ -506,7 +506,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
|||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED), new GeneralData(), new Exception("Bang...")));
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED), new GeneralData(), new System.Exception("Bang...")));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
|
|
75
TestShareeLib/Model/Logging/TestLoggingDirectoryManager.cs
Normal file
75
TestShareeLib/Model/Logging/TestLoggingDirectoryManager.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Logging;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestLoggingDirectoryManager
|
||||
{
|
||||
[Test]
|
||||
public void TestConstructInvalidArgs()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(
|
||||
() => new LoggingDirectoryManager(
|
||||
(name) => new List<string> { "2018_02_06_22_18_00" /* oldest */, "2018_02_06_23_10_00" /*youngest*/ , "2018_02_06_22_19_00", "2018_02_06_22_20_00" },
|
||||
(name) => false,
|
||||
(name) => { },
|
||||
(name) => { },
|
||||
"abc",
|
||||
'\\',
|
||||
0));
|
||||
|
||||
Assert.Throws<ArgumentException>(
|
||||
() => new LoggingDirectoryManager(
|
||||
(name) => new List<string> { "2018_02_06_22_18_00" /* oldest */, "2018_02_06_23_10_00" /*youngest*/ , "2018_02_06_22_19_00", "20180206222000" },
|
||||
(name) => false,
|
||||
(name) => { },
|
||||
(name) => { },
|
||||
"",
|
||||
'\\',
|
||||
3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeleteObsoleteLogs()
|
||||
{
|
||||
var l_oDeletedFilesList = new List<string>();
|
||||
|
||||
var l_oManger = new LoggingDirectoryManager(
|
||||
(name) => new List<string> { "2018_02_06_22_18_00" /* oldest */, "2018_02_06_23_10_00" /*youngest*/ , "2018_02_06_22_19_00", "20180206222000" },
|
||||
(name) => false,
|
||||
(name) => { },
|
||||
(name) => { l_oDeletedFilesList.Add(name); },
|
||||
"abc",
|
||||
'\\',
|
||||
3);
|
||||
|
||||
l_oManger.DeleteObsoleteLogs();
|
||||
|
||||
Assert.AreEqual(2, l_oDeletedFilesList.Count);
|
||||
Assert.IsTrue(l_oDeletedFilesList.Contains("2018_02_06_22_18_00"));
|
||||
Assert.IsTrue(l_oDeletedFilesList.Contains("2018_02_06_22_19_00"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeleteObsoleteLogs_EmptyDirectory()
|
||||
{
|
||||
var l_oDeletedFilesList = new List<string>();
|
||||
|
||||
var l_oManger = new LoggingDirectoryManager(
|
||||
(name) => new List<string>(),
|
||||
(name) => false,
|
||||
(name) => { },
|
||||
(name) => { l_oDeletedFilesList.Add(name); },
|
||||
"abc",
|
||||
'\\',
|
||||
3);
|
||||
|
||||
l_oManger.DeleteObsoleteLogs();
|
||||
|
||||
Assert.AreEqual(0, l_oDeletedFilesList.Count);
|
||||
}
|
||||
}
|
||||
}
|
124
TestShareeLib/Model/Settings/TestFilterCollectionStore.cs
Normal file
124
TestShareeLib/Model/Settings/TestFilterCollectionStore.cs
Normal file
|
@ -0,0 +1,124 @@
|
|||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Settings;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestFilterCollectionStore
|
||||
{
|
||||
[Test]
|
||||
public void TestSerialize_Null()
|
||||
{
|
||||
var l_oSettings = new Dictionary<string, string>().SetGroupFilterSettings(null);
|
||||
var l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.IsNull(l_oFilterColl);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerialize_Invalid()
|
||||
{
|
||||
var l_oSettings = new Dictionary<string, string>().SetGroupFilterSettings(new Dictionary<string, FilterState>());
|
||||
var l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.IsNull(l_oFilterColl);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerializeLegacy()
|
||||
{
|
||||
var l_oSettings = new Dictionary<string, string>().SetGroupFilterSettings(
|
||||
new Dictionary<string, FilterState>
|
||||
{
|
||||
{ "TINK.Copri", FilterState.On },
|
||||
{ "TINK.SMS", FilterState.Off},
|
||||
{ "Konrad", FilterState.On }
|
||||
});
|
||||
|
||||
var l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.AreEqual(2, l_oFilterColl.Count);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["Konrad"]);
|
||||
|
||||
l_oSettings = new Dictionary<string, string>().SetGroupFilterSettings(
|
||||
new Dictionary<string, FilterState>
|
||||
{
|
||||
{ "TINK.Copri", FilterState.Off },
|
||||
{ "TINK.SMS", FilterState.On},
|
||||
{ "Konrad", FilterState.On }
|
||||
});
|
||||
|
||||
l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.AreEqual(2, l_oFilterColl.Count);
|
||||
Assert.AreEqual(FilterState.Off, l_oFilterColl["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["Konrad"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerializeInvalid()
|
||||
{
|
||||
var l_oSettings = new Dictionary<string, string>()
|
||||
.SetGroupFilterSettings(
|
||||
new Dictionary<string, FilterState>
|
||||
{
|
||||
{ "TINK.SMS", FilterState.Off},
|
||||
{ "Konrad", FilterState.On }
|
||||
});
|
||||
|
||||
var l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.AreEqual(2, l_oFilterColl.Count);
|
||||
Assert.AreEqual(FilterState.Off, l_oFilterColl["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["Konrad"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerializeRoundtrip()
|
||||
{
|
||||
var l_oSettings = new Dictionary<string, string>()
|
||||
.SetGroupFilterSettings(
|
||||
new Dictionary<string, FilterState>
|
||||
{
|
||||
{ "TINK", FilterState.On },
|
||||
{ "Konrad", FilterState.On }
|
||||
});
|
||||
|
||||
var l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.AreEqual(2, l_oFilterColl.Count);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["Konrad"]);
|
||||
|
||||
l_oSettings = new Dictionary<string, string>().SetGroupFilterSettings(
|
||||
new Dictionary<string, FilterState>
|
||||
{
|
||||
{ "TINK", FilterState.Off },
|
||||
{ "Konrad", FilterState.On }
|
||||
});
|
||||
|
||||
l_oFilterColl = JsonSettingsDictionary.GetGoupFilterSettings(l_oSettings);
|
||||
|
||||
Assert.AreEqual(2, l_oFilterColl.Count);
|
||||
Assert.AreEqual(FilterState.Off, l_oFilterColl["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oFilterColl["Konrad"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_ToString_Emtpy()
|
||||
{
|
||||
Assert.AreEqual("{}", FilterCollectionStore.ToString(new Dictionary<string, FilterState>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_ToString()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"{(Test1= Off), (Test2= On)}",
|
||||
FilterCollectionStore.ToString(new Dictionary<string, FilterState> { { "Test1", FilterState.Off }, { "Test2", FilterState.On } }));
|
||||
}
|
||||
}
|
||||
}
|
45
TestShareeLib/Model/Settings/TestSettings.cs
Normal file
45
TestShareeLib/Model/Settings/TestSettings.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using Serilog.Events;
|
||||
using TINK.Model.Services.CopriApi.ServerUris;
|
||||
using TINK.Settings;
|
||||
using TINK.ViewModel.Map;
|
||||
using TINK.ViewModel.Settings;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.SettingsNS
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSettings
|
||||
{
|
||||
[Test]
|
||||
public void TestConstructDefaults()
|
||||
{
|
||||
var settings = new TINK.Model.Settings.Settings();
|
||||
|
||||
Assert.AreEqual(LogEventLevel.Error, settings.MinimumLogEventLevel);
|
||||
|
||||
// Was GroupFilterHelper.GetSettingsFilterDefaults when used in TINK- context.
|
||||
Assert.AreEqual(new GroupFilterSettings(), settings.GroupFilterSettings);
|
||||
|
||||
// Was GroupFilterHelper.GetMapPageFilterDefaults when used in TINK- context.
|
||||
Assert.AreEqual(new GroupFilterMapPage(), settings.GroupFilterMapPage);
|
||||
|
||||
Assert.AreEqual(new CopriServerUriList().ActiveUri, settings.ActiveUri);
|
||||
|
||||
Assert.AreEqual(PollingParameters.Default, settings.PollingParameters);
|
||||
|
||||
Assert.IsTrue(
|
||||
settings.CenterMapToCurrentLocation,
|
||||
"Center to map for sharee.bike because bt- locks require location info.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorTink()
|
||||
{
|
||||
var settings = new TINK.Model.Settings.Settings(activeUri: new Uri(CopriServerUriList.TINK_LIVE));
|
||||
Assert.IsFalse(
|
||||
settings.CenterMapToCurrentLocation,
|
||||
"Do not center to current location for TINK.");
|
||||
}
|
||||
}
|
||||
}
|
30
TestShareeLib/Model/State/TestStateBookedInfo.cs
Normal file
30
TestShareeLib/Model/State/TestStateBookedInfo.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateBookedInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oBookedInfo = new StateOccupiedInfo(new DateTime(2017, 09, 20, 23, 05, 0), "Heinz@mueller", "17 xxb");
|
||||
|
||||
Assert.AreEqual(
|
||||
new DateTime(2017, 09, 20, 23, 05, 0),
|
||||
l_oBookedInfo.From);
|
||||
|
||||
Assert.AreEqual(
|
||||
"Heinz@mueller",
|
||||
l_oBookedInfo.MailAddress);
|
||||
|
||||
Assert.AreEqual(
|
||||
"17 xxb",
|
||||
l_oBookedInfo.Code);
|
||||
}
|
||||
}
|
||||
}
|
17
TestShareeLib/Model/State/TestStateDisposableInfo.cs
Normal file
17
TestShareeLib/Model/State/TestStateDisposableInfo.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateDisposableInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, new StateAvailableInfo().Value);
|
||||
}
|
||||
}
|
||||
}
|
214
TestShareeLib/Model/State/TestStateInfoSerializeJSON.cs
Normal file
214
TestShareeLib/Model/State/TestStateInfoSerializeJSON.cs
Normal file
|
@ -0,0 +1,214 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TestFramework;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib.Fixtures.State
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateInfoSerializeJSON
|
||||
{
|
||||
[Test]
|
||||
public void TestSerializeJSON_Disposable()
|
||||
{
|
||||
string l_strJSONDetected;
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 20, 23, 20, 0));
|
||||
|
||||
// Serialize object and verify json
|
||||
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
});
|
||||
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""StateInfoObject"":
|
||||
{
|
||||
""$type"":""TINK.Model.State.StateAvailableInfo, TINKLib""
|
||||
}
|
||||
}";
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
|
||||
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
|
||||
}
|
||||
|
||||
{
|
||||
// Deserialize object
|
||||
var l_oInUseStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oInUseStateTarget.Value);
|
||||
Assert.AreEqual("Disposable", l_oInUseStateTarget.ToString());
|
||||
Assert.IsNull(l_oInUseStateTarget.RemainingTime);
|
||||
Assert.IsNull(l_oInUseStateTarget.From);
|
||||
Assert.IsNull(l_oInUseStateTarget.MailAddress);
|
||||
Assert.IsNull(l_oInUseStateTarget.Code);
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public void TestSerializeJSON_Booked()
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oInUseState = new StateInfoMutable(
|
||||
() => new DateTime(2017, 11, 18, 23, 20, 0) // Mocked time stamp returned when StateInfo- object is crated
|
||||
);
|
||||
|
||||
l_oInUseState.Load(
|
||||
InUseStateEnum.Booked,
|
||||
new DateTime(2017, 11, 18, 23, 19, 0), // Time booked at
|
||||
"heiz@mustermann",
|
||||
"173"); // Code
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oInUseState.Value);
|
||||
Assert.AreEqual("heiz@mustermann", l_oInUseState.MailAddress);
|
||||
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 19, 0), l_oInUseState.From);
|
||||
Assert.AreEqual("173", l_oInUseState.Code);
|
||||
|
||||
// Verify json
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""StateInfoObject"":
|
||||
{
|
||||
""$type"":""TINK.Model.State.StateOccupiedInfo, TINKLib"",
|
||||
""From"":""2017 - 11 - 18T23: 19:00"",
|
||||
""MailAddress"":""heiz @mustermann"",""Code"":""173""
|
||||
}
|
||||
}";
|
||||
|
||||
var l_oDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED).Replace("\n", string.Empty).Replace("\r", string.Empty),
|
||||
TestHelper.PrepareXmlForStringCompare(l_oDetected).Replace("\n", string.Empty).Replace("\r", string.Empty));
|
||||
|
||||
// Deserialize object an verify state.
|
||||
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oStateTarget.Value);
|
||||
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 19, 0), l_oInUseState.From);
|
||||
Assert.AreEqual("heiz@mustermann", l_oStateTarget.MailAddress);
|
||||
Assert.AreEqual("173", l_oInUseState.Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerializeJSON_Reserved_NoCode()
|
||||
{
|
||||
string l_strJSONDetected;
|
||||
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 21, 23, 20, 0));
|
||||
l_oInUseState.Load(
|
||||
InUseStateEnum.Reserved,
|
||||
new DateTime(2017, 09, 21, 23, 20, 0),
|
||||
"heiz@mustermann");
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oInUseState.Value);
|
||||
Assert.AreEqual("heiz@mustermann", l_oInUseState.MailAddress);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 20, 0), l_oInUseState.From);
|
||||
Assert.AreEqual(new TimeSpan(0, 15, 0), l_oInUseState.RemainingTime);
|
||||
Assert.IsNull(l_oInUseState.Code);
|
||||
|
||||
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
});
|
||||
|
||||
// Verify json
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""StateInfoObject"":
|
||||
{
|
||||
""$type"":""TINK.Model.State.StateRequestedInfo, TINKLib"",
|
||||
""From"":""2017 - 09 - 21T23: 20:00"",
|
||||
""MailAddress"":""heiz @mustermann""
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
|
||||
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
|
||||
}
|
||||
|
||||
{
|
||||
// Deserialize object an verify state.
|
||||
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateTarget.Value);
|
||||
Assert.AreEqual("heiz@mustermann", l_oStateTarget.MailAddress);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 20, 0), l_oStateTarget.From);
|
||||
Assert.IsNull(l_oStateTarget.RemainingTime, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
|
||||
Assert.IsNull(l_oStateTarget.Code);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerializeJSON_Reserved()
|
||||
{
|
||||
string l_strJSONDetected;
|
||||
|
||||
{
|
||||
Func<DateTime> l_oNow = () => new DateTime(2017, 11, 18, 23, 18, 0);
|
||||
// Create object to test.
|
||||
var l_oInUseState = new StateInfoMutable(l_oNow);
|
||||
|
||||
DateTime l_oFrom = new DateTime(2017, 11, 18, 23, 18, 0);
|
||||
l_oInUseState.Load(
|
||||
InUseStateEnum.Reserved,
|
||||
l_oFrom,
|
||||
"z@C",
|
||||
"01815A");
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oInUseState.Value);
|
||||
Assert.AreEqual("z@C", l_oInUseState.MailAddress);
|
||||
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 18, 0), l_oInUseState.From);
|
||||
Assert.AreEqual((new TimeSpan(0, 15, 0)).Subtract(l_oNow().Subtract(l_oFrom)), l_oInUseState.RemainingTime);
|
||||
Assert.AreEqual("01815A", l_oInUseState.Code);
|
||||
|
||||
l_strJSONDetected = JsonConvert.SerializeObject(l_oInUseState, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
});
|
||||
|
||||
// Verify json
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""StateInfoObject"":
|
||||
{
|
||||
""$type"":""TINK.Model.State.StateRequestedInfo, TINKLib"",
|
||||
""From"":""2017 - 11 - 18T23: 18:00"",
|
||||
""MailAddress"":""z @C"",
|
||||
""Code"":""01815A""
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
|
||||
TestHelper.PrepareXmlForStringCompare(l_strJSONDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
|
||||
}
|
||||
|
||||
{
|
||||
// Deserialize object an verify state.
|
||||
var l_oStateTarget = JsonConvert.DeserializeObject<StateInfoMutable>(l_strJSONDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateTarget.Value);
|
||||
Assert.AreEqual("z@C", l_oStateTarget.MailAddress);
|
||||
Assert.AreEqual(new DateTime(2017, 11, 18, 23, 18, 0), l_oStateTarget.From);
|
||||
Assert.IsNull(l_oStateTarget.RemainingTime, "If deserialized date time provider is DateTime.Now. With a from- value of 2017-11- ... there is no more time remaining.");
|
||||
Assert.AreEqual("01815A", l_oStateTarget.Code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TestFramework;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib.Fixtures.State
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateReInquestedfoSerializeJSON
|
||||
{
|
||||
[Test]
|
||||
public void TestSerializeJSON()
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oReservedInfo = new StateRequestedInfo(
|
||||
() => new DateTime(2017, 09, 20),
|
||||
new DateTime(2017, 09, 19),
|
||||
"ä@b",
|
||||
"372");
|
||||
|
||||
// Serialize object
|
||||
// Serialize object and verify.
|
||||
var l_oDetected = JsonConvert.SerializeObject(l_oReservedInfo);
|
||||
// Verify xml
|
||||
const string EXPECTED = @"{""From"":""2017 - 09 - 19T00: 00:00"",""MailAddress"":""ä @b"",""Code"":""372""}";
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED),
|
||||
TestHelper.PrepareXmlForStringCompare(l_oDetected));
|
||||
|
||||
// Deserialize object.
|
||||
var l_oInfoTarge = JsonConvert.DeserializeObject<StateRequestedInfo>(l_oDetected);
|
||||
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oInfoTarge.Value);
|
||||
Assert.AreEqual("ä@b", l_oInfoTarge.MailAddress);
|
||||
Assert.AreEqual("372", l_oInfoTarge.Code);
|
||||
Assert.AreEqual(new DateTime(2017, 9, 19, 0, 0, 0), l_oInfoTarge.From);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
TestShareeLib/Model/Station/TestNullStation.cs
Normal file
29
TestShareeLib/Model/Station/TestNullStation.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Station;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Station
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestNullStation
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var nullStation = new NullStation();
|
||||
|
||||
// Was -1 before swiching type of id from int to string when switching from COPRI version v4.0 to v4.1
|
||||
Assert.That(
|
||||
nullStation.Id,
|
||||
Is.Null);
|
||||
|
||||
Assert.AreEqual(0, nullStation.Group.ToList().Count);
|
||||
Assert.AreEqual(string.Empty, nullStation.StationName);
|
||||
Assert.IsNaN(nullStation.Position.Latitude);
|
||||
Assert.IsNaN(nullStation.Position.Longitude);
|
||||
Assert.That(
|
||||
nullStation.OperatorData,
|
||||
Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
49
TestShareeLib/Model/Station/TestStation.cs
Normal file
49
TestShareeLib/Model/Station/TestStation.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
|
||||
namespace TestTINKLib.Fixtures.Station
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStation
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oStation = new TINK.Model.Station.Station("7", new HashSet<string>(new List<string> { "TINK" }).ToList(), PositionFactory.Create(1, 2), "Hallo");
|
||||
Assert.AreEqual("7", l_oStation.Id);
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oStation.Group));
|
||||
Assert.AreEqual(1, l_oStation.Position.Latitude);
|
||||
Assert.AreEqual(2, l_oStation.Position.Longitude);
|
||||
Assert.AreEqual("Hallo", l_oStation.StationName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_InvalidStationName()
|
||||
{
|
||||
var l_oStation = new TINK.Model.Station.Station("7", new HashSet<string>(new List<string> { "TINK" }).ToList(), PositionFactory.Create(1, 2), null);
|
||||
Assert.AreEqual("7", l_oStation.Id);
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oStation.Group));
|
||||
Assert.AreEqual(1, l_oStation.Position.Latitude);
|
||||
Assert.AreEqual(2, l_oStation.Position.Longitude);
|
||||
Assert.AreEqual("", l_oStation.StationName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_InvalidStationGroup()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new TINK.Model.Station.Station("7", null, PositionFactory.Create(1, 2), "Hallo"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_NoOperator()
|
||||
{
|
||||
Assert.That(
|
||||
new TINK.Model.Station.Station("7", new List<string>(), PositionFactory.Create(1, 2), "Hallo").OperatorData,
|
||||
Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
58
TestShareeLib/Model/User/Account/TestAccount.cs
Normal file
58
TestShareeLib/Model/User/Account/TestAccount.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace UITest.Fixtures.ObjectTests.User.Account
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestAccount
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
// Act
|
||||
var account = new TINK.Model.User.Account.Account(
|
||||
"hans.musterman@hotmail.com", // Mail
|
||||
"myPasswd", // Pwd
|
||||
false,
|
||||
"aktuellerKeks", // Cookie
|
||||
new List<string> { "Honkey", "Tonkey" }, // Group
|
||||
TINK.Model.User.Account.Permissions.None);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("hans.musterman@hotmail.com", account.Mail);
|
||||
Assert.AreEqual("myPasswd", account.Pwd);
|
||||
Assert.That(account.IsAgbAcknowledged, Is.False);
|
||||
Assert.AreEqual("aktuellerKeks", account.SessionCookie);
|
||||
Assert.AreEqual("Honkey,Tonkey", String.Join(",", account.Group));
|
||||
Assert.AreEqual(TINK.Model.User.Account.Permissions.None, account.DebugLevel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_Copy()
|
||||
{
|
||||
var account = new TINK.Model.User.Account.Account(new TINK.Model.User.Account.Account(
|
||||
"a@b",
|
||||
"112",
|
||||
true, // Agbs have been acknowledged
|
||||
"3330",
|
||||
new List<string> { "Honkey", "Tonkey" },
|
||||
TINK.Model.User.Account.Permissions.None));
|
||||
|
||||
Assert.AreEqual("a@b", account.Mail);
|
||||
Assert.AreEqual("112", account.Pwd);
|
||||
Assert.That(account.IsAgbAcknowledged, Is.True);
|
||||
Assert.AreEqual("3330", account.SessionCookie);
|
||||
Assert.AreEqual("Honkey,Tonkey", String.Join(",", account.Group));
|
||||
Assert.AreEqual(TINK.Model.User.Account.Permissions.None, account.DebugLevel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_InvalidGroup()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new TINK.Model.User.Account.Account("a@b", "112", false, "3330", null, TINK.Model.User.Account.Permissions.None));
|
||||
Assert.Throws<ArgumentException>(() => new TINK.Model.User.Account.Account(null));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
30
TestShareeLib/Model/User/Account/TestValidator.cs
Normal file
30
TestShareeLib/Model/User/Account/TestValidator.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Model.User.Account;
|
||||
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestValidator
|
||||
{
|
||||
[Test]
|
||||
public void TestValidateMailAndPasswordDelegate()
|
||||
{
|
||||
Assert.AreEqual(Elements.None, Validator.ValidateMailAndPasswordDelegate(null, null).ValidElement);
|
||||
|
||||
Assert.AreEqual(Elements.None, Validator.ValidateMailAndPasswordDelegate("", null).ValidElement);
|
||||
|
||||
Assert.AreEqual(Elements.None, Validator.ValidateMailAndPasswordDelegate("a", null).ValidElement);
|
||||
|
||||
Assert.AreEqual(Elements.None, Validator.ValidateMailAndPasswordDelegate("a@", null).ValidElement);
|
||||
|
||||
|
||||
Assert.AreEqual(Elements.Mail, Validator.ValidateMailAndPasswordDelegate("a@c", "").ValidElement);
|
||||
|
||||
Assert.AreEqual(Elements.Mail, Validator.ValidateMailAndPasswordDelegate("a@c", "123").ValidElement);
|
||||
|
||||
Assert.AreEqual(Elements.Mail | Elements.Password, Validator.ValidateMailAndPasswordDelegate("a@c", "123456789" /* password */).ValidElement);
|
||||
}
|
||||
}
|
||||
}
|
99
TestShareeLib/Model/User/TestUser.cs
Normal file
99
TestShareeLib/Model/User/TestUser.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.User;
|
||||
using TINK.Model.User.Account;
|
||||
using TINK.Repository;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestUser
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct_NotLoggedIn_NoUsername()
|
||||
{
|
||||
var storeMock = new StoreMock(); // Account without user name, password and cookie
|
||||
|
||||
var l_oUser = new User(
|
||||
storeMock,
|
||||
storeMock.Load().Result,
|
||||
"HwId1000000000000");
|
||||
|
||||
Assert.IsFalse(l_oUser.IsLoggedIn);
|
||||
Assert.IsNull(l_oUser.Mail);
|
||||
Assert.IsNull(l_oUser.Password);
|
||||
Assert.IsNull(l_oUser.SessionCookie);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_NotLoggedIn_NoCookie()
|
||||
{
|
||||
var storeMock = new StoreMock(new Account("John", "123", true, null, new List<string>())); // Account without session cookie.
|
||||
|
||||
var user = new User(
|
||||
storeMock,
|
||||
storeMock.Load().Result,
|
||||
"123456789");
|
||||
|
||||
Assert.IsFalse(user.IsLoggedIn);
|
||||
Assert.AreEqual("John", user.Mail);
|
||||
Assert.AreEqual("123", user.Password);
|
||||
Assert.IsNull(user.SessionCookie);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_LoggedIn()
|
||||
{
|
||||
var l_oStoreMock = new StoreMock(new Account("John", "123", false, "9512", new List<string> { "TINK" }));
|
||||
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789");
|
||||
|
||||
Assert.IsTrue(l_oUser.IsLoggedIn, "If store does not hold cookie user is considered to not be logged in");
|
||||
|
||||
Assert.AreEqual("John", l_oUser.Mail);
|
||||
Assert.AreEqual("123", l_oUser.Password);
|
||||
Assert.AreEqual("9512", l_oUser.SessionCookie);
|
||||
}
|
||||
|
||||
/// <summary>Test logging in. </summary>
|
||||
[Test]
|
||||
public async Task TestSetCredentials()
|
||||
{
|
||||
var l_oConnector = new ConnectorCache(
|
||||
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
|
||||
null /*UI language */,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
server: new CopriCallsMemory("MyMerchId", SampleSets.Set2, 1));
|
||||
|
||||
var l_oStoreMock = new StoreMock(); // Account without user name, password and cookie
|
||||
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"HwId1000000000000");
|
||||
|
||||
Assert.IsFalse(l_oUser.IsLoggedIn);
|
||||
Assert.IsNull(l_oUser.Mail);
|
||||
|
||||
IAccount l_oAccount = l_oConnector.Command.DoLogin(
|
||||
LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
l_oUser.DeviceId).Result;
|
||||
|
||||
await l_oUser.Login(l_oAccount);
|
||||
Assert.IsTrue(l_oUser.IsLoggedIn);
|
||||
|
||||
Assert.AreEqual(LoginSessionCopriInfo.JavaministerHardwareNr1.Mail, l_oUser.Mail);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue