Exemplo n.º 1
0
 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"); });
 }
Exemplo n.º 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;
        }
Exemplo n.º 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
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        /// <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();
        }
Exemplo n.º 9
0
 /// <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);
Exemplo n.º 10
0
 /// <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);
Exemplo n.º 11
0
        /// <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);
Exemplo n.º 12
0
 public NotificationDto Notify(NotificationDto notificationDto, string sendingApplicationName)
 {
     return Notifier.Notify(notificationDto, sendingApplicationName).ToDto();
 }
Exemplo n.º 13
0
 static partial void OnDto(this Notification entity, NotificationDto dto)
 {
     dto.SentToSubscribers = (List <SubscriberDto>)entity.SentToSubscribers.ToDtos();
 }