public void ApplicationHealthSerializationTest()
        {
            ApplicationHealth appHealth = this.random.CreateRandom <ApplicationHealth>();

            var deployedApplicationHealthState = new DeployedApplicationHealthState()
            {
                ApplicationName       = new Uri("fabric:/" + "testApp" + this.random.CreateRandom <string>()),
                NodeName              = "NodeName_" + this.random.CreateRandom <string>(),
                AggregatedHealthState = this.random.CreateRandom <HealthState>()
            };

            appHealth.DeployedApplicationHealthStates = new List <DeployedApplicationHealthState>()
            {
                deployedApplicationHealthState
            };

            var serviceHealthState = new ServiceHealthState()
            {
                ServiceName           = new Uri("fabric:/" + "testSvc" + this.random.CreateRandom <string>()),
                AggregatedHealthState = this.random.CreateRandom <HealthState>()
            };

            appHealth.ServiceHealthStates = new List <ServiceHealthState>()
            {
                serviceHealthState
            };

            TestUsingSerializer(this.Serializer, appHealth);
        }
Esempio n. 2
0
        /// <summary>
        /// Overloaded ToString function for formatting the output on the console.
        /// </summary>
        /// <param name="deployedApplicationHealthState"> Object of type DeployedApplicationHealthState </param>
        /// <returns>
        /// Returns formatted string.
        /// </returns>
        public static string ToString(DeployedApplicationHealthState deployedApplicationHealthState)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "ApplicationName", deployedApplicationHealthState.ApplicationName));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "NodeName", deployedApplicationHealthState.NodeName));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "AggregatedHealthState", deployedApplicationHealthState.AggregatedHealthState));
            strBuilder.Append(Environment.NewLine);

            return(strBuilder.ToString());
        }
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, DeployedApplicationHealthState obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize);
            if (obj.NodeName != null)
            {
                writer.WriteProperty(obj.NodeName, "NodeName", NodeNameConverter.Serialize);
            }

            if (obj.ApplicationName != null)
            {
                writer.WriteProperty(obj.ApplicationName, "ApplicationName", ApplicationNameConverter.Serialize);
            }

            writer.WriteEndObject();
        }