public static void Metrics_Not_Sent_If_Array_Is_Null_Or_Empty()
        {
            // Arrange
            var mock   = new Mock <IStatsDTransport>();
            var config = new StatsDConfiguration();

            using (var publisher = new StatsDPublisher(config, mock.Object))
            {
                // Act
                publisher.Decrement(-1, 1, null as string[]);
                publisher.Increment(-1, 1, null as string[]);
                publisher.Decrement(1, 1, null as string[]);
                publisher.Increment(1, 1, null as string[]);
                publisher.Decrement(1, 1, Array.Empty <string>());
                publisher.Increment(1, 1, Array.Empty <string>());
                publisher.Decrement(-1, 1, Array.Empty <string>());
                publisher.Increment(-1, 1, Array.Empty <string>());
                publisher.Decrement(-1, 1, new List <string>());
                publisher.Increment(-1, 1, new List <string>());
                publisher.Decrement(1, 1, null as IEnumerable <string>);
                publisher.Increment(1, 1, null as IEnumerable <string>);
                publisher.Decrement(1, 1, new[] { string.Empty });
                publisher.Increment(1, 1, new[] { string.Empty });
            }

            // Assert
            mock.Verify((p) => p.Send(It.IsAny <ArraySegment <byte> >()), Times.Never());
        }
        public static void Metrics_Not_Sent_If_Array_Is_Null_Or_Empty()
        {
            // Arrange
            var mock   = new Mock <IStatsDTransport>();
            var config = new StatsDConfiguration();

            using (var publisher = new StatsDPublisher(config, mock.Object))
            {
                // Act
#nullable disable
                publisher.Decrement(-1, 1, null as string[]);
                publisher.Increment(-1, 1, null as string[]);
                publisher.Decrement(1, 1, null as string[]);
                publisher.Increment(1, 1, null as string[]);
                publisher.Decrement(1, 1, Array.Empty <string>());
                publisher.Increment(1, 1, Array.Empty <string>());
                publisher.Decrement(-1, 1, Array.Empty <string>());
                publisher.Increment(-1, 1, Array.Empty <string>());
                publisher.Decrement(-1, 1, new List <string>());
                publisher.Increment(-1, 1, new List <string>());
                publisher.Decrement(1, 1, null as IEnumerable <string>);
                publisher.Increment(1, 1, null as IEnumerable <string>);
                publisher.Decrement(1, 1, new[] { string.Empty });
                publisher.Increment(1, 1, new[] { string.Empty });
#nullable enable
            }
        public static void Increment_Sends_Multiple_Metrics()
        {
            // Arrange
            var mock = new Mock <IStatsDTransport>();

            var config = new StatsDConfiguration
            {
                Prefix = "red",
            };

            using (var publisher = new StatsDPublisher(config, mock.Object))
            {
                // Act
                publisher.Increment(10, "black");
                publisher.Increment(-10, "yellow");
                publisher.Increment(10, 1, "pink");
                publisher.Increment(-10, 1, "orange");
                publisher.Increment(10, 1, new[] { "white", "blue" });
                publisher.Increment(10, 1, new List <string>()
                {
                    "green", "red"
                });
                publisher.Increment(10, 1, null as IEnumerable <string>);
            }

            // Assert
            mock.Verify((p) => p.Send(It.Ref <ArraySegment <byte> > .IsAny), Times.Exactly(8));
        }
        public void ConfigurationIsValidWithHostIp()
        {
            var validConfig = new StatsDConfiguration
            {
                Host = "10.0.1.2"
            };

            using var stats = new StatsDPublisher(validConfig);
        }
        public void ConfigurationIsValidWithHostName()
        {
            var validConfig = new StatsDConfiguration
            {
                Host = "someserver.somewhere.com"
            };

            var stats = new StatsDPublisher(validConfig);

            stats.ShouldNotBeNull();
        }
        public void ConfigurationIsValidWithHostIp()
        {
            var validConfig = new StatsDConfiguration
            {
                Host = "10.0.1.2"
            };

            var stats = new StatsDPublisher(validConfig);

            stats.ShouldNotBeNull();
        }
Esempio n. 7
0
        public static void Metrics_Not_Sent_If_No_Metrics()
        {
            // Arrange
            var mock   = new Mock <IStatsDTransport>();
            var config = new StatsDConfiguration();

            var publisher = new StatsDPublisher(config, mock.Object);

            // Act
            publisher.Decrement(1, 0, new[] { "foo" });
            publisher.Increment(1, 0, new[] { "bar" });

            // Assert
            mock.Verify((p) => p.Send(It.IsAny <ArraySegment <byte> >()), Times.Never());
        }
        public static void Decrement_Sends_Multiple_Metrics()
        {
            // Arrange
            var mock = new Mock <IStatsDTransport>();

            var config = new StatsDConfiguration
            {
                Prefix = "red",
            };

            var publisher = new StatsDPublisher(config, mock.Object);

            // Act
            publisher.Decrement(10, 1, "white", "blue");

            // Assert
            mock.Verify((p) => p.Send(It.Ref <ArraySegment <byte> > .IsAny), Times.Exactly(2));
        }
Esempio n. 9
0
        public static async Task Can_Send_Metrics_To_StatsD_Using_Udp(
            string host,
            SocketProtocol socketProtocol)
        {
            Skip.If(Environment.GetEnvironmentVariable("CI") == null, "By default, this test is only run during continuous integration.");

            // Arrange
            var config = new StatsDConfiguration
            {
                Host           = host,
                Prefix         = Guid.NewGuid().ToString().Replace("-", string.Empty, StringComparison.Ordinal),
                SocketProtocol = socketProtocol,
            };

            using var publisher = new StatsDPublisher(config);

            // Act and Assert
            await AssertMetrics(config, publisher);
        }