示例#1
0
        public void TestEventLog()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            // First set up a script
            string script =
                @"Sub OnAcceptMessage(oClient, oMessage)
                               EventLog.Write(""HOWDY"")
                              End Sub";

            Scripting scripting = _settings.Scripting;
            string    file      = scripting.CurrentScriptFile;

            TestSetup.WriteFile(file, script);
            scripting.Enabled = true;
            scripting.Reload();

            // Drop the current event log
            string eventLogFile = _settings.Logging.CurrentEventLog;

            SingletonProvider <TestSetup> .Instance.DeleteEventLog();

            // Add an account and send a message to it.
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SendMessageToTest();

            POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            TestSetup.AssertFileExists(eventLogFile, false);

            // Check that it starts with Unicode markers.
            for (int i = 0; i <= 400; i++)
            {
                try
                {
                    var fs = new FileStream(eventLogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    var br = new BinaryReader(fs);
                    int i1 = br.ReadByte();
                    int i2 = br.ReadByte();
                    br.Close();
                    fs.Close();

                    CustomAssert.AreEqual(255, i1);
                    CustomAssert.AreEqual(254, i2);

                    break;
                }
                catch (Exception e)
                {
                    if (i == 40)
                    {
                        throw e;
                    }
                }

                Thread.Sleep(25);
            }
        }