/// <summary> /// Fetches all pacts and verifies them. Returns all test results. /// </summary> /// <param name="providerName">The name of the provider, as stated in the pacts.</param> /// <returns>Testresults. Use <seealso cref="ITestResult.Success" /> to check the results of each pact.</returns> public async Task <IEnumerable <ITestResult> > Verify(string providerName) { var repo = new PactRepo(configuration); var results = new List <ITestResult>(); foreach (var pact in repo.FetchAll(providerName)) { using (var server = new TestServer(new WebHostBuilder().UseStartup <TStartup>(pact, setup))) using (var client = server.CreateClient()) { var result = await pact.Verify(client); var args = new PactResultEventArgs(pact, result); Verified?.Invoke(this, args); if (!result.Success) { VerificationFailed?.Invoke(this, args); pact.Configuration.LogSafe(LogLevel.Error, $"Assertion failed:{Environment.NewLine}{result}{Environment.NewLine}"); } results.Add(result); } } if (!(DoNotGenerateOneDummyTestResultWhenNoPactsAreFound || results.Any())) { results.Add(new DummyTestResult()); } return(results); }
public override void OnVerificationFailed(FirebaseException exception) { IsVerificationSucceed = false; ErrorMessage = exception.Message; VerificationFailed?.Invoke(this, new EventArgs()); // This callback is invoked in an invalid request for verification is made, // for instance if the the phone number format is not valid. }
public async void VerifyRequirements() { LogHelper.Log("SystemVerificationService:VerifyRequirements:"); SystemVerificationErrorCode errorCode = SystemVerificationErrorCode.NoError; if (Debug.SimulatedVerificationError != SystemVerificationErrorCode.NoError) { errorCode = Debug.SimulatedVerificationError; } else if (!Environment.Is64BitOperatingSystem) { errorCode = SystemVerificationErrorCode.Not64BitSystem; } else if (!VerifyWindowsVersion()) { errorCode = SystemVerificationErrorCode.UnsupportedOS; } else if (!VerifyRAM()) { errorCode = SystemVerificationErrorCode.InsufficientRAM; } else if (!InitializeFrameworkService()) { errorCode = SystemVerificationErrorCode.UnsupportedFirmware; } else { try { if (!await Task.Run(() => CheckCPUCoresCount())) { errorCode = SystemVerificationErrorCode.SingleCoreProcessor; } else { await Task.Run(() => VerifyUSB30()); LogHelper.Log("SystemVerificationService:VerifyRequirements: Success"); } } catch (SystemVerificationException ex) { errorCode = ex.Code; } catch (Exception ex) { LogHelper.Log("SystemVerificationService:VerifyRequirements: Message: {0}", ex.Message); LogHelper.Log("SystemVerificationService:VerifyRequirements: StackTrace: {0}", ex.StackTrace); errorCode = SystemVerificationErrorCode.GenericVerificationError; } } if (errorCode == SystemVerificationErrorCode.NoError) { VerificationPassed?.Invoke(this, null); } else { LogHelper.Log("SystemVerificationService:VerifyRequirements: Error: {0}", errorCode); if (errorCode != SystemVerificationErrorCode.NotUSB30Port) { LogHelper.Flush(); } VerificationFailed?.Invoke(this, new EndlessErrorEventArgs <SystemVerificationErrorCode> { ErrorCode = errorCode }); } }
private void VerifyFiles() { while (true) { IndexedRemoteFileInfo indexedFileInfo; if (stopped) { break; } lock (locker) { indexedFileInfo = filesToCheck[0]; } RemoteFileInfo fileInfo = indexedFileInfo.FileInfo; bool checkFileHash = true; if (fileInfo.Compressed) { try { CompressionHelper.DecompressFile(downloadDirectory + fileInfo.GetFilePathWithCompression(), downloadDirectory + fileInfo.FilePath); File.Delete(downloadDirectory + fileInfo.GetFilePathWithCompression()); } catch (Exception ex) { // The SevenZip compressor doesn't define what exceptions // it might throw, so we'll just catch them all UpdaterLogger.Log("Decompressing file " + fileInfo.FilePath + " failed! Message: " + ex.Message); VerificationFailed?.Invoke(this, new IndexEventArgs(indexedFileInfo.Index)); queueReady = false; checkFileHash = false; } } if (checkFileHash) { if (!HashHelper.FileHashMatches(downloadDirectory + fileInfo.FilePath, fileInfo.UncompressedHash)) { UpdaterLogger.Log("File " + fileInfo.FilePath + " failed verification!"); VerificationFailed?.Invoke(this, new IndexEventArgs(indexedFileInfo.Index)); queueReady = false; } else { UpdaterLogger.Log("File " + fileInfo.FilePath + " passed verification."); } } bool waitingForWork = false; lock (locker) { filesToCheck.RemoveAt(0); waitingForWork = filesToCheck.Count == 0; waitHandle.Reset(); if (queueReady && waitingForWork) { Completed?.Invoke(this, EventArgs.Empty); break; } //if (stopped) //{ // filesToCheck.Clear(); // break; //} } if (waitingForWork) { waitHandle.WaitOne(); } } lock (locker) { waitHandle.Dispose(); waitHandle = null; } // We could also dispose of verifierTask, but it sounds like we don't need to bother // https://blogs.msdn.microsoft.com/pfxteam/2012/03/25/do-i-need-to-dispose-of-tasks/ // In case we'd still want to do it, it'd be safest for this class to have a function // for disposing the task (maybe this class could implement IDisposable), and the // user of this class would then call it }