Exemple #1
0
        public void FailingSend_ThrowsException()
        {
            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <double>())).Throws <Exception>();
            var graphite = new Graphite(_log, _settings, mockClient.Object);

            Assert.Throws <Exception>(() => { graphite.Send("test", 1); });
        }
Exemple #2
0
        public void Send_Datapoint_Works()
        {
            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <Datapoint[]>()));
            _settings.ThrowExceptions = true;
            var graphite = new Graphite(_log, _settings, mockClient.Object);

            Assert.DoesNotThrow(() => { graphite.Send(new Datapoint("test", 1, DateTime.UtcNow)); });
        }
Exemple #3
0
        public void Send_Works()
        {
            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <double>()));
            _settings.ThrowExceptions = true;
            var graphite = new Graphite(_log, _settings, mockClient.Object);

            Assert.DoesNotThrow(() => { graphite.Send("test", 1); });
        }
Exemple #4
0
        public void NonAnsweringHost_ThrowsException()
        {
            _settings.ThrowExceptions = true;

            try
            {
                _graphite.Send("test", 1);
                Assert.Fail($"{nameof(NonAnsweringHost_ThrowsException)} should have thrown an exception");
            }
            catch
            {
                Assert.Pass();
            }
        }
Exemple #5
0
        public void SendingWithPrefix_Works()
        {
            const string prefix         = "prefix_test";
            const string testMetricName = "test";
            string       returnValue    = null;
            var          expectedName   = $"{prefix}.{testMetricName}";

            _settings.Prefix = prefix;

            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <double>()))
            .Callback((string metricName, double value) => { returnValue = metricName; });

            var graphite = new Graphite(_log, _settings, mockClient.Object);

            graphite.Send(testMetricName, 1);

            Assert.IsNotNull(returnValue);
            Assert.AreEqual(returnValue, expectedName);
        }
Exemple #6
0
        public void SendingDatapointWithPrefix_Works()
        {
            const string prefix         = "prefix_test";
            const string testMetricName = "test";
            string       returnValue    = null;
            var          expectedName   = $"{prefix}.{testMetricName}";

            _settings.Prefix = prefix;

            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <ICollection <Datapoint> >()))
            .Callback((ICollection <Datapoint> x) => { returnValue = x.First().Series; });
            mockClient.Setup(x => x.Send(It.IsAny <Datapoint>()))
            .Callback((Datapoint[] x) => { returnValue = x[0].Series; });

            var graphite = new Graphite(_log, _settings, mockClient.Object);

            graphite.Send(new Datapoint(testMetricName, 1, DateTime.Now));

            Assert.IsNotNull(returnValue);
            Assert.AreEqual(expectedName, returnValue);
        }