Esempio n. 1
0
        public async Task ShouldFireEventForNewCharsOnAlreadyTrackedLine()
        {
            var filepath = $"./{Guid.NewGuid()}";

            using (var writer = CreateConcurrentWriter(filepath))
            {
                var raisedEvents = new List <GameStateChangedEventArgs>();
                var watcher      = new LogObserver(filepath);
                watcher.GameStateChanged += (sender, @event) => raisedEvents.Add(@event);

                watcher.Start();
                await writer.WriteAsync("1");

                await Task.Delay(WriteDelayInMilliseconds);

                await writer.WriteLineAsync("2");

                await writer.WriteLineAsync("3");

                await Task.Delay(WriteDelayInMilliseconds);

                Assert.True(raisedEvents.Count > 0);
                Assert.Equal(new[] { "1", "2", "3" }, raisedEvents.SelectMany(x => x.Data).ToArray());
            }
        }
Esempio n. 2
0
        public async Task ShouldFireEventsWithGroupedLines()
        {
            var filepath = $"./{Guid.NewGuid()}";

            using (var writer = CreateConcurrentWriter(filepath))
            {
                var raisedEvents = new List <GameStateChangedEventArgs>();
                var watcher      = new LogObserver(filepath);
                watcher.GameStateChanged += (sender, @event) => raisedEvents.Add(@event);

                watcher.Start();
                await writer.WriteLineAsync("0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14");

                await Task.Delay(WriteDelayInMilliseconds);

                Assert.Equal(2, raisedEvents.Count);
                Assert.Equal(new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, raisedEvents[0].Data);
                Assert.Equal(new[] { "10", "11", "12", "13", "14" }, raisedEvents[1].Data);
            }
        }
Esempio n. 3
0
        public async Task ShouldNotFireEventOnEmptyLinesOnly()
        {
            var filepath = $"./{Guid.NewGuid()}";

            using (var writer = CreateConcurrentWriter(filepath))
            {
                bool isEventRaised = false;
                var  watcher       = new LogObserver(filepath);
                watcher.GameStateChanged += (sender, @event) => isEventRaised = true;

                watcher.Start();
                await writer.WriteLineAsync(" ");

                await writer.WriteLineAsync(string.Empty);

                await Task.Delay(WriteDelayInMilliseconds);

                Assert.False(isEventRaised);
            }
        }
Esempio n. 4
0
        public async Task ShouldFireEventOnNewLogLines()
        {
            var filepath = $"./{Guid.NewGuid()}";

            using (var writer = CreateConcurrentWriter(filepath))
            {
                var watcher = new LogObserver(filepath);

                var raisedEvent = await Assert.RaisesAsync <GameStateChangedEventArgs>(
                    handler => watcher.GameStateChanged += handler,
                    handler => watcher.GameStateChanged -= handler,
                    async() =>
                {
                    watcher.Start();
                    await writer.WriteLineAsync("1\r\n2\r\n3");
                    await Task.Delay(WriteDelayInMilliseconds);
                });

                Assert.Equal(new[] { "1", "2", "3" }, raisedEvent.Arguments.Data);
            }
        }
Esempio n. 5
0
        public async Task ShouldNotFireEventForPreviouslyTrackedLines()
        {
            var filepath = $"./{Guid.NewGuid()}";

            using (var writer = CreateConcurrentWriter(filepath))
            {
                var raisedEvents = new List <GameStateChangedEventArgs>();
                var watcher      = new LogObserver(filepath);

                watcher.Start();
                await writer.WriteLineAsync("1");

                watcher.GameStateChanged += (sender, @event) => raisedEvents.Add(@event);
                await Task.Delay(WriteDelayInMilliseconds);

                await writer.WriteLineAsync("2\r\n3");

                await Task.Delay(WriteDelayInMilliseconds);

                Assert.True(raisedEvents.Count == 1);
                Assert.Equal(new[] { "2", "3" }, raisedEvents[0].Data);
            }
        }