public void SendAlert_WhenInvoked_VerifyRequestContent()
        {
            var alert = new OpsGenieAlertRequest("Test alert")
            {
                Alias       = "nimator-failure",
                Description = "This is the rendered text from the check",
                Responders  = new[]
                {
                    new OpsGenieResponder
                    {
                        Type = OpsGenieResponderType.Team,
                        Name = "Some opsgenie team"
                    }
                },
                Tags = new[] { "Nimator", "Some failed layer" }
            };

            httpHandler
            .Setup(_ => _.CreateRequest(It.IsAny <string>()))
            .Returns((string url) => (HttpWebRequest)WebRequest.Create(url));

            string handledContent = null;

            httpHandler
            .Setup(_ => _.HandleRequest(It.IsAny <HttpWebRequest>(), It.IsAny <string>()))
            .Callback((HttpWebRequest r, string content) => { handledContent = content; });

            sut.SendAlert(alert);

            var expectedContent = JsonConvert.SerializeObject(alert);

            Assert.That(handledContent, Is.EqualTo(expectedContent));
        }
        public void SendAlert_WhenInvoked_VerifyHandleRequest()
        {
            var alert = new OpsGenieAlertRequest("some message");

            httpHandler
            .Setup(_ => _.CreateRequest(It.IsAny <string>()))
            .Returns((string url) => (HttpWebRequest)WebRequest.Create(url));

            sut.SendAlert(alert);

            httpHandler.Verify(_ => _.HandleRequest(It.IsAny <HttpWebRequest>(), It.IsAny <string>()), Times.Once);
        }
Beispiel #3
0
        /// <inheritdoc/>
        public void SendAlert(OpsGenieAlertRequest alert)
        {
            var request = httpHandler.CreateRequest(AlertUrl);

            request.Method = "POST";
            request.Headers[HeaderApiKeyName] = headerApiKeyValue;
            request.Accept      = ContentTypeJson;
            request.ContentType = ContentTypeJson;
            request.KeepAlive   = false;

            httpHandler.HandleRequest(request, JsonConvert.SerializeObject(alert));
        }
        public void Notify_WhenNimatorResultLevelBelowThreshold_VerifyDonotSendAlert()
        {
            var resultMock = new Mock <INimatorResult>();

            resultMock.Setup(r => r.Level).Returns(NotificationLevel.Error);

            settings.Threshold = NotificationLevel.Critical;

            var request = new OpsGenieAlertRequest("Some message");

            converter.Setup(_ => _.Convert(resultMock.Object)).Returns(request);

            sut.Notify(resultMock.Object);

            client.Verify(_ => _.SendAlert(request), Times.Never);
        }
        public void SendAlert_WhenInvoked_VerifyRequest()
        {
            var alert = new OpsGenieAlertRequest("some message");

            httpHandler
            .Setup(_ => _.CreateRequest(It.IsAny <string>()))
            .Returns((string url) => (HttpWebRequest)WebRequest.Create(url));

            HttpWebRequest handledRequest = null;

            httpHandler
            .Setup(_ => _.HandleRequest(It.IsAny <HttpWebRequest>(), It.IsAny <string>()))
            .Callback((HttpWebRequest r, string c) => { handledRequest = r; });

            sut.SendAlert(alert);

            Assert.That(handledRequest, Is.Not.Null);

            Assert.That(handledRequest.Method, Is.EqualTo("POST"));
            Assert.That(handledRequest.Headers["Authorization"], Is.EqualTo($"GenieKey { settings.ApiKey}"));
            Assert.That(handledRequest.Accept, Is.EqualTo("application/json"));
            Assert.That(handledRequest.ContentType, Is.EqualTo("application/json"));
            Assert.That(handledRequest.KeepAlive, Is.EqualTo(false));
        }