public void PASS_CreateSort()
 {
     ScriptSort sort = new ScriptSort(new Scripts.Script("script"), "number");
     Assert.IsNotNull(sort);
     Assert.AreEqual("script", sort.Script.ScriptText);
     Assert.AreEqual("number", sort.Type);
 }
 public void PASS_Serialize()
 {
     ScriptSort sort = new ScriptSort(new Scripts.Script("script") 
         { 
             Parameters =  new List<ScriptParameter>() { new ScriptParameter("field", "value") }
         }, "number");
     string json = JsonConvert.SerializeObject(sort);
     Assert.IsNotNull(json);
     string expectedJson = "{\"_script\":{\"type\":\"number\",\"script\":\"script\",\"params\":{\"field\":\"value\"}}}";
     Assert.AreEqual(expectedJson, json);
 }
 public void FAIL_CreateSort_Type()
 {
     try
     {
         ScriptSort sort = new ScriptSort(new Scripts.Script("script"), "");
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("type", ex.ParamName);
     }
 }
 public void FAIL_CreateSort_Script()
 {
     try
     {
         ScriptSort sort = new ScriptSort(null, "number");
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("script", ex.ParamName);
     }
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (fieldDict.ContainsKey(SortTypeEnum.Script.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            ScriptSort sort = new ScriptSort(fieldDict.DeserializeObject<Bolay.Elastic.Scripts.Script>(), fieldDict.GetString(_TYPE));

            sort.Reverse = fieldDict.GetBool(SortClauseSerializer._REVERSE, SortClauseSerializer._REVERSE_DEFAULT);
            if (fieldDict.ContainsKey(_MODE))
                sort.SortMode = SortModeEnum.Find(fieldDict.GetString(_MODE));
            sort.SortOrder = SortOrderEnum.Find(fieldDict.GetString(SortClauseSerializer._ORDER, SortClauseSerializer._ORDER_DEFAULT.ToString()));

            return sort;
        }