示例#1
0
        public async Task UpdateCurrentSample(PastWeekEligibleSample sample)
        {
            var standAloneServerTask = this.serverRepository.ReadPrimaryStandaloneAsync();

            // Reset Sample
            await this.sampleHistoryRepository.ResetCurrentSampleAsync(sample.ServerId);

            // Add the Arrival Rate sample hours to the table
            await this.sampleHistoryRepository.AddToCurrentSampleAsync(sample.ArrivalRateHours);

            // Add the Concurrency sample hours to the table
            await this.sampleHistoryRepository.AddToCurrentSampleAsync(sample.ConcurrencyHours);

            // Determine if we need to add standalone edds to sample history
            var standAloneServer = await standAloneServerTask;

            if (standAloneServer.HasValue)
            {
                var standAloneServerHours = sample.ArrivalRateHours.Select(h => new SampleHistory
                {
                    HourId   = h.HourId,
                    ServerId = standAloneServer.Value,
                    IsActiveArrivalRateSample = h.IsActiveArrivalRateSample
                }).ToList();
                await this.logger.LogVerboseAsync($"Sample Standalone server hours to be added - {standAloneServerHours.Count} -- {{ {string.Join(" | ", standAloneServerHours.Select(h => $"ID: {h.Id} - HourID: {h.HourId}"))} }}");

                await this.sampleHistoryRepository.AddToCurrentSampleAsync(standAloneServerHours);
            }
        }
        public async Task UpdateCurrentSample_EddsStandalone()
        {
            // Arrange
            var sample = new PastWeekEligibleSample()
            {
                ServerId         = 1,
                HourId           = 2,
                ArrivalRateHours = new[] { new SampleHistory() },
                ConcurrencyHours = new[] { new SampleHistory() }
            };

            // Edds is standalone
            var eddsStandaloneArtifactId = 123;

            this.serverRepositoryMock.Setup(m => m.ReadPrimaryStandaloneAsync()).ReturnsAsync(eddsStandaloneArtifactId);

            this.sampleHistoryRepositoryMock.Setup(m => m.ResetCurrentSampleAsync(sample.ServerId)).Returns(Task.Delay(1));
            this.sampleHistoryRepositoryMock.Setup(m => m.AddToCurrentSampleAsync(sample.ArrivalRateHours))
            .Returns(Task.Delay(1));
            this.sampleHistoryRepositoryMock.Setup(m => m.AddToCurrentSampleAsync(sample.ConcurrencyHours))
            .Returns(Task.Delay(1));
            this.sampleHistoryRepositoryMock.Setup(m =>
                                                   m.AddToCurrentSampleAsync(It.Is <List <SampleHistory> >(sh =>
                                                                                                           sh.Exists(h => h.ServerId == eddsStandaloneArtifactId))))
            .Returns(Task.Delay(1));

            // Act
            await this.userExperienceSampleService.UpdateCurrentSample(sample);

            // Assert
            this.serverRepositoryMock.VerifyAll();
            this.sampleHistoryRepositoryMock.VerifyAll();
        }
        public async Task UpdateCurrentSample_NoEddsStandalone()
        {
            // Arrange
            var sample = new PastWeekEligibleSample()
            {
                ServerId         = 1,
                HourId           = 2,
                ArrivalRateHours = new[] { new SampleHistory() },
                ConcurrencyHours = new[] { new SampleHistory() }
            };

            // No Standalone
            this.serverRepositoryMock.Setup(m => m.ReadPrimaryStandaloneAsync()).ReturnsAsync((int?)null);

            this.sampleHistoryRepositoryMock.Setup(m => m.ResetCurrentSampleAsync(sample.ServerId)).Returns(Task.Delay(1));
            this.sampleHistoryRepositoryMock.Setup(m => m.AddToCurrentSampleAsync(sample.ArrivalRateHours))
            .Returns(Task.Delay(1));
            this.sampleHistoryRepositoryMock.Setup(m => m.AddToCurrentSampleAsync(sample.ConcurrencyHours))
            .Returns(Task.Delay(1));

            // Act
            await this.userExperienceSampleService.UpdateCurrentSample(sample);

            // Assert
            this.serverRepositoryMock.VerifyAll();
            this.sampleHistoryRepositoryMock.VerifyAll();
        }
        public async Task UpdateSample()
        {
            var sample = new PastWeekEligibleSample();

            await this.userExperienceSampleService.UpdateCurrentSample(sample);

            Assert.Pass();
        }
        public async Task ScoreMetrics_Empty()
        {
            // Arrange
            // server
            var serverId         = 1;
            var serverArtifactId = 2;

            // hour
            var hourId = 9;
            var hour   = new Hour {
                Id = hourId, HourTimeStamp = DateTime.UtcNow
            };

            this.hourRepositoryMock.Setup(m => m.ReadAsync(hourId)).ReturnsAsync(hour);

            // parameters
            var category = new Category {
                HourId = hourId
            };
            var categoryScore = new CategoryScore
            {
                ServerId = serverId,
                Category = category,
                Server   = new Server {
                    ArtifactId = serverArtifactId, ServerId = serverId
                }
            };
            var metricDatas = new List <MetricData>();

            // scores
            var UXArrivalRateScore = Defaults.Scores.UserExperience;
            var UXConcurrencyScore = Defaults.Scores.UserExperience;
            var expectedResult     = (UXArrivalRateScore + UXConcurrencyScore) / 2;

            // sample
            var sample = new PastWeekEligibleSample {
                ServerId = serverId, HourId = hourId, ArrivalRateHours = new List <SampleHistory>(), ConcurrencyHours = new List <SampleHistory>()
            };

            this.userExperienceSampleServiceMock.Setup(m => m.CalculateSample(serverId, hourId)).ReturnsAsync(sample);
            this.userExperienceSampleServiceMock.Setup(m => m.UpdateCurrentSample(sample)).Returns(Task.Delay(1));

            // writing to userExperienceRatings
            this.userExperienceRatingsRepositoryMock.Setup(
                m => m.CreateAsync(serverArtifactId, UXArrivalRateScore, UXConcurrencyScore, hour.Id))
            .Returns(Task.CompletedTask);

            // report data
            this.serverAuditReporter.Setup(r => r.ReportServerAudits(categoryScore.Server, hour, It.Is <decimal>(d => d == expectedResult)))
            .Returns(Task.Delay(1));
            this.serverAuditReporter.Setup(r => r.FinalizeServerReports(categoryScore.Server, hour))
            .Returns(Task.Delay(1));
            this.serverAuditReporter.Setup(r => r.DeleteServerTempReportData(categoryScore.Server, hour)).Returns(Task.Delay(1));

            // Act
            var result = await this.userExperienceScoringLogic.ScoreMetrics(categoryScore, metricDatas);

            // Assert
            Assert.That(result, Is.EqualTo(expectedResult));
            this.mockRepository.VerifyAll();
        }
        public async Task ScoreMetrics(decimal uxArrivalRateScore, decimal uxConcurrencyScore)
        {
            // scores
            var UXArrivalRateScore = 98;
            var UXConcurrencyScore = 98;
            var expectedResult     = (UXArrivalRateScore + UXConcurrencyScore) / 2;

            // Arrange
            // server
            var serverId         = 1;
            var serverArtifactId = 2;

            // hour
            var hourId = 9;
            var hour   = new Hour {
                Id = hourId, HourTimeStamp = DateTime.UtcNow
            };

            this.hourRepositoryMock.Setup(m => m.ReadAsync(hourId)).ReturnsAsync(hour);
            var concurrencySampleHistoryHourId = 8;
            var arrivalRateSampleHistoryHourId = 7;
            var sampleConcurrencyHours         = new List <SampleHistory>
            {
                new SampleHistory
                {
                    HourId = concurrencySampleHistoryHourId,
                    IsActiveConcurrencySample = true,
                    IsActiveArrivalRateSample = true
                }
            };
            var sampleArrivalRateHours = new List <SampleHistory>
            {
                new SampleHistory {
                    HourId = arrivalRateSampleHistoryHourId, IsActiveArrivalRateSample = true
                }
            };

            var concurrencyMetricData = new List <MetricData> {
                new MetricData {
                    Score = UXConcurrencyScore
                }
            };
            var arrivalRateMetricData = new List <MetricData> {
                new MetricData {
                    Score = UXArrivalRateScore
                }
            };

            this.metricDataServiceMock
            .Setup(m => m.GetMetricData(It.Is <IList <int> >(list => list.Contains(concurrencySampleHistoryHourId)), serverId,
                                        CategoryType.UserExperience)).ReturnsAsync(concurrencyMetricData);
            this.metricDataServiceMock
            .Setup(m => m.GetMetricData(It.Is <IList <int> >(list => list.Contains(arrivalRateSampleHistoryHourId)), serverId,
                                        CategoryType.UserExperience)).ReturnsAsync(arrivalRateMetricData);


            var sample = new PastWeekEligibleSample
            {
                ServerId         = serverId,
                HourId           = hourId,
                ArrivalRateHours = sampleArrivalRateHours,
                ConcurrencyHours = sampleConcurrencyHours
            };

            // parameters
            var category = new Category {
                HourId = hourId
            };
            var categoryScore = new CategoryScore
            {
                ServerId = serverId,
                Category = category,
                Server   = new Server {
                    ArtifactId = serverArtifactId, ServerId = serverId
                }
            };
            var metricDatas = new List <MetricData>();

            this.userExperienceSampleServiceMock.Setup(m => m.CalculateSample(serverId, hourId)).ReturnsAsync(sample);
            this.userExperienceSampleServiceMock.Setup(m => m.UpdateCurrentSample(sample)).Returns(Task.Delay(1));

            // writing to userExperienceRatings
            this.userExperienceRatingsRepositoryMock.Setup(
                m => m.CreateAsync(serverArtifactId, UXArrivalRateScore, UXConcurrencyScore, hour.Id))
            .Returns(Task.CompletedTask);

            // report data
            this.serverAuditReporter.Setup(r => r.ReportServerAudits(categoryScore.Server, hour, It.IsAny <decimal>()))
            .Returns(Task.Delay(1));
            this.serverAuditReporter.Setup(r => r.FinalizeServerReports(categoryScore.Server, hour))
            .Returns(Task.Delay(1));
            this.serverAuditReporter.Setup(r => r.DeleteServerTempReportData(categoryScore.Server, hour)).Returns(Task.Delay(1));

            // Act
            var result = await this.userExperienceScoringLogic.ScoreMetrics(categoryScore, metricDatas);

            // Assert
            Assert.That(result, Is.EqualTo(expectedResult));
            this.hourRepositoryMock.VerifyAll();
            this.userExperienceSampleServiceMock.VerifyAll();
            this.userExperienceRatingsRepositoryMock.VerifyAll();
        }