public void when_serializing_a_log_entry_then_object_can_serialize()
        {
            var payload = new Dictionary<string, object> { { "msg", "the message" }, { "date", DateTime.UtcNow } };
            var logObject =
                EventEntryTestHelper.Create(
                    timestamp: DateTimeOffset.UtcNow,
                    payloadNames: payload.Keys,
                    payload: payload.Values);

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", true).Serialize(new[] { logObject });

            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));
        }
        public void when_serializing_with_global_context_then_object_can_serialize()
        {
            var ctx = new Dictionary<string, string>()
            {
                {"TestCtx1", "TestCtxValue1"},
                {"TestCtx2", "TestCtxValue2"}
            };
            var payload = new Dictionary<string, object> { { "msg", "the message" }, { "date", DateTime.UtcNow } };
            var logObject =
                EventEntryTestHelper.Create(
                    timestamp: DateTimeOffset.UtcNow,
                    payloadNames: payload.Keys,
                    payload: payload.Values);

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", true, ctx).Serialize(new[] { logObject });

            Debug.WriteLine(actual);

            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));
        }
        public void when_serializing_logentries_can_serialize_valid_bulk_request_format()
        {
            // Note: converting an array does not create valid message for use in elasticsearch bulk operation

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", true).Serialize(new[] { CreateEventEntry(), CreateEventEntry() });

            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));
        }
        public void when_serializing_a_log_with_jsonprops_entry_then_json_merged()
        {
            var payload = new Dictionary<string, object>
            {
                { "msg", "the message" },
                { "date", DateTime.UtcNow },
                { "_jsonPayload", "{\"test\": \"value\", \"test2\": \"value2\"}"}
            };
            var logObject =
                EventEntryTestHelper.Create(
                    timestamp: DateTimeOffset.UtcNow,
                    payloadNames: payload.Keys,
                    payload: payload.Values);

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", true).Serialize(new[] { logObject });

            // Make sure the payload is still valid
            var obj = JObject.Parse(actual.Split('\n')[1]);

            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));
        }
        public void when_serializing_a_log_entry_with_activtyid_then_activityid_serialized()
        {
            var payload = new Dictionary<string, object> { { "msg", "the message" }, { "date", DateTime.UtcNow } };
            var logObject =
                EventEntryTestHelper.Create(
                    timestamp: DateTimeOffset.UtcNow,
                    payloadNames: payload.Keys,
                    payload: payload.Values,
                    activityId: Guid.NewGuid(),
                    relatedActivityId: Guid.NewGuid());

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", true).Serialize(new[] { logObject });

            var serializedEntry = actual.Split('\n')[1];
            var jsonObject = JObject.Parse(serializedEntry);

            Assert.AreEqual(logObject.ActivityId.ToString(), jsonObject["ActivityId"]);
            Assert.AreEqual(logObject.RelatedActivityId.ToString(), jsonObject["RelatedActivityId"]);
            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));
        }
        public void when_serializing_a_log_entry_without_flattened_payload_then_payload_nested()
        {
            var payload = new Dictionary<string, object> { { "msg", "the message" }, { "date", DateTime.UtcNow } };
            var logObject =
                EventEntryTestHelper.Create(
                    timestamp: DateTimeOffset.UtcNow,
                    payloadNames: payload.Keys,
                    payload: payload.Values);

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", false).Serialize(new[] { logObject });

            var serializedEntry = actual.Split('\n')[1];
            var jsonObject = JObject.Parse(serializedEntry);

            Assert.IsTrue(jsonObject["Payload"]["msg"] != null);
            Assert.IsTrue(jsonObject["Payload"]["date"] != null);
            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));
        }
        public void when_serializing_a_log_entry_then_object_can_serialize_process_and_thread_id()
        {
            var payload = new Dictionary<string, object> { { "msg", "the message" }, { "date", DateTime.UtcNow } };
            var logObject =
                EventEntryTestHelper.Create(
                    timestamp: DateTimeOffset.UtcNow,
                    payloadNames: payload.Keys,
                    payload: payload.Values,
                    processId: 300,
                    threadId: 500);

            var actual = new ElasticsearchEventEntrySerializer("logstash", "slab", "instance", true).Serialize(new[] { logObject });

            Assert.IsNotNull(actual);
            Assert.IsTrue(this.IsValidBulkMessage(actual));

            var serializedEntry = actual.Split('\n')[1];
            var jsonObject = JObject.Parse(serializedEntry);

            Assert.AreEqual(300, jsonObject["ProcessId"]);
            Assert.AreEqual(500, jsonObject["ThreadId"]);
        }