public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> suggestDict = serializer.Deserialize<Dictionary<string, object>>(reader);

            List<ISuggester> suggestors = new List<ISuggester>();
            SuggestTypeEnum suggestType = SuggestTypeEnum.Term;
            foreach (KeyValuePair<string, object> fieldKvp in suggestDict.Where(x => !x.Key.Equals(_TEXT)))
            {
                // dig down to get the type i am dealing with
                Dictionary<string, object> fieldSuggestDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldKvp.Value.ToString());
                KeyValuePair<string, object> suggestTypeKvp = fieldSuggestDict.FirstOrDefault(x => !x.Key.Equals(_TEXT));

                // create a dictionary just for this one
                Dictionary<string, object> internalDict = new Dictionary<string, object>();
                internalDict.Add(fieldKvp.Key, fieldKvp.Value);
                Dictionary<string, object> suggestTypeDict = new Dictionary<string,object>();
                suggestTypeDict.Add("junk", internalDict);

                suggestType = SuggestTypeEnum.Find(suggestTypeKvp.Key);
                if (suggestType == null)
                    throw new Exception(suggestTypeKvp.Key + " is not a valid type of suggestor.");

                string suggestTypeJsonStr = JsonConvert.SerializeObject(suggestTypeDict.First().Value);
                suggestors.Add(JsonConvert.DeserializeObject(suggestTypeJsonStr, suggestType.ImplementationType) as ISuggester);
            }

            Suggest suggest = new Suggest(suggestors);
            suggest.Text = suggestDict.GetStringOrDefault(_TEXT);

            return suggest;
        }
 public void FAIL_Create()
 {
     try
     {
         Suggest suggest = new Suggest(null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("suggestors", ex.ParamName);   
     }
 }
        public void PASS_Serialize_Term()
        {
            Suggest suggest = new Suggest(new List<ISuggester>() 
                                    { 
                                        new TermSuggester("test", "field") { Text = "text" }
                                    });

            string json = JsonConvert.SerializeObject(suggest);
            Assert.IsNotNull(json);

            string expectedJson = "{\"test\":{\"text\":\"text\",\"term\":{\"field\":\"field\"}}}";
            Assert.AreEqual(expectedJson, json);
        }
        public void PASS_Create()
        {
            Suggest suggest = new Suggest(
                new List<ISuggester>() 
                { 
                    new TermSuggester("test", "field")
                });

            Assert.IsNotNull(suggest);
            Assert.AreEqual(1, suggest.Suggestors.Count());
            Assert.AreEqual("test", (suggest.Suggestors.First() as TermSuggester).SuggestName);
            Assert.AreEqual("field", (suggest.Suggestors.First() as TermSuggester).Field);
        }
        public void PASS_Serialize_Phrase_Term()
        {
            Suggest suggest = new Suggest(new List<ISuggester>() 
                                    { 
                                        new TermSuggester("test", "field"),
                                        new PhraseSuggester("test-phrase", "field2")
                                        {
                                            Analyzer = "analyzer"
                                        }
                                    });
            suggest.Text = "this is the text";

            string json = JsonConvert.SerializeObject(suggest);
            Assert.IsNotNull(json);

            string expectedJson = "{\"text\":\"this is the text\",\"test\":{\"term\":{\"field\":\"field\"}},\"test-phrase\":{\"phrase\":{\"field\":\"field2\",\"analyzer\":\"analyzer\"}}}";
            Assert.AreEqual(expectedJson, json);
        }
        public void PASS_Serialize_Completion()
        {
            Suggest suggest = new Suggest(new List<ISuggester>() 
                                    { 
                                        new CompletionSuggester("test-completion", "field")
                                        {
                                            Fuzzy = new FuzzyCompletion()
                                            {
                                                Fuzziness = 4,
                                                IsUnicodeAware = true,
                                                MinimumLength = 2,
                                                PrefixLength = 5,
                                                Transpositions = false
                                            },
                                            Size = 2,
                                            Text = "mispeld"
                                        }
                                    });

            string json = JsonConvert.SerializeObject(suggest);
            Assert.IsNotNull(json);

            string expectedJson = "{\"test-completion\":{\"text\":\"mispeld\",\"completion\":{\"field\":\"field\",\"size\":2,\"fuzzy\":{\"fuzziness\":4,\"unicode_aware\":true,\"min_length\":2,\"prefix_length\":5,\"transpositions\":false}}}}";
            Assert.AreEqual(expectedJson, json);
        }