コード例 #1
0
        private void should_merge_collections()
        {
            var blob  = new { Ids = new[] { 12 }.ToList() };
            var blob2 = new { Ids = new[] { 34 }.ToList() };

            var dictionary = ObjectMerging.Flatten(new[] { blob, blob2 });

            Assert.True(dictionary.ContainsKey("Ids"));
            Assert.Collection <object>((IEnumerable <object>)dictionary["Ids"],
                                       id => Assert.Equal(12, id),
                                       id => Assert.Equal(34, id));
        }
コード例 #2
0
        private void should_merge_collections_of_mixed_types()
        {
            var blob  = new { Ids = new[] { 12 }.ToList() };
            var blob2 = new { Ids = new[] { "34" }.ToList() };
            var blob3 = new { Ids = new[] { true } };

            var dictionary = ObjectMerging.Flatten(new object[] { blob, blob2, blob3 });

            Assert.True(dictionary.ContainsKey("Ids"));
            Assert.Collection <object>((IEnumerable <object>)dictionary["Ids"],
                                       id => Assert.Equal(12, id),
                                       id => Assert.Equal("34", id),
                                       id => Assert.Equal(true, id));
        }
コード例 #3
0
        public static ProcessedLogEvent Process(LogEvent logEvent)
        {
            var requiredFields = new Dictionary <string, object>()
            {
                { "@version", 1 },
                { "@timestamp", logEvent.Timestamp.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture) }
            };

            var allFields = new object[] { requiredFields }
            .Concat(logEvent.AdditionalFields)
            .Concat(new object[] { logEvent.Content });

            return(new ProcessedLogEvent()
            {
                Content = ObjectMerging.Flatten(allFields)
            });
        }
コード例 #4
0
        private void should_merge_non_generic_collections()
        {
            var data1 = new Exception().Data;

            data1.Clear();
            data1.Add("blob", "thang");
            var blob = new { Things = data1 };

            var data2 = new Exception().Data;

            data2.Clear();
            data2.Add("blob", "thang2");
            var blob2 = new { Things = data2 };

            var dictionary = ObjectMerging.Flatten(new object[] { blob, blob2 });

            Assert.True(dictionary.ContainsKey("Things"));
            Assert.Collection <object>((IEnumerable <object>)dictionary["Things"],
                                       id => Assert.Equal(new DictionaryEntry("blob", "thang"), id),
                                       id => Assert.Equal(new DictionaryEntry("blob", "thang2"), id));
        }