コード例 #1
0
        [TestCase(Int32.MaxValue)] // Represents some yet unknown NotifcationLevel
        public void Notify_WhenPassedResultAtThreshold_WillCallWriteLine(NotificationLevel level)
        {
            fakeSettings.Threshold = level;
            var sut        = new ConsoleNotifier(fakeSettings, fakeWriteLine);
            var resultMock = new Mock <INimatorResult>();

            resultMock.Setup(r => r.Level).Returns(fakeSettings.Threshold);
            resultMock.Setup(r => r.RenderPlainText(level)).Returns(level.ToString());

            sut.Notify(resultMock.Object);

            Assert.That(lastWrittenLine, Is.EqualTo(level.ToString()));
        }
コード例 #2
0
        public void DefaultInstance_WhenGetName_ReturnsSensibleName(NotificationLevel level)
        {
            var sut = new NoopCheck(new NoopCheckSettings {
                LevelToSimulate = level
            });

            Assert.That(sut.ShortName, Is.Not.Null.And.Not.Empty);
            Assert.That(sut.ShortName, Does.Contain(level.ToString()));
        }
コード例 #3
0
        private DataDogEvent ConvertToDataDogEvent(NotificationLevel level, string layerName, string checkName, params string[] messages)
        {
            var dataDogEvent = new DataDogEvent
            {
                StatName = MetricsName,
                Title = checkName,
                AlertType = ConvertToAlertType(level)
            };

            var message = string.Join(Environment.NewLine, messages);
            message = message.Truncate(settings.MessageLengthLimit);
            dataDogEvent.Message = message;

            dataDogEvent.AddTag("check", checkName);
            dataDogEvent.AddTag("layer", layerName);
            dataDogEvent.AddTag("level", level.ToString());

            return dataDogEvent;
        }
コード例 #4
0
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (NotificationLevel != null)
            {
                p.Add(new KeyValuePair <string, string>("NotificationLevel", NotificationLevel.ToString()));
            }

            if (LastConsumedMessageIndex != null)
            {
                p.Add(new KeyValuePair <string, string>("LastConsumedMessageIndex", LastConsumedMessageIndex.ToString()));
            }

            if (LastConsumptionTimestamp != null)
            {
                p.Add(new KeyValuePair <string, string>("LastConsumptionTimestamp", Serializers.DateTimeIso8601(LastConsumptionTimestamp)));
            }

            return(p);
        }
コード例 #5
0
        private void ShowNotification(NotificationLevel level, string message, string heading)
        {
            var settings       = new NotificationSettings(string.IsNullOrWhiteSpace(heading) ? level.ToString("G") : heading, message, $"notification-{level.ToString("G").ToLower()}");
            var notificationId = Guid.NewGuid();
            var notification   = new RenderFragment(b => {
                b.OpenComponent <NotificationComponent>(0);
                b.AddAttribute(1, "NotificationSettings", settings);
                b.AddAttribute(2, "NotificationId", notificationId);
                b.CloseComponent();
            });

            NotificationList.Add(notificationId, notification);

            var notificationTimer = new Timer(5000);

            notificationTimer.Elapsed  += (sender, args) => { RemoveNotification(notificationId); };
            notificationTimer.AutoReset = false;
            notificationTimer.Start();

            StateHasChanged();
        }