Ejemplo n.º 1
0
        public void Serialize_onecall()
        {
            var filename = "./Resources/DarkSky_onecall_SI.json";
            var client   = new WeatherServiceBase_Wrapper();

            Forecast input = null;

            using (var jsonStream = File.OpenRead(filename)) {
                input = client.ParseJsonFromStream_Wrapper <Forecast>(jsonStream);
            }

            string outputJson = null;

            using (var sw = new StringWriter())
                using (var jw = new JsonTextWriter(sw)) {
                    var serializer = new JsonSerializer();
                    serializer.NullValueHandling = NullValueHandling.Ignore;
                    serializer.ContractResolver  = new DefaultContractResolver {
                        NamingStrategy = new CamelCaseNamingStrategy()
                    };
                    //serializer.Formatting = Formatting.Indented;
                    //serializer.Converters.Add(new MyAlertConverter());
                    serializer.Serialize(jw, input);
                    outputJson = sw.ToString();
                }
            outputJson.ShouldNotBeNullOrWhiteSpace();
            outputJson.Length.ShouldBeGreaterThan(32);
            outputJson[0].ShouldBe('{');
            outputJson[outputJson.Length - 1].ShouldBe('}');
            outputJson[outputJson.Length - 1].ShouldBe('}');
            outputJson.ShouldContain("\"lat\":");
            outputJson.ShouldContain("\"currently\":");
        }
Ejemplo n.º 2
0
        public void Serialize_OpenW_currentWeather()
        {
            var filename = "./Resources/OpenW_currentweather_SI.json";
            var client   = new WeatherServiceBase_Wrapper();

            MultiWeatherApi.OpenWeather.Model.WeatherConditions input = null;
            using (var jsonStream = File.OpenRead(filename)) {
                input = client.ParseJsonFromStream_Wrapper <MultiWeatherApi.OpenWeather.Model.WeatherConditions>(jsonStream);
            }

            string outputJson = null;

            using (var sw = new StringWriter())
                using (var jw = new JsonTextWriter(sw)) {
                    var serializer = new JsonSerializer();
                    serializer.NullValueHandling = NullValueHandling.Ignore;
                    serializer.ContractResolver  = new DefaultContractResolver {
                        NamingStrategy = new CamelCaseNamingStrategy()
                    };
                    //serializer.Formatting = Formatting.Indented;
                    serializer.Serialize(jw, input);
                    outputJson = sw.ToString();
                }
            outputJson.ShouldNotBeNullOrWhiteSpace();
            outputJson[0].ShouldBe('{');
            outputJson[outputJson.Length - 1].ShouldBe('}');
        }