public async Task <IList <int> > CreateCategoryScoresForCategory(int categoryId) { var category = await this.categoryRepository.ReadAsync(categoryId); // Get list of compatible serverTypes for this metric type var compatibleServerTypes = ServerTypeMapper.GetServerTypes(category.CategoryType); var categoryScoresToCreate = new List <CategoryScore>(); if (ServerTypeMapper.GetServerTypes(category.CategoryType).Any()) { var servers = await this.serverRepository.ReadAllActiveAsync(); categoryScoresToCreate.AddRange(servers .Where(s => compatibleServerTypes.Any(st => s.ServerType == st)) .GroupBy(s => s.ServerIpAddress) .Select(sg => new CategoryScore { CategoryId = category.Id, ServerId = sg.OrderBy(s => s.ServerId).First().ServerId })); } else { categoryScoresToCreate.Add(new CategoryScore { CategoryId = category.Id }); } var categoryScores = await categoryScoresToCreate .Select(cs => this.categoryScoreRepository.CreateAsync(cs)) .WhenAllStreamed(); return(categoryScores.Select(cs => cs.Id).ToList()); }
public async Task <IList <int> > CreateMetricDatasForCategoryScores(int categoryScoreId) { var categoryScore = await this.categoryScoreRepository.ReadAsync(categoryScoreId); var category = await this.categoryRepository.ReadAsync(categoryScore.CategoryId); // Create the metrics var metrics = await this.CreateMetricsForHour(category.HourId, category.CategoryType); // Read the metrics that don't have metric datas/scores created for them if (categoryScore.ServerId.HasValue) { var server = await this.serverRepository.ReadAsync(categoryScore.ServerId.Value); return(await metrics .Where(m => ServerTypeMapper.GetServerTypes(m.MetricType).Contains(server.ServerType)) .Select(m => this.CreateMetricDatasForMetric(m.Id, server.ServerId)) .WhenAllStreamed()); } else { return(await metrics .Select(m => this.CreateMetricDatasForMetric(m.Id)) .WhenAllStreamed()); } }
[TestCase(MetricType.Ram, new[] { ServerType.Database })] // Temp fix public void ServerTypeMapper_GetServerTypes_MetricType(MetricType metricType, ServerType[] expecteServerTypes) { //Act var results = ServerTypeMapper.GetServerTypes(metricType); //Assert Assert.That(results.OrderBy(r => r), Is.EqualTo(expecteServerTypes.OrderBy(r => r))); }
public void ServerTypeMapper_GetServerTypes_CategoryType(CategoryType categoryType, ServerType[] expecteServerTypes) { //Act var results = ServerTypeMapper.GetServerTypes(categoryType); //Assert Assert.That(results.OrderBy(r => r), Is.EqualTo(expecteServerTypes.OrderBy(r => r))); }
public void ServerTypeMapper_GetServerTypes_CategoryType_CannotBeMapped() { //Act & Assert Assert.Throws <ArgumentException>(() => ServerTypeMapper.GetServerTypes((CategoryType)0), "CategoryType 0 cannot be mapped."); }