public void TestNotify_ApplicationNotRegistered_ReturnsErrorLogsFailure()
 {
     var service = new FoghornService();
     var notificationDto = new NotificationDto
         {
             NotificationMessage = "This is the message of the test notification.",
             NotificationTypeName = NotificationName + "1",
             NotificationTitle = "Notification Title"
         };
     Assert.Throws<ArgumentException>(delegate { service.Notify(notificationDto, "IncorrectApplication"); });
 }
Exemple #2
0
        public static Notification Notify(NotificationDto notificationDto, string sendingApplicationName)
        {
            var dataContext = new FoghornEntities();

            var sendingApplication =
                dataContext.SendingApplications.FirstOrDefault(x => x.SendingApplicationName == sendingApplicationName);

            if (sendingApplication == null)
            {
                var exception =
                    new ArgumentException("sendingApplicationName must match a previously registered SendingApplication",
                                          "sendingApplicationName");
                Logger.ErrorException(FailureMessage, exception);
                throw exception;
            }

            if (notificationDto == null)
            {
                var exception = new ArgumentException("notification must not be null", "notificationDto");
                Logger.ErrorException(FailureMessage, exception);
                throw exception;
            }

            if (notificationDto.Priority > 2) notificationDto.Priority = 2;
            if (notificationDto.Priority < -2) notificationDto.Priority = -2;

            var growlNotification = new Growl.Connector.Notification(sendingApplication.SendingApplicationName,
                                                                     notificationDto.NotificationTypeName,
                                                                     notificationDto.NotificationId.ToString(
                                                                         CultureInfo.InvariantCulture),
                                                                     notificationDto.NotificationTitle,
                                                                     notificationDto.NotificationMessage)
                {
                    Sticky = notificationDto.Sticky,
                    Priority = (Priority) notificationDto.Priority
                };

            var notification = notificationDto.ToEntity();
            foreach (var subscriber in sendingApplication.Subscribers)
            {
                var port = subscriber.Port.HasValue ? subscriber.Port.Value : Settings.Default.GrowlDefaultPort;
                var growlConnector = new GrowlConnector(subscriber.Password, subscriber.HostName, port);
                growlConnector.Notify(growlNotification);
                subscriber.NotificationsSent.Add(notification);
            }

            notification.SentDateTime = DateTime.UtcNow;
            notification.NotificationType =
                dataContext.NotificationTypes.FirstOrDefault(
                    x => x.NotificationTypeName == notificationDto.NotificationTypeName);
            dataContext.Notifications.Add(notification);
            dataContext.SaveChanges();
            return notification;
        }
Exemple #3
0
        public void TestNotify_ApplicationExists_NotificationSent()
        {
            var foghornClient =
                new ChannelFactory<IFoghornService>(new BasicHttpBinding(), new EndpointAddress(ServiceUrl)).CreateChannel();

            var notificationDto = new NotificationDto
                {
                    NotificationMessage = "This is the message of the test notification.",
                    NotificationTypeName = "Error",
                    NotificationTitle = "Notification Title",
                    Priority = 2,
                    Sticky = true
                };
            foghornClient.Notify(notificationDto, ApplicationTestName);

            //TODO: Add Assertions
        }
        /// <summary>
        /// Converts this instance of <see cref="Notification"/> to an instance of <see cref="NotificationDto"/>.
        /// </summary>
        /// <param name="entity"><see cref="Notification"/> to convert.</param>
        public static NotificationDto ToDto(this Notification entity)
        {
            if (entity == null) return null;

            var dto = new NotificationDto();

            dto.NotificationId = entity.NotificationId;
            dto.NotificationTitle = entity.NotificationTitle;
            dto.NotificationMessage = entity.NotificationMessage;
            dto.SentDateTime = entity.SentDateTime;
            dto.Priority = entity.Priority;
            dto.Sticky = entity.Sticky;

            entity.OnDto(dto);

            return dto;
        }
 public void TestNotify_SetUpConfigurationAndCallNotify_NotificationSentAndLogged()
 {
     TestRegisterSubscription_ApplicationExists_SubscriberRegistered();
     var service = new FoghornService();
     var notificationDto = new NotificationDto
         {
             NotificationMessage = "This is the message of the test notification.",
             NotificationTypeName = NotificationName + "1",
             NotificationTitle = "Notification Title",
             Sticky = true,
             Priority = 2
         };
     var notificationDtoReturned = service.Notify(notificationDto, ApplicationTestName);
     var notificationId = notificationDtoReturned.NotificationId;
     var dataContext = new FoghornEntities();
     var checkNotification = dataContext.Notifications.FirstOrDefault(x => x.NotificationId == notificationId);
     Assert.NotNull(checkNotification);
 }
        /// <summary>
        /// Converts this instance of <see cref="Notification"/> to an instance of <see cref="NotificationDto"/>.
        /// </summary>
        /// <param name="entity"><see cref="Notification"/> to convert.</param>
        public static NotificationDto ToDto(this Notification entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var dto = new NotificationDto();

            dto.NotificationId      = entity.NotificationId;
            dto.NotificationTitle   = entity.NotificationTitle;
            dto.NotificationMessage = entity.NotificationMessage;
            dto.SentDateTime        = entity.SentDateTime;
            dto.Priority            = entity.Priority;
            dto.Sticky = entity.Sticky;

            entity.OnDto(dto);

            return(dto);
        }
        /// <summary>
        /// Converts this instance of <see cref="NotificationDto"/> to an instance of <see cref="Notification"/>.
        /// </summary>
        /// <param name="dto"><see cref="NotificationDto"/> to convert.</param>
        public static Notification ToEntity(this NotificationDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            var entity = new Notification();

            entity.NotificationId      = dto.NotificationId;
            entity.NotificationTitle   = dto.NotificationTitle;
            entity.NotificationMessage = dto.NotificationMessage;
            entity.SentDateTime        = dto.SentDateTime;
            entity.Priority            = dto.Priority;
            entity.Sticky = dto.Sticky;

            dto.OnEntity(entity);

            return(entity);
        }
partial         static void OnDto(this Notification entity, NotificationDto dto)
        {
            dto.SentToSubscribers = (List<SubscriberDto>) entity.SentToSubscribers.ToDtos();
        }
 /// <summary>
 /// Invoked when <see cref="ToEntity"/> operation is about to return.
 /// </summary>
 /// <param name="dto"><see cref="NotificationDto"/> converted from <see cref="Notification"/>.</param>
 /// <param name="entity"><see cref="Notification"/> converted from <see cref="NotificationDto"/>.</param>
 static partial void OnEntity(this NotificationDto dto, Notification entity);
 /// <summary>
 /// Invoked when <see cref="ToDto"/> operation is about to return.
 /// </summary>
 /// <param name="dto"><see cref="NotificationDto"/> converted from <see cref="Notification"/>.</param>
 /// <param name="entity"><see cref="Notification"/> converted from <see cref="NotificationDto"/>.</param>
 static partial void OnDto(this Notification entity, NotificationDto dto);
        /// <summary>
        /// Invoked when <see cref="ToDto"/> operation is about to return.
        /// </summary>
        /// <param name="dto"><see cref="NotificationDto"/> converted from <see cref="Notification"/>.</param>
        /// <param name="entity"><see cref="Notification"/> converted from <see cref="NotificationDto"/>.</param>
partial         static void OnDto(this Notification entity, NotificationDto dto);
Exemple #12
0
 public NotificationDto Notify(NotificationDto notificationDto, string sendingApplicationName)
 {
     return Notifier.Notify(notificationDto, sendingApplicationName).ToDto();
 }
Exemple #13
0
 static partial void OnDto(this Notification entity, NotificationDto dto)
 {
     dto.SentToSubscribers = (List <SubscriberDto>)entity.SentToSubscribers.ToDtos();
 }