public void Instantiate_Error_ReturnsFalse() { var newAlertArgs = new NewAlertEventArgs(); var result = newAlertArgs.Instantiate("Error Occurred"); Assert.IsFalse(result); }
public virtual void TryToGetAndSendNewSosOnlineAlerts(SirenOfShameSettings settings, DateTime now, Action <NewAlertEventArgs> invokeNewAlert) { if (!settings.GetSosOnlineContent()) { return; } bool weHaveAlreadyCheckedForAlertsToday = settings.LastCheckedForAlert != null && (now - settings.LastCheckedForAlert.Value).TotalHours < 24; if (weHaveAlreadyCheckedForAlertsToday) { return; } settings.LastCheckedForAlert = DateTime.Now; settings.Save(); var webClient = GetWebClient(); webClient.DownloadStringCompleted += (s, e) => { try { if (e.Error != null) { _log.Error("Error retrieving alert", e.Error); return; } NewAlertEventArgs args = new NewAlertEventArgs(); var successParsing = args.Instantiate(e.Result); if (successParsing) { if (settings.SoftwareInstanceId == null) { settings.SoftwareInstanceId = args.SoftwareInstanceId; settings.Save(); } if (settings.AlertClosed == null || args.AlertDate > settings.AlertClosed) { invokeNewAlert(args); } } } catch (Exception ex) { _log.Error("Error retrieving alert", ex); } }; string url = string.Format(SOS_URL + "/GetAlert?SirenEverConnected={0}&SoftwareInstanceId={1}&ServerType={2}&Version={3}", settings.SirenEverConnected, settings.SoftwareInstanceId, string.Join(",", settings.CiEntryPointSettings.Select(cip => cip.Name)), Application.ProductVersion ); webClient.DownloadStringAsync(new Uri(url)); }
public void Instantiate_ExtraArgs_Ignored() { var newAlertArgs = new NewAlertEventArgs(); var result = newAlertArgs.Instantiate("56\r\nhttp://www.google.com\r\nHello World\r\n633979872000000000\r\n\r\n\r\n\r\n\r\n"); Assert.IsTrue(result); Assert.AreEqual(56, newAlertArgs.SoftwareInstanceId); Assert.AreEqual("Hello World", newAlertArgs.Message); Assert.AreEqual("http://www.google.com", newAlertArgs.Url); }
public void Instantiate_ThreeArgsAllGood_ReturnsTrue() { var newAlertArgs = new NewAlertEventArgs(); var result = newAlertArgs.Instantiate(@"56 http://www.google.com Hello World 633979872000000000"); Assert.IsTrue(result); Assert.AreEqual(56, newAlertArgs.SoftwareInstanceId); Assert.AreEqual("Hello World", newAlertArgs.Message); Assert.AreEqual("http://www.google.com", newAlertArgs.Url); Assert.AreEqual(new DateTime(2010, 1, 2), newAlertArgs.AlertDate); }