public void WithNotFound() { MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl()); string nonExistingHash = "61dffeaa728844adbf49eb090e4ece0e"; CreateStub("/hash/" + nonExistingHash, "GET", 200, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.fetchScanResultByHash.fetchScanResult_notFound.json")); bool isException = false; try { metadefenderCoreClient.FetchScanResultByHash(nonExistingHash); } catch (MetadefenderClientException) { isException = true; } Assert.True(isException); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/hash/" + nonExistingHash)); } ); }
public void WithError() { MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl()); string existingDataId = "61dffeaa728844adbf49eb090e4ece0e"; CreateStub("/hash/" + existingDataId, "GET", 500, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.errorJson.json")); bool isException = false; try { metadefenderCoreClient.FetchScanResultByHash(existingDataId); } catch (MetadefenderClientException) { isException = true; } Assert.True(isException); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/hash/" + existingDataId)); } ); }
public void WithoutDataId() { MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl()); bool isException = false; try { metadefenderCoreClient.FetchScanResultByHash(null); } catch (MetadefenderClientException) { isException = true; } Assert.True(isException); }
private static void FetchScanResultByHash(string apiUrl, string hash) { MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(apiUrl); try { FileScanResult result = metadefenderCoreClient.FetchScanResultByHash(hash); Console.WriteLine("Fetch result by file hash: " + result.process_info.result); if (result.process_info.post_processing != null) { Console.WriteLine("post processing: " + result.process_info.post_processing); } } catch (MetadefenderClientException e) { Console.WriteLine("Error during fetch scan by hash: " + e.GetDetailedMessage()); } }
public void Success() { MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl()); string existingHash = "e981b537cff14c3fbbba923d7a71ff2e"; CreateStub("/hash/" + existingHash, "GET", 200, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.fetchScanResultByHash.fetchScanResultByHash_success.json")); FileScanResult result = metadefenderCoreClient.FetchScanResultByHash(existingHash); Assert.AreEqual(existingHash, result.data_id); Assert.AreEqual("Allowed", result.process_info.result); Assert.AreEqual("Clean", result.scan_results.scan_all_result_a); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/hash/" + existingHash)); }); }