public void FindTemplate_Remote_Test() { HttpRequestMessage request = new HttpRequestMessage(); request.RequestUri = new Uri("http://test:100/"); MockObjectRepository repo = new MockObjectRepository(); repo.InitializeFHIR2Repository(); repo.InitializeLCG(); ResourceReference reference = new ResourceReference(); reference.Reference = "http://test.com/FHIR/StructureDefinition/test"; MockWebClient webClient = new MockWebClient(); var dafPatientJson = Trifolia.Test.Helper.GetSampleContents("Trifolia.Test.DocSamples.daf-patient_struc_def.json"); StructureDefinition strucDef = (StructureDefinition)FhirParser.ParseResourceFromJson(dafPatientJson); webClient.ExpectContent("http://test.com/FHIR/StructureDefinition/test", dafPatientJson); var foundTemplate = Shared.FindTemplate(request, webClient, repo, reference); Assert.IsNotNull(foundTemplate); Assert.AreEqual(1, foundTemplate.Id); Assert.AreEqual(strucDef.Name, foundTemplate.Name); }
public void PrtgClient_Constructor_RetrievesPassHash() { var webClient = new MockWebClient(new PassHashResponse()); var client = new PrtgClient("prtg.example.com", "username", "password", AuthMode.Password, webClient); Assert.IsTrue(client.PassHash == "12345678"); }
public static PrtgClient Initialize_Client(IWebResponse response) { var webClient = new MockWebClient(response); var client = new PrtgClient("prtg.example.com", "username", "12345678", AuthMode.PassHash, webClient); return(client); }
public async Task AdminTool_RestartCore_CanWaitAsync() { var standardClient = Initialize_Client(new BasicResponse(string.Empty)); var webClient = new MockWebClient(new RestartPrtgCoreResponse()); var customClient = new PrtgClient(standardClient.Server, standardClient.UserName, standardClient.PassHash, AuthMode.PassHash, webClient); await customClient.RestartCoreAsync(true); }
public void SensorTotals_AllFields_HaveValues() { var webClient = new MockWebClient(new SensorTotalsResponse(new Items.SensorTotalsItem())); var client = new PrtgClient("prtg.example.com", "username", "12345678", AuthMode.PassHash, webClient); var result = client.GetSensorTotals(); Assert2.AllPropertiesAreNotDefault(result); }
protected NotificationAction GetNotificationAction() { var webClient = new MockWebClient(new NotificationActionResponse(new[] { new NotificationActionItem() })); var client = new PrtgClient("prtg.example.com", "username", "12345678", AuthMode.PassHash, webClient); return(client.GetNotificationActions().First()); }
private PrtgClient GetRestartProbeClient() { var standardClient = Initialize_Client(new BasicResponse(string.Empty)); var webClient = new MockWebClient(new RestartProbeResponse()); var customClient = new PrtgClient(standardClient.Server, standardClient.UserName, standardClient.PassHash, AuthMode.PassHash, webClient); return(customClient); }
public void PrtgClient_Constructor_CantRetrievePassHash() { var webClient = new MockWebClient(new PassHashResponse("PRTG Network Monitor is starting")); AssertEx.Throws <PrtgRequestException>( () => new PrtgClient("prtg.example.com", "username", "password", AuthMode.Password, webClient), "Could not retrieve PassHash from PRTG Server." ); }
public void Object_DeserializesSchedule() { var webClient = new MockWebClient(new SensorSettingsResponse()); var client = new PrtgClient("server", "username", "1234567890", AuthMode.PassHash, webClient); var properties = client.GetSensorProperties(1001); Assert.AreEqual("Weekdays Nights (17:00 - 9:00) [GMT+0800]", properties.Schedule.ToString(), "Schedule was not correct"); }
private static void CheckSequence(Request[] requests, Action <IWebClient> executeSequence) { // Success test var webClient = new MockWebClient(requests); executeSequence(webClient); webClient.CheckFinished(); // Test failure at each step for (var i = 0; i < requests.Length; ++i) { Assert.That(() => executeSequence(new MockWebClient(requests, i)), Throws.InstanceOf <LoginException>() .And.Property("Reason").EqualTo(LoginException.FailureReason.WebException)); } }
public void GetAsync_PageNotFound() { using (var mockClient = new MockWebClient()) using (var realClient = new HttpClientWrapper()) { var testUrl = new Uri("https://bsaber.com/wp-jsoasdfn/bsabasdfer-api/songs/"); WebUtils.Initialize(); using (var realResponse = realClient.GetAsync(testUrl).Result) using (var mockResponse = mockClient.GetAsync(testUrl).Result) { var test = realResponse.Content.ReadAsStringAsync().Result; Assert.AreEqual(realResponse.IsSuccessStatusCode, mockResponse.IsSuccessStatusCode); Assert.AreEqual(realResponse.StatusCode, mockResponse.StatusCode); Assert.AreEqual(realResponse.Content.ContentType, mockResponse.Content.ContentType); } } }
public void AdminTool_RestartProbe_CanWait() { var standardClient = Initialize_Client(new BasicResponse(string.Empty)); var webClient = new MockWebClient(new RestartProbeResponse()); var customClient = new PrtgClient(standardClient.Server, standardClient.UserName, standardClient.PassHash, AuthMode.PassHash, webClient); var count = 0; customClient.RestartProbe(null, true, probes => { count += probes.Count; return(false); }); Assert.AreEqual(2, count, "Callback was not called expected number of times"); }
public void Serializer_ThrowsInvalidEnum() { var webClient = new MockWebClient(new SensorResponse(new SensorItem(status: "banana", statusRaw: "8765"))); var client = new PrtgClient("prtg.example.com", "username", "password", AuthMode.PassHash, webClient); try { client.GetSensors(); } catch (Exception ex) { if (ex.Message != "Could not deserialize value '8765' as it is not a valid member of type 'PrtgAPI.Status'. Could not process XML '<status>banana</status><status_raw>8765</status_raw><message><div class=\"status\">OK<div class=\"moreicon\"></div></div></message>'") { throw; } } }
private void ExecuteSocketException(SocketError error) { var ctor = typeof(SocketException).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(int), typeof(EndPoint) }, null); var ex = (SocketException)ctor.Invoke(new object[] { (int)error, new IPEndPoint(new IPAddress(0x2414188f), 80) }); var response = new ExceptionResponse(ex); var webClient = new MockWebClient(response); var client = new PrtgClient("prtg.example.com", "username", "1234567890", AuthMode.PassHash, webClient); client.GetSensors(); }
public void WebClient_GetAsync_PageNotFound() { using (var mockClient = new MockWebClient()) using (var realClient = new WebClientWrapper()) { mockClient.Timeout = 5000; realClient.Timeout = 5000; realClient.ErrorHandling = ErrorHandling.ReturnEmptyContent; var testUrl = new Uri("https://bsaber.com/wp-jsoasdfn/bsabasdfer-api/songs/"); //WebUtils.Initialize(realClient); using (var realResponse = realClient.GetAsync(testUrl).Result) using (var mockResponse = mockClient.GetAsync(testUrl).Result) { var test = realResponse?.Content?.ReadAsStringAsync().Result; Assert.AreEqual(realResponse.IsSuccessStatusCode, mockResponse.IsSuccessStatusCode); Assert.AreEqual(realResponse.StatusCode, mockResponse.StatusCode); Assert.AreEqual(realResponse.Content?.ContentType, mockResponse.Content.ContentType); } } }
public void AdminTool_RestartCore_CanWait() { var standardClient = Initialize_Client(new BasicResponse(string.Empty)); RestartCoreStage lastCoreStage = RestartCoreStage.Shutdown; var webClient = new MockWebClient(new RestartPrtgCoreResponse()); var customClient = new PrtgClient(standardClient.Server, standardClient.UserName, standardClient.PassHash, AuthMode.PassHash, webClient); customClient.RestartCore(true, stage => { lastCoreStage = stage; if (stage == RestartCoreStage.Restart) return false; return true; }); Assert.AreEqual(RestartCoreStage.Restart, lastCoreStage, "Waiting did not stop after returning false"); }
public void FindTemplate_Local_RelativeUrl_Test() { HttpRequestMessage request = new HttpRequestMessage(); request.RequestUri = new Uri("http://test:100/"); MockObjectRepository repo = new MockObjectRepository(); repo.InitializeFHIR2Repository(); var ig = repo.FindOrAddImplementationGuide(repo.FindImplementationGuideType(MockObjectRepository.DEFAULT_FHIR_DSTU2_IG_TYPE_NAME), "Test IG"); var template = repo.GenerateTemplate("urn:oid:1.2.3.4", repo.FindTemplateType(MockObjectRepository.DEFAULT_FHIR_DSTU2_IG_TYPE_NAME, "Composition"), "Test Template", ig); ResourceReference reference = new ResourceReference(); reference.Reference = "StructureDefinition/" + template.Id; MockWebClient webClient = new MockWebClient(); var foundTemplate = Shared.FindTemplate(request, webClient, repo, reference); Assert.IsNotNull(foundTemplate); Assert.AreEqual(template.Id, foundTemplate.Id); Assert.AreEqual(template.Name, foundTemplate.Name); Assert.AreEqual(0, webClient.RequestCount); }
public void TestCheckUpdateWithoutUUID() { // If HKEY_LOCAL_MACHINE\Software\Citrix\XenTools\AutoUpdate Identify == NO // Make a call to the specified URL without including the UUID var xsdict = new Dictionary <string, string>(); var brandingdict = new Dictionary <string, string>(); var regdict = new Dictionary <string, Dictionary <string, string> >(); brandingdict.Add("BRANDING_updaterURL", "http://127.0.0.1/updates.tsv"); brandingdict.Add("BRANDING_userAgent", "UnitTest"); xsdict.Add("/guest_agent_features/Guest_agent_auto_update/licensed", "1"); xsdict.Add("/guest_agent_features/Guest_agent_auto_update/parameters/enabled", "1"); xsdict.Add("/guest_agent_features/Guest_agent_auto_update/parameters/update_url", null); xsdict.Add("/guest_agent_features/Guest_agent_auto_update/parameters/allow-driver-install", "NO"); xsdict.Add("data/xd/present", "0"); xsdict.Add("vm", "/vm/11111111-1111-1111-1111-111111111111"); regdict.Add("HKEY_LOCAL_MACHINE\\Software\\Citrix\\XenTools\\AutoUpdate", new Dictionary <string, string>()); regdict["HKEY_LOCAL_MACHINE\\Software\\Citrix\\XenTools\\AutoUpdate"].Add("Identify", "NO"); Version nv = new Version(6, 6, 0, 1); var au = new AutoUpdate(new MockXenStoreItemFactory(xsdict), new MockBranding(brandingdict), new MockGetReg(regdict)); au.version = nv; MockWebClient wc = new MockWebClient(); au.CheckForUpdates(wc); Assert.AreEqual(wc.setUserAgent, true); Assert.AreEqual(wc.setUserAgentUnitTest, true); Assert.AreEqual(wc.urlhasid, false); }
public async Task SensorTotals_CanExecuteAsync() { var webClient = new MockWebClient(new SensorTotalsResponse(new SensorTotalsItem())); var client = new PrtgClient("prtg.example.com", "username", "12345678", AuthMode.PassHash, webClient); await client.GetSensorTotalsAsync(); }
public MockViewModel() { WebClient = new MockWebClient(); }
public void PrtgClient_Constructor_CantRetrievePassHash() { var webClient = new MockWebClient(new PassHashResponse("PRTG Network Monitor is starting")); var client = new PrtgClient("prtg.example.com", "username", "password", AuthMode.Password, webClient); }