public void CanRemoveCollector()
        {
            var registry  = new CollectorRegistry();
            var collector = new DummyCollector("collector", "metric");

            registry.Add(collector);

            var collector1 = new DummyCollector("collector1", "metric1");

            registry.Add(collector1);

            var res = registry.Remove(collector1);

            Assert.True(res);
            Assert.False(registry.TryGet("collector1", out var _));
            Assert.True(registry.TryGet("collector", out var _));
        }
        public void CopyToAddsCollectorToDestination()
        {
            var source      = new CollectorRegistry();
            var factory     = new MetricFactory(source);
            var destination = new CollectorRegistry();

            factory.CreateCounter("test_counter", string.Empty).Inc();

            source.CopyTo("test_counter", destination);
            Assert.True(destination.TryGet("test_counter", out _));
        }
        public void MoveToRemovesCollectorFromSource()
        {
            var source      = new CollectorRegistry();
            var factory     = new MetricFactory(source);
            var destination = new CollectorRegistry();

            factory.CreateCounter("test_counter", string.Empty).Inc();

            source.MoveTo("test_counter", destination);
            Assert.False(source.TryGet("test_counter", out _));
        }
        public void ShouldNotThrowOnRemoveByNameNonRegisteredCollector(string keyToRemove)
        {
            var registry  = new CollectorRegistry();
            var collector = new DummyCollector("collector", "metric");

            registry.Add(collector);

            var res = registry.Remove(keyToRemove);

            Assert.Equal(null, res);
            Assert.True(registry.TryGet("collector", out var _));
        }
        public void CanRemoveCollector()
        {
            var registry  = new CollectorRegistry();
            var collector = Substitute.For <ICollector>();

            collector.MetricNames.Returns(new[] { "metric" });
            collector.Configuration.Name.Returns("collector");
            registry.Add(collector);

            var collector1 = Substitute.For <ICollector>();

            collector1.MetricNames.Returns(new[] { "metric1" });
            collector1.Configuration.Name.Returns("metric1");
            registry.Add(collector1);

            var res = registry.Remove(collector1);

            Assert.True(res);
            Assert.False(registry.TryGet("metric1", out var _));
            Assert.True(registry.TryGet("collector", out var _));
        }