<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Raven.Client.Embedded;
using Serilog.Events;
using Serilog.Parsing;

namespace Serilog.Sinks.RavenDB.Tests
{
    [TestFixture]
    public class RavenDBSinkTests
    {
        static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(50);
        
        [Test]
        public void WhenAnEventIsEnqueuedItIsWrittenToABatch_OnTimer()
        {
            using (var documentStore = new EmbeddableDocumentStore {RunInMemory = true}.Initialize())
            {
                var timestamp = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, new TimeSpan(0));
                var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null);
                var logEvent = new LogEvent(timestamp, LogEventLevel.Information, new ArgumentNullException("Mládek"), new MessageTemplateParser().Parse("Geneva"), new List<LogEventProperty> { new LogEventProperty("Youngblood", new ScalarValue("New Macabre")) });
                ravenSink.Emit(logEvent);
                Thread.Sleep(TinyWait + TinyWait);
                ravenSink.Dispose();

                using (var session = documentStore.OpenSession())
                {
                    var events = session.Query<LogEventEntity>().Customize(x => x.WaitForNonStaleResults()).ToList();
                    Assert.AreEqual(1, events.Count);
                    Assert.AreEqual(timestamp, events.First().Timestamp);
                    Assert.AreEqual(LogEventLevel.Information, events.First().Level);
                    Assert.AreEqual(1, events.First().Properties.Count);
                }
            }
        }<commit_msg>Getting to know the contributed RavenDB sink by tinkering with the test case.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using NUnit.Framework;
using Raven.Client.Embedded;
using Serilog.Events;
using Serilog.Parsing;

namespace Serilog.Sinks.RavenDB.Tests
{
    [TestFixture]
    public class RavenDBSinkTests
    {
        static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(50);
        
        [Test]
        public void WhenAnEventIsWrittenToTheSinkItIsRetrievableFromTheDocumentStore()
        {
            using (var documentStore = new EmbeddableDocumentStore {RunInMemory = true}.Initialize())
            {
                var timestamp = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var exception = new ArgumentException("Mládek");
                const LogEventLevel level = LogEventLevel.Information;
                const string messageTemplate = "{Song}";
                var properties = new List<LogEventProperty> { new LogEventProperty("Song", new ScalarValue("New Macabre")) };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var events = session.Query<LogEventEntity>().Customize(x => x.WaitForNonStaleResults()).ToList();
                    Assert.AreEqual(1, events.Count);
                    var single = events.Single();
                    Assert.AreEqual(messageTemplate, single.MessageTemplate);
                    Assert.AreEqual("\"New Macabre\"", single.RenderedMessage);
                    Assert.AreEqual(timestamp, single.Timestamp);
                    Assert.AreEqual(level, single.Level);
                    Assert.AreEqual(1, single.Properties.Count);
                    Assert.AreEqual(exception.Message, single.Exception.Message);
                }
            }
        }
{'fraction_non_alphanumeric': 0.09651541739784407, 'fraction_numerical': 0.011782401604412133, 'mean_word_length': 2.2975206611570247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4224991', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1010, 'n_words': 222}