public async Task ShouldPickUpEvents()
        {
            var directoryProvider = new TestDirectoryProvider();

            Directory.Delete(directoryProvider.Directory, true);
            var events = new ConcurrentBag <LogEvent>();

            CollectionAssert.IsEmpty(events);

            string testFile1 = Path.Combine(directoryProvider.Directory, "Journal.1234.log");
            string testFile2 = Path.Combine(directoryProvider.Directory, "Journal.2345.log");

            File.WriteAllText(testFile1, EventsAsJson.Skip(5).First());
            var journalMonitor = new JournalMonitor(directoryProvider, 5);

            journalMonitor.Subscribe(events.Add);

            File.AppendAllText(testFile1, EventsAsJson.Skip(8).First());
            await Delay;

            CollectionAssert.IsNotEmpty(events);

            while (events.Count > 0)
            {
                events.TryTake(out var e);
            }

            File.WriteAllText(testFile2, EventsAsJson.Skip(9).First());
            await Delay;

            CollectionAssert.IsNotEmpty(events);

            while (events.Count > 0)
            {
                events.TryTake(out var e);
            }

            await Delay;

            CollectionAssert.IsEmpty(events);
        }
예제 #2
0
        public async Task ShouldPickUpEvents()
        {
            var directoryProvider = new TestDirectoryProvider();
            var events            = new ConcurrentBag <JournalEvent>();

            CollectionAssert.IsEmpty(events);

            string testFile1 = Path.Combine(directoryProvider.Directory, "Journal.1234.log");
            string testFile2 = Path.Combine(directoryProvider.Directory, "Journal.2345.log");

            File.WriteAllText(testFile1, EventsAsJson.ElementAt(0));
            var journalMonitor = new JournalMonitor(directoryProvider, 5);

            journalMonitor.Subscribe(events.Add);

            File.AppendAllText(testFile1, EventsAsJson.ElementAt(1));
            await Delay;

            CollectionAssert.IsNotEmpty(events);

            while (!events.IsEmpty)
            {
                events.TryTake(out var e);
            }

            File.WriteAllText(testFile2, EventsAsJson.ElementAt(2));
            await Delay;

            CollectionAssert.IsNotEmpty(events);

            while (!events.IsEmpty)
            {
                events.TryTake(out var e);
            }

            await Delay;

            CollectionAssert.IsEmpty(events);
        }