Пример #1
0
        public static string ReadExistingTextFile(string fileName)
        {
            CustomAsserts.AssertFileExists(fileName, false);

            for (int i = 1; i <= 100; i++)
            {
                try
                {
                    var    stream   = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    var    reader   = new StreamReader(stream);
                    string contents = reader.ReadToEnd();
                    reader.Close();
                    stream.Close();

                    // Check that some data has actually been read.
                    if (!string.IsNullOrEmpty(contents))
                    {
                        return(contents);
                    }
                }
                catch (Exception ex)
                {
                    if (i == 100)
                    {
                        throw ex;
                    }
                }

                Thread.Sleep(100);
            }

            return("");
        }
Пример #2
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;

            File.WriteAllText(file, script);
            scripting.Enabled = true;
            scripting.Reload();

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

            LogHandler.DeleteEventLog();

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

            SendMessageToTest();

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

            CustomAsserts.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();

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

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

                Thread.Sleep(25);
            }
        }