コード例 #1
0
        public void PASS_Serialize()
        {
            AttachmentProperty prop = new AttachmentProperty("attach")
            {
                Fields = new List<IDocumentProperty>()
                {
                    new StringProperty("file")
                    {
                        Index = IndexSettingEnum.No,
                        IndexOptions = IndexOptionEnum.DocumentId,
                        OmitNorms = true
                    },
                    new DateProperty("date")
                    {
                        Store = true
                    },
                    new StringProperty("author")
                    {
                        Analyzer = new PropertyAnalyzer(new StandardAnalyzer("standard"))
                    }
                }
            };
            string json = JsonConvert.SerializeObject(prop);
            Assert.IsNotNull(json);

            string expectedJson = "{\"attach\":{\"type\":\"attachment\",\"fields\":{\"file\":{\"type\":\"string\",\"index\":\"no\"},\"date\":{\"type\":\"date\",\"store\":true},\"author\":{\"type\":\"string\",\"analyzer\":\"standard\"}}}}";
            Assert.AreEqual(expectedJson, json);
        }
コード例 #2
0
 public void PASS_Create()
 {
     AttachmentProperty prop = new AttachmentProperty("attach")
     {
         Fields = new List<IDocumentProperty>()
         {
             new StringProperty("file")
             {
                 Index = IndexSettingEnum.No
             },
             new DateProperty("date")
             {
                 Store = true
             },
             new StringProperty("author")
             {
                 Analyzer = new PropertyAnalyzer(new StandardAnalyzer("standard"))
             }
         }
     };
     Assert.IsNotNull(prop);
     Assert.AreEqual("attach", prop.Name);
     Assert.AreEqual((int)3, prop.Fields.Count());
     Assert.IsInstanceOfType(prop.Fields.First(), typeof(StringProperty));
     StringProperty stringProp = prop.Fields.First() as StringProperty;
     Assert.AreEqual(IndexSettingEnum.No, stringProp.Index);
     Assert.IsInstanceOfType(prop.Fields.ElementAt(1), typeof(DateProperty));
     DateProperty dateProp = prop.Fields.ElementAt(1) as DateProperty;
     Assert.AreEqual(true, dateProp.Store);
     Assert.IsInstanceOfType(prop.Fields.Last(), typeof(StringProperty));
     stringProp = prop.Fields.Last() as StringProperty;
     Assert.AreEqual("standard", stringProp.Analyzer.Analyzer.Name);
 }
コード例 #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> propDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            AttachmentProperty prop = new AttachmentProperty(propDict.First().Key);

            Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(propDict.First().Value.ToString());

            DocumentPropertyBase.Deserialize(prop, fieldDict);

            if (fieldDict.ContainsKey(_FIELDS))
                prop.Fields = JsonConvert.DeserializeObject<DocumentPropertyCollection>(fieldDict.GetString(_FIELDS));

            return prop;
        }