public void ServerError() { CreateStubForLogin(); MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl(), "admin", "admin"); CreateStub("/admin/license", "GET", 500, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.errorJson.json")); bool isException = false; try { metadefenderCoreClient.GetCurrentLicenseInformation(); } catch (MetadefenderClientException) { isException = true; } Assert.True(isException); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/admin/license")); } ); }
public void ApiRedirectTest() { CreateStubForLogin(); MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl(), "admin", "admin"); HttpServer.Stub(x => x.CustomVerb("/admin/license", "GET")) .AddHeader("Content-Type", "application/json; charset=utf-8") .AddHeader("Location", "/admin/licenseRedirected") .WithStatus((HttpStatusCode)302); // the redirected resource HttpServer.Stub(x => x.CustomVerb("/admin/licenseRedirected", "GET")) .Return(GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.getCurrentLicenseInformation.getCurrentLicenseInformation_success.json")) .AddHeader("Content-Type", "application/json; charset=utf-8") .AddHeader("Location", "/admin/licenseRedirected") .WithStatus((HttpStatusCode)200); License result = metadefenderCoreClient.GetCurrentLicenseInformation(); Assert.AreEqual(3740, result.days_left); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/admin/license")); } ); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/admin/licenseRedirected")); } ); }
public void Success_withNewUnknownFields() { CreateStubForLogin(); MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl(), "admin", "admin"); CreateStub("/admin/license", "GET", 200, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.getCurrentLicenseInformation.getCurrentLicenseInformation_withNewUnknownFields.json")); License result = metadefenderCoreClient.GetCurrentLicenseInformation(); Assert.AreEqual(3740, result.days_left); Assert.AreEqual("OPSWAT, Inc.", result.licensed_to); Assert.AreEqual(10, result.max_agent_count); HttpServer.AssertWasCalled(x => { return(x.CustomVerb("GET", "/admin/license")); } ); }
private static void ShowApiInfo(string apiUrl, string apiUser, string apiUserPass) { MetadefenderCoreClient metadefenderCoreClient; try { metadefenderCoreClient = new MetadefenderCoreClient(apiUrl, apiUser, apiUserPass); Console.WriteLine("Metadefender client created. Session id is: " + metadefenderCoreClient.GetSessionId()); } catch (MetadefenderClientException e) { Console.WriteLine("Cannot login to this API. Error message: " + e.GetDetailedMessage()); return; } try { License license = metadefenderCoreClient.GetCurrentLicenseInformation(); Console.WriteLine("Licensed to: " + license.licensed_to); } catch (MetadefenderClientException e) { Console.WriteLine("Cannot get license details: " + e.GetDetailedMessage()); } try { List <EngineVersion> result = metadefenderCoreClient.GetEngineVersions(); Console.WriteLine("Fetched engine/database versions: " + result.Count); } catch (MetadefenderClientException e) { Console.WriteLine("Cannot get engine/database versions: " + e.GetDetailedMessage()); } try { ApiVersion apiVersion = metadefenderCoreClient.GetVersion(); Console.WriteLine("Api endpoint apiVersion: " + apiVersion.version); } catch (MetadefenderClientException e) { Console.WriteLine("Cannot get api endpoint version: " + e.GetDetailedMessage()); } try { List <ScanRule> scanRules = metadefenderCoreClient.GetAvailableScanRules(); Console.WriteLine("Available scan rules: " + scanRules.Count); } catch (MetadefenderClientException e) { Console.WriteLine("Cannot get available scan rules: " + e.GetDetailedMessage()); } try { metadefenderCoreClient.Logout(); Console.WriteLine("Client successfully logged out."); } catch (MetadefenderClientException e) { Console.WriteLine("Cannot log out: " + e.GetDetailedMessage()); } }