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); }
/// <summary> /// Overloaded ToString function for formatting the output on the console. /// </summary> /// <param name="serviceHealthState"> Object of type ServiceHealthState </param> /// <returns> /// Returns formatted string. /// </returns> public static string ToString(ServiceHealthState serviceHealthState) { var strBuilder = new StringBuilder(); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "ServiceName", serviceHealthState.ServiceName)); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "AggregatedHealthState", serviceHealthState.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, ServiceHealthState obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize); if (obj.ServiceName != null) { writer.WriteProperty(obj.ServiceName, "ServiceName", ServiceNameConverter.Serialize); } writer.WriteEndObject(); }