public void AddCollector_PerformanceCounterCollector_CollectorIsInCollectionOfConfig()
        {
            // Arrange
            var store            = NewDocumentStore(configureStore: ConfigureTestStore);
            var config           = new CollectorConfigStored();
            var configRepository = Substitute.For <ICollectorConfigRepository>();

            configRepository.Get(Arg.Any <string>()).Returns(config);

            // Act
            var collectorCommand = new Fixture().Build <AddPerformanceCounterCollectorToConfigCommand>()
                                   .Create();
            var collectorConfigService = new CollectorConfigService(configRepository);

            collectorConfigService.AddCollectorAsync(config.Id, collectorCommand);

            // Assert
            config.Collectors.Should().AllBeOfType <PerformanceCounterCollector>();
        }
        public void AddCollector_MsSqlCountCollector_CollectorIsInCollectionOfConfig()
        {
            // Arrange
            var store            = NewDocumentStore(configureStore: ConfigureTestStore);
            var config           = new CollectorConfigStored();
            var configRepository = Substitute.For <ICollectorConfigRepository>();

            configRepository.Get(Arg.Any <string>()).Returns(config);

            // Act
            var collectorCommand = new Fixture().Build <AddSqlCountCollectorToConfigCommand>()
                                   .With(w => w.SourceProvider, SqlCollectorSourceProvider.MsSql)
                                   .Create();
            var collectorConfigService = new CollectorConfigService(configRepository);

            collectorConfigService.AddCollectorAsync(config.Id, collectorCommand);

            // Assert
            config.Collectors.Should().AllBeOfType <Implementation.Collectors.Sql.MsSql.CountCollector>();
        }
        public void AddCollector_RestApiCollector_CollectorIsInCollectionOfConfig()
        {
            // Arrange
            var store            = NewDocumentStore(configureStore: ConfigureTestStore);
            var config           = new CollectorConfigStored();
            var configRepository = Substitute.For <ICollectorConfigRepository>();

            configRepository.Get(Arg.Any <string>()).Returns(config);

            // Act
            var collectorCommand = new Fixture().Build <AddRestApiCollectorToConfigCommand>()
                                   .With(x => x.RequestUri, "https://github.com/t0ms3n/monytor")
                                   .Create();
            var collectorConfigService = new CollectorConfigService(configRepository);

            collectorConfigService.AddCollectorAsync(config.Id, collectorCommand);

            // Assert
            config.Collectors.Should().AllBeOfType <RestApiCollector>();
        }
        public async Task Create_EmptyConfig_Success()
        {
            var store            = NewDocumentStore(configureStore: ConfigureTestStore);
            var uow              = new UnitOfWork(store);
            var configRepository = new CollectorConfigRepository(uow);

            var collectorConfigService = new CollectorConfigService(configRepository);
            var command = new CreateCollectorConfigCommand()
            {
                DisplayName      = "Test",
                SchedulerAgentId = "default"
            };

            uow.OpenSession();
            var id = await collectorConfigService.CreateCollectorConfigAsync(command);

            uow.SaveChanges();

            using (var session = store.OpenSession()) {
                var loadedConfig = session.Load <CollectorConfigStored>(id);
                loadedConfig.Should().NotBeNull();
                loadedConfig.DisplayName.Should().BeEquivalentTo(command.DisplayName);
            }
        }