コード例 #1
0
        private void should_replace_deep_circular_refs_with_a_flag()
        {
            var parentblob = new Blob();

            var deepchild = new Blob {
                Child = parentblob
            };

            parentblob.Child = new Blob {
                Child = new Blob {
                    Child = new Blob {
                        Child = deepchild
                    }
                }
            };

            var dictionary = ObjectMerging.ToDictionary(parentblob);

            var child = (Dictionary <string, object>)(dictionary["Child"]);

            child = (Dictionary <string, object>)(child["Child"]);
            child = (Dictionary <string, object>)(child["Child"]);
            child = (Dictionary <string, object>)(child["Child"]);
            child = (Dictionary <string, object>)(child["Child"]);

            Assert.Equal(child["OcelogWarning"], "Found a Circular Reference");
        }
コード例 #2
0
        private void should_serialise_exceptions_targetsite()
        {
            var blob = GetException();

            var dictionary = ObjectMerging.ToDictionary(blob);

            Assert.True(dictionary.ContainsKey("TargetSite"));
            Assert.Equal(blob.TargetSite.ToString(), dictionary["TargetSite"]);
        }
コード例 #3
0
        private void should_ignore_exceptions_thrown_by_getters()
        {
            var blob = new ThrowException();

            var dictionary = ObjectMerging.ToDictionary(blob);

            var child = (Dictionary <string, object>)(dictionary["Prop"]);

            Assert.Equal(child["OcelogWarning"], "Exception thrown by invocation");
        }
コード例 #4
0
        private void should_ignore_privates()
        {
            var blob = new Blob();

            blob.SetPrivates("hello");

            var dictionary = ObjectMerging.ToDictionary(blob);

            Assert.False(dictionary.ContainsKey("PrivateTextProp"));
            Assert.False(dictionary.ContainsKey("privateText"));
        }
コード例 #5
0
        private void should_replace_circular_refs_with_a_flag()
        {
            var blob = new Blob();

            blob.Child = blob;

            var dictionary = ObjectMerging.ToDictionary(blob);

            var child = (Dictionary <string, object>)(dictionary["Child"]);

            Assert.Equal(child["OcelogWarning"], "Found a Circular Reference");
        }
コード例 #6
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));
        }
コード例 #7
0
        private void should_replace_circular_refs_in_enumerable_with_a_flag()
        {
            var blob = new Blob();

            blob.ChildrenList = Enumerable.Repeat(blob, 1);

            var dictionary = ObjectMerging.ToDictionary(blob);

            var children = (IEnumerable <object>)dictionary["ChildrenList"];
            var child    = (Dictionary <string, object>)children.First();

            Assert.Equal(child["OcelogWarning"], "Found a Circular Reference");
        }
コード例 #8
0
        private void should_ignore_properties_that_are_delegate_types()
        {
            var    didExecute  = false;
            Action execute     = () => { didExecute = true; };
            Action methodGroup = this.should_ignore_properties_that_are_delegate_types;
            var    blob        = new { ThingToExecute = execute, ThingToExecute2 = methodGroup };

            var dictionary = ObjectMerging.ToDictionary(blob);

            Assert.False(didExecute);
            Assert.False(dictionary.ContainsKey("ThingToExecute"));
            Assert.False(dictionary.ContainsKey("ThingToExecute2"));
        }
コード例 #9
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));
        }
コード例 #10
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)
            });
        }
コード例 #11
0
        public void should_show_deep_path_of_fields_when_comparing_to_dictionary()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = new { Deep = new { } } };

            logSpy.Logger.Info(content);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(ObjectMerging.ToDictionary(new { Some = new { Deep = new { Field = "Field" } } }));
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some.Deep.Field", exception.Message);
                    throw;
                }
            });
        }
コード例 #12
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));
        }