Exemple #1
0
        public async Task GetDeploymentsTest(int numDeployments)
        {
            // Arrange
            var deploymentsList   = new List <DeploymentServiceModel>();
            var deploymentMetrics = new DeploymentMetricsServiceModel(null, null)
            {
                DeviceMetrics = new Dictionary <DeploymentStatus, long>()
                {
                    { DeploymentStatus.Succeeded, 0 },
                    { DeploymentStatus.Pending, 0 },
                    { DeploymentStatus.Failed, 0 }
                }
            };

            for (var i = 0; i < numDeployments; i++)
            {
                deploymentsList.Add(new DeploymentServiceModel()
                {
                    Name             = DEPLOYMENT_NAME + i,
                    DeviceGroupId    = DEVICE_GROUP_ID + i,
                    DeviceGroupQuery = DEVICE_GROUP_QUERY + i,
                    PackageContent   = PACKAGE_CONTENT + i,
                    Priority         = PRIORITY + i,
                    Id                 = DEPLOYMENT_ID + i,
                    PackageType        = PackageType.EdgeManifest,
                    ConfigType         = CONFIG_TYPE,
                    CreatedDateTimeUtc = DateTime.UtcNow,
                    DeploymentMetrics  = deploymentMetrics
                });
            }

            this.deploymentsMock.Setup(x => x.ListAsync()).ReturnsAsync(
                new DeploymentServiceListModel(deploymentsList)
                );

            // Act
            var results = await this.deploymentsController.GetAsync();

            // Assert
            Assert.Equal(numDeployments, results.Items.Count);
            for (var i = 0; i < numDeployments; i++)
            {
                var result = results.Items[i];
                Assert.Equal(DEPLOYMENT_ID + i, result.DeploymentId);
                Assert.Equal(DEPLOYMENT_NAME + i, result.Name);
                Assert.Equal(DEVICE_GROUP_QUERY + i, result.DeviceGroupQuery);
                Assert.Equal(DEVICE_GROUP_ID + i, result.DeviceGroupId);
                Assert.Equal(PACKAGE_CONTENT + i, result.PackageContent);
                Assert.Equal(PRIORITY + i, result.Priority);
                Assert.Equal(PackageType.EdgeManifest, result.PackageType);
                Assert.Equal(CONFIG_TYPE, result.ConfigType);
                Assert.True((DateTimeOffset.UtcNow - result.CreatedDateTimeUtc).TotalSeconds < 5);
                Assert.Equal(5, result.Metrics.SystemMetrics.Count());
            }
        }
        public async Task GetDeploymentsTest(int numDeployments)
        {
            // Arrange
            var deploymentsList   = new List <DeploymentServiceModel>();
            var deploymentMetrics = new DeploymentMetricsServiceModel(null, null)
            {
                DeviceMetrics = new Dictionary <DeploymentStatus, long>()
                {
                    { DeploymentStatus.Succeeded, 0 },
                    { DeploymentStatus.Pending, 0 },
                    { DeploymentStatus.Failed, 0 },
                },
            };

            for (var i = 0; i < numDeployments; i++)
            {
                deploymentsList.Add(new DeploymentServiceModel()
                {
                    Name             = DeploymentName + i,
                    DeviceGroupId    = DeviceGroupId + i,
                    DeviceGroupQuery = DeviceGroupQuery + i,
                    PackageContent   = PackageContent + i,
                    Priority         = Priority + i,
                    Id                 = DeploymentId + i,
                    PackageType        = PackageType.EdgeManifest,
                    ConfigType         = ConfigurationType,
                    CreatedDateTimeUtc = DateTime.UtcNow,
                    DeploymentMetrics  = deploymentMetrics,
                });
            }

            this.deploymentsMock.Setup(x => x.ListFromStorageAsync()).ReturnsAsync(
                new DeploymentServiceListModel(deploymentsList));

            // Act
            var results = await this.controller.GetAsync();

            // Assert
            Assert.Equal(numDeployments, results.Items.Count);
            for (var i = 0; i < numDeployments; i++)
            {
                var result = results.Items[i];
                Assert.Equal(DeploymentId + i, result.DeploymentId);
                Assert.Equal(DeploymentName + i, result.Name);
                Assert.Equal(DeviceGroupQuery + i, result.DeviceGroupQuery);
                Assert.Equal(DeviceGroupId + i, result.DeviceGroupId);
                Assert.Equal(PackageContent + i, result.PackageContent);
                Assert.Equal(Priority + i, result.Priority);
                Assert.Equal(PackageType.EdgeManifest, result.PackageType);
                Assert.Equal(ConfigurationType, result.ConfigType);
                Assert.True((DateTimeOffset.UtcNow - result.CreatedDateTimeUtc).TotalSeconds < 5);
                Assert.Equal(5, result.Metrics.SystemMetrics.Count());
            }
        }
Exemple #3
0
        public DeploymentMetricsApiModel(DeploymentMetricsServiceModel metricsServiceModel)
        {
            this.SystemMetrics = new Dictionary <string, long>();

            this.SystemMetrics[APPLIED_METRICS_KEY]  = 0;
            this.SystemMetrics[TARGETED_METRICS_KEY] = 0;

            if (metricsServiceModel == null)
            {
                return;
            }

            this.CustomMetrics = metricsServiceModel.CustomMetrics;
            this.SystemMetrics = metricsServiceModel.SystemMetrics != null && metricsServiceModel.SystemMetrics.Count > 0 ?
                                 metricsServiceModel.SystemMetrics : this.SystemMetrics;
            this.DeviceStatuses = metricsServiceModel.DeviceStatuses;

            if (metricsServiceModel.DeviceMetrics != null)
            {
                this.SystemMetrics[SUCCESSFUL_METRICS_KEY] =
                    metricsServiceModel.DeviceMetrics[DeploymentStatus.Succeeded];
                this.SystemMetrics[FAILED_METRICS_KEY] =
                    metricsServiceModel.DeviceMetrics[DeploymentStatus.Failed];
                this.SystemMetrics[PENDING_METRICS_KEY] =
                    metricsServiceModel.DeviceMetrics[DeploymentStatus.Pending];
            }

            if (this.CustomMetrics != null)
            {
                // Override System metrics if custom metric contain same metrics
                if (this.CustomMetrics.ContainsKey(SUCCESSFUL_METRICS_KEY))
                {
                    this.SystemMetrics[SUCCESSFUL_METRICS_KEY] =
                        this.CustomMetrics[SUCCESSFUL_METRICS_KEY];
                    this.CustomMetrics.Remove(SUCCESSFUL_METRICS_KEY);
                }

                if (this.CustomMetrics.ContainsKey(FAILED_METRICS_KEY))
                {
                    this.SystemMetrics[FAILED_METRICS_KEY] =
                        this.CustomMetrics[FAILED_METRICS_KEY];
                    this.CustomMetrics.Remove(FAILED_METRICS_KEY);
                }

                if (this.CustomMetrics.ContainsKey(PENDING_METRICS_KEY))
                {
                    this.SystemMetrics[PENDING_METRICS_KEY] =
                        this.CustomMetrics[PENDING_METRICS_KEY];
                    this.CustomMetrics.Remove(PENDING_METRICS_KEY);
                }
            }
        }
Exemple #4
0
        public DeploymentMetricsApiModel(DeploymentMetricsServiceModel metricsServiceModel)
        {
            this.SystemMetrics = new Dictionary <string, long>();

            this.SystemMetrics[AppliedMetricsKey]  = 0;
            this.SystemMetrics[TargetedMetricsKey] = 0;

            if (metricsServiceModel == null)
            {
                return;
            }

            this.CustomMetrics = metricsServiceModel.CustomMetrics;
            this.SystemMetrics = metricsServiceModel.SystemMetrics != null && metricsServiceModel.SystemMetrics.Count > 0 ?
                                 metricsServiceModel.SystemMetrics : this.SystemMetrics;
            this.DeviceStatuses = metricsServiceModel.DeviceStatuses;

            if (metricsServiceModel.DeviceMetrics != null)
            {
                this.SystemMetrics[SuccessfulMetricsKey] =
                    metricsServiceModel.DeviceMetrics[DeploymentStatus.Succeeded];
                this.SystemMetrics[FailedMetricsKey] =
                    metricsServiceModel.DeviceMetrics[DeploymentStatus.Failed];
                this.SystemMetrics[PendingMetricsKey] =
                    metricsServiceModel.DeviceMetrics[DeploymentStatus.Pending];
            }

            if (this.CustomMetrics != null)
            {
                // Override System metrics if custom metric contain same metrics
                if (this.CustomMetrics.ContainsKey(SuccessfulMetricsKey))
                {
                    this.SystemMetrics[SuccessfulMetricsKey] =
                        this.CustomMetrics[SuccessfulMetricsKey];
                    this.CustomMetrics.Remove(SuccessfulMetricsKey);
                }

                if (this.CustomMetrics.ContainsKey(FailedMetricsKey))
                {
                    this.SystemMetrics[FailedMetricsKey] =
                        this.CustomMetrics[FailedMetricsKey];
                    this.CustomMetrics.Remove(FailedMetricsKey);
                }

                if (this.CustomMetrics.ContainsKey(PendingMetricsKey))
                {
                    this.SystemMetrics[PendingMetricsKey] =
                        this.CustomMetrics[PendingMetricsKey];
                    this.CustomMetrics.Remove(PendingMetricsKey);
                }
            }
        }