public void PASS_Create() { ElisionTokenFilter filter = new ElisionTokenFilter("name", new List<string>() { "d'", "l'" }); Assert.IsNotNull(filter); Assert.AreEqual("name", filter.Name); Assert.AreEqual("d'", filter.Articles.First()); Assert.AreEqual("l'", filter.Articles.Last()); }
public void PASS_Serialize() { ElisionTokenFilter filter = new ElisionTokenFilter("name", new List<string>() { "d'", "l'" }); string json = JsonConvert.SerializeObject(filter); Assert.IsNotNull(json); string expectedJson = "{\"name\":{\"type\":\"elision\",\"articles\":[\"d'\",\"l'\"]}}"; Assert.AreEqual(expectedJson, json); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { Dictionary<string, object> filterDict = serializer.Deserialize<Dictionary<string, object>>(reader); Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(filterDict.First().Value.ToString()); ElisionTokenFilter filter = new ElisionTokenFilter(filterDict.First().Key, JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_ARTICLES))); TokenFilterBase.Deserialize(filter, fieldDict); return filter; }