コード例 #1
0
        public void PASS_Create()
        {
            DocumentSource source = new DocumentSource()
            {
                IsEnabled = false,
                IsCompressed = true,
                Excludes = new List<string>()
                {
                    "ex1", "ex2"
                },
                Includes = new List<string>()
                {
                    "in1", "in2"
                },
                CompressionThreshold = new CompressionThreshold(10, SizeUnitEnum.Byte)
            };

            Assert.IsNotNull(source);
            Assert.AreEqual(false, source.IsEnabled);
            Assert.AreEqual(true, source.IsCompressed);
            Assert.AreEqual("ex1", source.Excludes.First());
            Assert.AreEqual("ex2", source.Excludes.Last());
            Assert.AreEqual("in1", source.Includes.First());
            Assert.AreEqual("in2", source.Includes.Last());
            Assert.AreEqual((Int64)10, source.CompressionThreshold.Size);
            Assert.AreEqual(SizeUnitEnum.Byte, source.CompressionThreshold.Unit);
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            DocumentSource source = new DocumentSource();

            source.IsCompressed = fieldDict.GetBool(_IS_COMPRESSED, DocumentSource._IS_COMPRESSED_DEFAULT);
            if (fieldDict.ContainsKey(_COMPRESSION_THRESHOLD))
            {
                source.CompressionThreshold = new CompressionThreshold(fieldDict.GetString(_COMPRESSION_THRESHOLD));
            }
                
            if(fieldDict.ContainsKey(_EXCLUDES))
            {
                source.Excludes = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_EXCLUDES));
            }

            if (fieldDict.ContainsKey(_INCLUDES))
            {
                source.Includes = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_INCLUDES));
            }

            source.IsEnabled = fieldDict.GetBool(_IS_ENABLED, DocumentSource._IS_ENABLED_DEFAULT);

            return source;
        }
コード例 #3
0
        public void PASS_Serialize()
        {
            DocumentSource source = new DocumentSource()
            {
                IsEnabled = false,
                IsCompressed = true,
                Excludes = new List<string>()
                {
                    "ex1", "ex2"
                },
                Includes = new List<string>()
                {
                    "in1", "in2"
                },
                CompressionThreshold = new CompressionThreshold(10, SizeUnitEnum.Byte)
            };

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

            string expectedJson = "{\"enabled\":false,\"compress\":true,\"compress_threshold\":\"10b\",\"includes\":[\"in1\",\"in2\"],\"excludes\":[\"ex1\",\"ex2\"]}";
            Assert.AreEqual(expectedJson, json);
        }