/// <summary> /// Засоряет информационное пространство ненужными уведомлениями. Получает сообщения и выводит уведомление, полагаясь на пользовательские настройки. /// </summary> /// <returns></returns> public bool IncreaseEntropy() { Notification notification = new Notification(); bool hasNewMessages = false; if (!isInit) return false; if (!brainsMessageReceiver.IsLogged()) return false; brainsMessageReceiver.RetrieveMessages(); notification.ClearMsgQueue(); while (brainsMessageReceiver.GetMessagesCount() > 0) { Message message = brainsMessageReceiver.PopFirstMsg(); if (message == null) break; if ((message.MsgType == MsgTypes.Personal) && (notifyAboutPersonal == false)) continue; if ((message.MsgType == MsgTypes.Dialog) && (notifyAboutDialogs == false)) continue; if ((message.MsgType == MsgTypes.Group) && (notifyAboutGroups == false)) continue; if (!lastIds.Contains(message.Id)) { lastIds.Add(message.Id); brainsAllMessagesForm.AddMessage(message); hasNewMessages = true; } notification.AddMessage(message); } if (hasNewMessages == true) if (notification.BuildNotification()) brainsNotifier.ShowNotification(notification); return true; }
public void NotificationUrl_ExceptionOnNull() { Notification notification = new Notification(); notification.NotificationUrl = null; }
/// <summary> /// Показывает уведомление, если объект инициализирован. /// </summary> /// <param name="n">The n.</param> /// <returns></returns> public bool ShowNotification(Notification n) { if (ni == null) return false; ni.Text = havenewText; ni.Icon = Properties.Resources.NewMessage; launchUrl = n.NotificationUrl; if (string.IsNullOrEmpty(n.NotificationText)) { if (string.IsNullOrEmpty(n.NotificationHeader)) ni.ShowBalloonTip(9000, "", defaultText, ToolTipIcon.Info); else ni.ShowBalloonTip(9000, "", n.NotificationHeader, ToolTipIcon.Info); } else ni.ShowBalloonTip(9000, n.NotificationHeader, n.NotificationText, ToolTipIcon.Info); return true; }
public void NotificationHeader_ExceptionOnNull() { Notification notification = new Notification(); notification.NotificationHeader = null; }
public void NotificationText_ExceptionOnNull() { Notification notification = new Notification(); notification.NotificationText = null; }
public void Correct_Property_Values() { Notification notification = new Notification(); string notificationHeader = "1"; string notificationText = "2"; string notificationUrl = "3"; notification.NotificationHeader = notificationHeader; notification.NotificationText = notificationText; notification.NotificationUrl = notificationUrl; Assert.AreEqual(notificationHeader, notification.NotificationHeader); Assert.AreEqual(notificationText, notification.NotificationText); Assert.AreEqual(notificationUrl, notification.NotificationUrl); }
public void BuildNotification_Correctly_Works_With_Messages_Of_One_Type() { Notification notification = new Notification(); Message msg1 = new Message(); Message msg2 = new Message(); msg1.DomainUrl = "msg1.DomainUrl"; msg1.MsgText = "msg1.MsgText"; msg1.MsgUrl = "msg1.MsgUrl"; msg1.SenderName = "msg1.SenderName"; msg2.DomainUrl = "msg2.DomainUrl"; msg2.MsgText = "msg2.MsgText"; msg2.MsgUrl = "msg2.MsgUrl"; msg2.SenderName = "msg2.SenderName"; // Разные domainUrl, тип сообщения Personal msg1.MsgType = MsgTypes.Personal; msg2.MsgType = MsgTypes.Personal; notification.ClearMsgQueue(); notification.AddMessage(msg1); notification.AddMessage(msg2); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/im", notification.NotificationUrl); // Разные domainUrl, тип сообщения Dialog msg1.MsgType = MsgTypes.Dialog; msg2.MsgType = MsgTypes.Dialog; notification.ClearMsgQueue(); notification.AddMessage(msg1); notification.AddMessage(msg2); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/im", notification.NotificationUrl); // Разные domainUrl, тип сообщения Group msg1.MsgType = MsgTypes.Group; msg2.MsgType = MsgTypes.Group; notification.ClearMsgQueue(); notification.AddMessage(msg1); notification.AddMessage(msg2); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/groups", notification.NotificationUrl); //Устанавливаем общий domainUrl msg2.DomainUrl = msg1.DomainUrl; // Один domainUrl, тип сообщения Personal msg1.MsgType = MsgTypes.Personal; msg2.MsgType = MsgTypes.Personal; notification.ClearMsgQueue(); notification.AddMessage(msg1); notification.AddMessage(msg2); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual(msg1.DomainUrl, notification.NotificationUrl); // Один domainUrl, тип сообщения Dialog msg1.MsgType = MsgTypes.Dialog; msg2.MsgType = MsgTypes.Dialog; notification.ClearMsgQueue(); notification.AddMessage(msg1); notification.AddMessage(msg2); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual(msg1.DomainUrl, notification.NotificationUrl); // Один domainUrl, тип сообщения Group msg1.MsgType = MsgTypes.Group; msg2.MsgType = MsgTypes.Group; notification.ClearMsgQueue(); notification.AddMessage(msg1); notification.AddMessage(msg2); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual(msg1.DomainUrl, notification.NotificationUrl); }
public void Constructor_PropertiesNotNull_Tests() { Notification notification = new Notification(); Assert.IsNotNull(notification.NotificationHeader); Assert.IsNotNull(notification.NotificationText); Assert.IsNotNull(notification.NotificationUrl); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("", notification.NotificationText); Assert.AreEqual("", notification.NotificationUrl); }
public void ClearMsgQueue_Makes_BuildNotification_False() { Notification notification = new Notification(); Message message = new Message(); Assert.IsFalse(notification.BuildNotification()); message.DomainUrl = "1"; message.MsgText = "2"; message.MsgUrl = "3"; message.SenderName = "4"; notification.AddMessage(message); Assert.IsTrue(notification.BuildNotification()); Assert.AreNotEqual("", notification.NotificationHeader); Assert.AreNotEqual("", notification.NotificationText); Assert.AreNotEqual("", notification.NotificationUrl); notification.ClearMsgQueue(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("", notification.NotificationText); Assert.AreEqual("", notification.NotificationUrl); Assert.IsFalse(notification.BuildNotification()); }
public void BuildNotification_Correctly_Works_With_Single_Message_And_Different_Message_Type() { Notification notification = new Notification(); Message messagePersonal = new Message(); Message messageDialog = new Message(); Message messageGroup = new Message(); messagePersonal.MsgType = MsgTypes.Personal; messagePersonal.SenderName = "PersonA"; messagePersonal.MsgText = "BLAHblahBLAH"; messagePersonal.MsgUrl = "http://example.com/A/123"; messagePersonal.DomainUrl = "http://example.com/A"; notification.AddMessage(messagePersonal); notification.BuildNotification(); Assert.AreEqual(messagePersonal.SenderName, notification.NotificationHeader); Assert.AreEqual(messagePersonal.MsgText, notification.NotificationText); Assert.AreEqual(messagePersonal.MsgUrl, notification.NotificationUrl); messageDialog.MsgType = MsgTypes.Dialog; messageDialog.SenderName = "PersonB"; messageDialog.MsgText = "HALBhalbHALB"; messageDialog.MsgUrl = "http://example.com/B/456"; messageDialog.DomainUrl = "http://example.com/B"; notification.ClearMsgQueue(); notification.AddMessage(messageDialog); notification.BuildNotification(); Assert.AreEqual(messageDialog.SenderName, notification.NotificationHeader); Assert.AreEqual(messageDialog.MsgText, notification.NotificationText); Assert.AreEqual(messageDialog.MsgUrl, notification.NotificationUrl); messageGroup.MsgType = MsgTypes.Group; messageGroup.SenderName = "PersonA"; messageGroup.MsgText = "BLAHblahBLAH"; messageGroup.MsgUrl = "http://example.com/C/456"; messageGroup.DomainUrl = "http://example.com/C"; notification.ClearMsgQueue(); notification.AddMessage(messageGroup); notification.BuildNotification(); Assert.AreEqual(messageGroup.SenderName, notification.NotificationHeader); Assert.AreEqual(messageGroup.MsgText, notification.NotificationText); Assert.AreEqual(messageGroup.MsgUrl, notification.NotificationUrl); notification.ClearMsgQueue(); notification.AddMessage(messagePersonal); notification.AddMessage(messageDialog); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/", notification.NotificationUrl); notification.ClearMsgQueue(); notification.AddMessage(messagePersonal); notification.AddMessage(messageGroup); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/", notification.NotificationUrl); notification.ClearMsgQueue(); notification.AddMessage(messageDialog); notification.AddMessage(messageGroup); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 2 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/", notification.NotificationUrl); notification.ClearMsgQueue(); notification.AddMessage(messageDialog); notification.AddMessage(messagePersonal); notification.AddMessage(messageGroup); notification.BuildNotification(); Assert.AreEqual("", notification.NotificationHeader); Assert.AreEqual("У вас 3 непрочитанных сообщений", notification.NotificationText); Assert.AreEqual("https://vk.com/", notification.NotificationUrl); }