public async void LastKeyUploadInfoIsUpdated() { //Given string url = Conf.URL_PUT_UPLOAD_DIAGNOSIS_KEYS.Replace(ApiStubHelper.StubServerUrl, ""); List <DateTime> keyDates = new List <DateTime> { new DateTime(2020, 6, 1) }; List <ExposureKeyModel> temporaryExposureKeys = keyDates.Select( (key, i) => new ExposureKeyModel(new byte[i], key, TimeSpan.FromDays(1), RiskLevel.Medium)).ToList(); ApiStubHelper.StubServer .Given(Request.Create().WithPath(url).UsingPost()) .RespondWith( Response.Create() .WithStatusCode(200) ); // When string lastKeyUploadInfoBeforePush = _developerToolsService.LastKeyUploadInfo; bool isSuccess = await _exposureNotificationWebService.PostSelfExposureKeys( GetMockedSelDiagnosisSubmissionDTO(temporaryExposureKeys), temporaryExposureKeys); string lastKeyUploadInfoAfterPush = _developerToolsService.LastKeyUploadInfo; // Then Assert.Empty(lastKeyUploadInfoBeforePush); Assert.True(isSuccess); Assert.NotEqual(lastKeyUploadInfoBeforePush, lastKeyUploadInfoAfterPush); }
// === Methods used both by EN API v1 and EN API v2 === public async Task UploadSelfExposureKeysToServerAsync(IEnumerable <TemporaryExposureKey> tempKeys) { // Convert to ExposureKeyModel list as it is extended with DaysSinceOnsetOfSymptoms value IEnumerable <ExposureKeyModel> temporaryExposureKeys = tempKeys?.Select(key => new ExposureKeyModel(key)) ?? new List <ExposureKeyModel>(); if (FakeGatewayUtils.IsFakeGatewayTest) { FakeGatewayUtils.LastPulledExposureKeys = temporaryExposureKeys; return; } if (AuthenticationState.PersonalData?.Access_token == null) { throw new AccessTokenMissingFromIDPortenException("The token from ID Porten is not set"); } if (AuthenticationState.PersonalData?.VisitedCountries == null) { throw new VisitedCountriesMissingException( "The visited countries list is missing. Possibly garbage collection removed it."); } if (!DateToSetDSOS.HasValue) { throw new DSOSDateMissingException("The symptom onset date is not set from the calling view model"); } DateTime dateToSetDSOSAsUniversalTime = DateToSetDSOS.Value.ToUniversalTime(); List <ExposureKeyModel> validKeys = UploadDiagnosisKeysHelper.CreateAValidListOfTemporaryExposureKeys(temporaryExposureKeys); validKeys = UploadDiagnosisKeysHelper.SetTransmissionRiskAndDSOS(validKeys, dateToSetDSOSAsUniversalTime); bool success = await _exposureNotificationWebService.PostSelfExposureKeys(validKeys); if (!success) { throw new FailedToPushToServerException("Failed to push keys to the server"); } }
public async Task UploadSelfExposureKeysToServerAsync(IEnumerable <TemporaryExposureKey> tempKeys) { // Convert to ExposureKeyModel list as it is extended with DaysSinceOnsetOfSymptoms value IEnumerable <ExposureKeyModel> temporaryExposureKeys = tempKeys?.Select(key => new ExposureKeyModel(key)) ?? new List <ExposureKeyModel>(); // There is a better behaviour of uploading keys when scanning is Stoped/Started (UIAlert for permission is always shown then), // The IF-check just toggles the scanning status on/off or off/on to keep the scanning status // the same as it was before method is called try { if (ServiceLocator.Current.GetInstance <IDeviceInfo>().Platform == DevicePlatform.iOS) { if (await ExposureNotification.IsEnabledAsync()) { await ExposureNotification.StopAsync(); await ExposureNotification.StartAsync(); } else { await ExposureNotification.StartAsync(); await ExposureNotification.StopAsync(); } } } catch (Exception e) { if (!e.HandleExposureNotificationException(nameof(ExposureNotificationHandler), nameof(UploadSelfExposureKeysToServerAsync))) { throw e; } } if (FakeGatewayUtils.IsFakeGatewayTest) { FakeGatewayUtils.LastPulledExposureKeys = temporaryExposureKeys; return; } if (AuthenticationState.PersonalData?.Access_token == null) { throw new AccessTokenMissingFromIDPortenException("The token from ID Porten is not set"); } if (AuthenticationState.PersonalData?.VisitedCountries == null) { throw new VisitedCountriesMissingException( "The visited countries list is missing. Possibly garbage collection removed it."); } if (!MiBaDate.HasValue) { throw new MiBaDateMissingException("The symptom onset date is not set from the calling view model"); } DateTime MiBaDateAsUniversalTime = MiBaDate.Value.ToUniversalTime(); List <ExposureKeyModel> validKeys = UploadDiagnosisKeysHelper.CreateAValidListOfTemporaryExposureKeys(temporaryExposureKeys); // Here all keys are extended with DaysSinceOnsetOfSymptoms value validKeys = UploadDiagnosisKeysHelper.SetTransmissionRiskLevel(validKeys, MiBaDateAsUniversalTime); bool success = await exposureNotificationWebService.PostSelfExposureKeys(validKeys); if (!success) { throw new FailedToPushToServerException("Failed to push keys to the server"); } }