コード例 #1
0
        public void TestTextWriter()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(TestContext.TestRunDirectory);
            sb.Append(@"\");
            sb.Append("testwritertestfile.txt");
            string fullPath = sb.ToString();

            TestLauncherActor.Test(() =>
            {
                using (var textWriter = new TextWriterActor(fullPath))
                {
                    textWriter.SendMessage("1st line");
                    textWriter.SendMessage("2nd line");
                    textWriter.SendMessage("3rd line");
                    textWriter.Flush();
                }
                using (var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    StreamReader reader = new StreamReader(stream);
                    try
                    {
                        Assert.AreEqual(reader.ReadLine(), "1st line");
                        Assert.AreEqual(reader.ReadLine(), "2nd line");
                        Assert.AreEqual(reader.ReadLine(), "3rd line");
                    }
                    finally
                    {
                        reader.Dispose();
                    }
                }
            });
        }
コード例 #2
0
 public void TestTextWriter()
 {
     TestLauncherActor.Test(() =>
     {
         using (var textWriter = new TextWriterActor("textwritertestfile.txt"))
         {
             textWriter.SendMessage("1st line");
             textWriter.SendMessage("2nd line");
             textWriter.SendMessage("3rd line");
             textWriter.Flush();
         }
         using (var stream = new FileStream("textwritertestfile.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
         {
             StreamReader reader = new StreamReader(stream);
             try
             {
                 Assert.AreEqual(reader.ReadLine(), "1st line");
                 Assert.AreEqual(reader.ReadLine(), "2nd line");
                 Assert.AreEqual(reader.ReadLine(), "3rd line");
             }
             finally
             {
                 reader.Dispose();
             }
         }
     }, 20000);
 }