Пример #1
0
        /// <summary>
        /// Comapre Time series details of recommendation action entity
        /// </summary>
        private static void CompareRecommendedActionMetricInfo(IList <RecommendedActionMetricInfo> expected, IList <RecommendedActionMetricInfo> response)
        {
            Assert.False(expected != null ^ response != null);

            if (response != null)
            {
                Assert.Equal(expected.Count, response.Count());

                foreach (RecommendedActionMetricInfo expectedMetric in expected)
                {
                    RecommendedActionMetricInfo responseMetric = response.FirstOrDefault(r => r.MetricName == expectedMetric.MetricName);
                    Assert.NotNull(responseMetric);
                    Assert.Equal(expectedMetric.MetricName, responseMetric.MetricName);
                    Assert.Equal(expectedMetric.Unit, responseMetric.Unit);
                    Assert.Equal(expectedMetric.StartTime, responseMetric.StartTime);
                    Assert.Equal(expectedMetric.TimeGrain.ToString(), responseMetric.TimeGrain);
                    Assert.Equal(expectedMetric.Value, responseMetric.Value);
                }
            }
        }
Пример #2
0
        internal static RecommendedActionData DeserializeRecommendedActionData(JsonElement element)
        {
            Optional <string>                                         kind                       = default;
            Optional <string>                                         location                   = default;
            ResourceIdentifier                                        id                         = default;
            string                                                    name                       = default;
            ResourceType                                              type                       = default;
            SystemData                                                systemData                 = default;
            Optional <string>                                         recommendationReason       = default;
            Optional <DateTimeOffset>                                 validSince                 = default;
            Optional <DateTimeOffset>                                 lastRefresh                = default;
            Optional <RecommendedActionStateInfo>                     state                      = default;
            Optional <bool>                                           isExecutableAction         = default;
            Optional <bool>                                           isRevertableAction         = default;
            Optional <bool>                                           isArchivedAction           = default;
            Optional <DateTimeOffset>                                 executeActionStartTime     = default;
            Optional <TimeSpan>                                       executeActionDuration      = default;
            Optional <DateTimeOffset>                                 revertActionStartTime      = default;
            Optional <TimeSpan>                                       revertActionDuration       = default;
            Optional <RecommendedActionInitiatedBy>                   executeActionInitiatedBy   = default;
            Optional <DateTimeOffset>                                 executeActionInitiatedTime = default;
            Optional <RecommendedActionInitiatedBy>                   revertActionInitiatedBy    = default;
            Optional <DateTimeOffset>                                 revertActionInitiatedTime  = default;
            Optional <int>                                            score                      = default;
            Optional <RecommendedActionImplementationInfo>            implementationDetails      = default;
            Optional <RecommendedActionErrorInfo>                     errorDetails               = default;
            Optional <IReadOnlyList <RecommendedActionImpactRecord> > estimatedImpact            = default;
            Optional <IReadOnlyList <RecommendedActionImpactRecord> > observedImpact             = default;
            Optional <IReadOnlyList <RecommendedActionMetricInfo> >   timeSeries                 = default;
            Optional <IReadOnlyList <string> >                        linkedObjects              = default;
            Optional <IReadOnlyDictionary <string, BinaryData> >      details                    = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    kind = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("recommendationReason"))
                        {
                            recommendationReason = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("validSince"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            validSince = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("lastRefresh"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            lastRefresh = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("state"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            state = RecommendedActionStateInfo.DeserializeRecommendedActionStateInfo(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("isExecutableAction"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isExecutableAction = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("isRevertableAction"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isRevertableAction = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("isArchivedAction"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isArchivedAction = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("executeActionStartTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            executeActionStartTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("executeActionDuration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            executeActionDuration = property0.Value.GetTimeSpan("P");
                            continue;
                        }
                        if (property0.NameEquals("revertActionStartTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            revertActionStartTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("revertActionDuration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            revertActionDuration = property0.Value.GetTimeSpan("P");
                            continue;
                        }
                        if (property0.NameEquals("executeActionInitiatedBy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            executeActionInitiatedBy = property0.Value.GetString().ToRecommendedActionInitiatedBy();
                            continue;
                        }
                        if (property0.NameEquals("executeActionInitiatedTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            executeActionInitiatedTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("revertActionInitiatedBy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            revertActionInitiatedBy = property0.Value.GetString().ToRecommendedActionInitiatedBy();
                            continue;
                        }
                        if (property0.NameEquals("revertActionInitiatedTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            revertActionInitiatedTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("score"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            score = property0.Value.GetInt32();
                            continue;
                        }
                        if (property0.NameEquals("implementationDetails"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            implementationDetails = RecommendedActionImplementationInfo.DeserializeRecommendedActionImplementationInfo(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("errorDetails"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            errorDetails = RecommendedActionErrorInfo.DeserializeRecommendedActionErrorInfo(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("estimatedImpact"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <RecommendedActionImpactRecord> array = new List <RecommendedActionImpactRecord>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(RecommendedActionImpactRecord.DeserializeRecommendedActionImpactRecord(item));
                            }
                            estimatedImpact = array;
                            continue;
                        }
                        if (property0.NameEquals("observedImpact"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <RecommendedActionImpactRecord> array = new List <RecommendedActionImpactRecord>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(RecommendedActionImpactRecord.DeserializeRecommendedActionImpactRecord(item));
                            }
                            observedImpact = array;
                            continue;
                        }
                        if (property0.NameEquals("timeSeries"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <RecommendedActionMetricInfo> array = new List <RecommendedActionMetricInfo>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(RecommendedActionMetricInfo.DeserializeRecommendedActionMetricInfo(item));
                            }
                            timeSeries = array;
                            continue;
                        }
                        if (property0.NameEquals("linkedObjects"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <string> array = new List <string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            linkedObjects = array;
                            continue;
                        }
                        if (property0.NameEquals("details"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            Dictionary <string, BinaryData> dictionary = new Dictionary <string, BinaryData>();
                            foreach (var property1 in property0.Value.EnumerateObject())
                            {
                                dictionary.Add(property1.Name, BinaryData.FromString(property1.Value.GetRawText()));
                            }
                            details = dictionary;
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new RecommendedActionData(id, name, type, systemData, kind.Value, location.Value, recommendationReason.Value, Optional.ToNullable(validSince), Optional.ToNullable(lastRefresh), state.Value, Optional.ToNullable(isExecutableAction), Optional.ToNullable(isRevertableAction), Optional.ToNullable(isArchivedAction), Optional.ToNullable(executeActionStartTime), Optional.ToNullable(executeActionDuration), Optional.ToNullable(revertActionStartTime), Optional.ToNullable(revertActionDuration), Optional.ToNullable(executeActionInitiatedBy), Optional.ToNullable(executeActionInitiatedTime), Optional.ToNullable(revertActionInitiatedBy), Optional.ToNullable(revertActionInitiatedTime), Optional.ToNullable(score), implementationDetails.Value, errorDetails.Value, Optional.ToList(estimatedImpact), Optional.ToList(observedImpact), Optional.ToList(timeSeries), Optional.ToList(linkedObjects), Optional.ToDictionary(details)));
        }