Exemplo n.º 1
0
        public void StartTest2_Twice()
        {
            String dir = Path.GetRandomFileName();
            // まあ確率的に例外とかないだろう
            Directory.CreateDirectory(dir);
            try
            {
                String[][] expectedRows = new String[][]{
                    new String[]{"2013-05-17T20:07:48", "9", "GUILD", "12133620", "白 菜", "テスト"},
                };
                int row = 0;

                using (IPso2LogWatcherFactory factory = new Pso2LogWatcherFactory())
                using (IPso2LogWatcher watcher = factory.CreatePso2LogWatcher())
                {
                    StartTestState2[] state = new StartTestState2[] { StartTestState2.WaitingAssertRow1 };
                    watcher.Pso2LogEvent += (s, e) =>
                    {
                        string[] expectedCols = expectedRows[row++];
                        int col = 0;
                        Assert.AreEqual(expectedCols[col++], e.Time);
                        Assert.AreEqual(expectedCols[col++], e.MessageID);
                        Assert.AreEqual(expectedCols[col++], e.SendTo);
                        Assert.AreEqual(expectedCols[col++], e.FromID);
                        Assert.AreEqual(expectedCols[col++], e.From);
                        Assert.AreEqual(expectedCols[col++], e.Message);

                        lock (state)
                        {
                            state[0]++;
                            Monitor.Pulse(state);
                        }
                    };
                    watcher.Start(dir);
                    using (TextWriter log =
                        new StreamWriter(
                            new FileStream(
                                Path.Combine(dir, "ChatLog20130519_00.txt"),
                                FileMode.CreateNew,
                                FileAccess.Write,
                                FileShare.Delete | FileShare.ReadWrite
                            ),
                            Encoding.Unicode
                        )
                    )
                    {
                        log.WriteLine("2013-05-17T20:07:48\t9\tGUILD\t12133620\t白 菜\tテスト");
                        log.Flush();
                    }
                    lock (state)
                    {
                        if (state[0] != StartTestState2.AssertedRow1)
                        {
                            Monitor.Wait(state, 3000);
                        }
                        Assert.AreEqual(StartTestState2.AssertedRow1, state[0]);
                    }
                    watcher.Stop();
                    Assert.Throws<ObjectDisposedException>(() =>
                    {
                        watcher.Start(dir);
                    });
                    watcher.Stop();
                }
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }
Exemplo n.º 2
0
        public void StartTest2_Twice()
        {
            String dir = Path.GetRandomFileName();

            // まあ確率的に例外とかないだろう
            Directory.CreateDirectory(dir);
            try
            {
                String[][] expectedRows = new String[][] {
                    new String[] { "2013-05-17T20:07:48", "9", "GUILD", "12133620", "白 菜", "テスト" },
                };
                int row = 0;

                using (IPso2LogWatcherFactory factory = new Pso2LogWatcherFactory())
                    using (IPso2LogWatcher watcher = factory.CreatePso2LogWatcher())
                    {
                        StartTestState2[] state = new StartTestState2[] { StartTestState2.WaitingAssertRow1 };
                        watcher.Pso2LogEvent += (s, e) =>
                        {
                            string[] expectedCols = expectedRows[row++];
                            int      col          = 0;
                            Assert.AreEqual(expectedCols[col++], e.Time);
                            Assert.AreEqual(expectedCols[col++], e.MessageID);
                            Assert.AreEqual(expectedCols[col++], e.SendTo);
                            Assert.AreEqual(expectedCols[col++], e.FromID);
                            Assert.AreEqual(expectedCols[col++], e.From);
                            Assert.AreEqual(expectedCols[col++], e.Message);

                            lock (state)
                            {
                                state[0]++;
                                Monitor.Pulse(state);
                            }
                        };
                        watcher.Start(dir);
                        using (TextWriter log =
                                   new StreamWriter(
                                       new FileStream(
                                           Path.Combine(dir, "ChatLog20130519_00.txt"),
                                           FileMode.CreateNew,
                                           FileAccess.Write,
                                           FileShare.Delete | FileShare.ReadWrite
                                           ),
                                       Encoding.Unicode
                                       )
                               )
                        {
                            log.WriteLine("2013-05-17T20:07:48\t9\tGUILD\t12133620\t白 菜\tテスト");
                            log.Flush();
                        }
                        lock (state)
                        {
                            if (state[0] != StartTestState2.AssertedRow1)
                            {
                                Monitor.Wait(state, 3000);
                            }
                            Assert.AreEqual(StartTestState2.AssertedRow1, state[0]);
                        }
                        watcher.Stop();
                        Assert.Throws <ObjectDisposedException>(() =>
                        {
                            watcher.Start(dir);
                        });
                        watcher.Stop();
                    }
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }