diff --git a/Covid19Radar/Covid19Radar/Services/ExposureNotificationHandler.cs b/Covid19Radar/Covid19Radar/Services/ExposureNotificationHandler.cs index a0a669ecb..bca502a57 100644 --- a/Covid19Radar/Covid19Radar/Services/ExposureNotificationHandler.cs +++ b/Covid19Radar/Covid19Radar/Services/ExposureNotificationHandler.cs @@ -389,7 +389,11 @@ private async Task CreateSubmissionAsync(IEnumerab // See if we can add the device verification if (DependencyService.Get() is IDeviceVerifier verifier) { +#if USE_MOCK + //nop +#else submission.DeviceVerificationPayload = await verifier?.VerifyAsync(submission); +#endif } loggerService.Info($"DeviceVerificationPayload is {(string.IsNullOrEmpty(submission.DeviceVerificationPayload) ? "null or empty" : "set")}."); diff --git a/Covid19Radar/Covid19Radar/Services/HttpDataServiceMock.cs b/Covid19Radar/Covid19Radar/Services/HttpDataServiceMock.cs index c2c2a8101..e6d85c514 100644 --- a/Covid19Radar/Covid19Radar/Services/HttpDataServiceMock.cs +++ b/Covid19Radar/Covid19Radar/Services/HttpDataServiceMock.cs @@ -157,18 +157,68 @@ async Task> IHttpDataService.GetTempor return Data(); } + // copy ./TestNativeImplementation.cs + private string[] UrlApi() + { + // "UrlApi" -> UrlApi= + // ".../api1/register1/" -> UrlApi= + string url = AppSettings.Instance.ApiUrlBase; + Regex r = new Regex("/r(egister)?[0-9]+"); + Regex d = new Regex("/d(iagnosis)?[0-9]+"); + string urlRegister = r.Match(url).Value; + url = r.Replace(url, ""); + string urlDiagnosis = d.Match(url).Value; + url = d.Replace(url, ""); + string urlApi = url; + return (new string[] { urlApi, urlRegister, urlDiagnosis }); + } + + // copy ./TestNativeImplementation.cs + private ushort NumberEndofSentence(string url) + { + Match match = Regex.Match(url, @"(?\d+)$"); + ushort dataVer = 0; + if (match.Success) + { + dataVer = Convert.ToUInt16(match.Groups["d"].Value); + } + return (dataVer); + } + async Task IHttpDataService.PostRegisterUserAsync() { Debug.WriteLine("HttpDataServiceMock::PostRegisterUserAsync called"); - return await Task.FromResult(true); + switch (NumberEndofSentence(UrlApi()[1])) + { + case 1: + return await Task.FromResult(false); + case 0: + default: + return await Task.FromResult(true); + } } Task IHttpDataService.PutSelfExposureKeysAsync(DiagnosisSubmissionParameter request) { + var code = HttpStatusCode.OK; // default. for PutSelfExposureKeys NG + var dataVer = NumberEndofSentence(UrlApi()[2]); + if (dataVer >= 100) + { + code = (HttpStatusCode)dataVer; + } + else + { + switch (dataVer) + { + case 1: + code = HttpStatusCode.NoContent; // for Successful PutSelfExposureKeys + break; + } + } return Task.Factory.StartNew(() => { Debug.WriteLine("HttpDataServiceMock::PutSelfExposureKeysAsync called"); - return HttpStatusCode.OK; + return code; }); } diff --git a/Covid19Radar/Covid19Radar/Services/TestNativeImplementation.cs b/Covid19Radar/Covid19Radar/Services/TestNativeImplementation.cs index 4a9e7c79a..043a17c05 100644 --- a/Covid19Radar/Covid19Radar/Services/TestNativeImplementation.cs +++ b/Covid19Radar/Covid19Radar/Services/TestNativeImplementation.cs @@ -58,6 +58,7 @@ private ushort[] DataPreset(int dataVer) 0(default): two low-risk matches (default for v1.2.3) 1: one high-risk match and 2 low-risk matches 2: no match + 3+: please add */ switch (dataVer) { @@ -82,20 +83,40 @@ private ushort[] DataPreset(int dataVer) } } - private ushort[] Data() + public string[] UrlApi() { + // "UrlApi" -> UrlApi= + // ".../api1/register1/" -> UrlApi= string url = AppSettings.Instance.ApiUrlBase; - if (Regex.IsMatch(url, @"^(\d+,)+\d+,*$")) - { - return (url.Split(",").ToList().Select(x => Convert.ToUInt16(x)).ToArray()); - } - int dataVer = -1; - Match match = Regex.Match(url, @"https://API_URL_BASE/api/(?\d+?)"); + Regex r = new Regex("/r(egister)?[0-9]+"); + Regex d = new Regex("/d(iagnosis)?[0-9]+"); + string urlRegister = r.Match(url).Value; + url = r.Replace(url, ""); + string urlDiagnosis = d.Match(url).Value; + url = d.Replace(url, ""); + string urlApi = url; + return (new string[] { urlApi, urlRegister, urlDiagnosis }); + } + + public ushort NumberEndofSentence(string url) + { + Match match = Regex.Match(url, @"(?\d+)$"); + ushort dataVer = 0; if (match.Success) { dataVer = Convert.ToUInt16(match.Groups["d"].Value); } - return (DataPreset(dataVer)); + return (dataVer); + } + + private ushort[] Data() + { + string url = UrlApi()[0]; + if (Regex.IsMatch(url, @"^(\d+,)+\d+,?$")) + { + return (url.Split(",").ToList().Select(x => Convert.ToUInt16(x)).ToArray()); + } + return (DataPreset(NumberEndofSentence(url))); } @@ -103,9 +124,9 @@ private ushort[] Data() { /* ApiUrlBase trick for Debug_Mock "10,2,5,0,0,10,15,65,5,4,11,5,40,3,2" -> direct input (the same with default) - "https://API_URL_BASE/api/2" -> dataVer = 2 + "https://API_URL_BASE/api2" -> dataVer = 2 "https://API_URL_BASE/api" -> dataVer = 0 (default) - others -> dataVer = 0 + others -> dataVer is the number at the end of the sentence */ var d = Data(); int i = 0;