Beispiel #1
0
        public void ResourceIsLocked()
        {
            var fileWriter1 = new FileWriter(TestFileName);
            fileWriter1.Write("Test");

            Assert.Throws<IOException>(() =>
            {
                var file2 = new FileWriter(TestFileName);
                file2.Write("adsf");
            });
        }
Beispiel #2
0
        public void WriteFewWordsDoesWork()
        {
            const string testLine = "TestLine";
            var extectedStr = String.Format("{0}{0}{0}{0}", testLine);
            var fileWriter = new FileWriter(TestFileName);
               /* using (var fileWriter = new FileWriter(TestFileName))*/
            {
                fileWriter.Write(testLine);
                fileWriter.Write(testLine);
                fileWriter.Write(testLine);
                fileWriter.Write(testLine);
            }

            using (var fileStream = File.OpenRead(TestFileName))
            using (var streamReader = new StreamReader(fileStream))
            {
                var str = streamReader.ReadToEnd();
                Assert.AreEqual(extectedStr, str);
            }
        }
Beispiel #3
0
        private static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                FileWriter fileWriter = null;
                try
                {
                    fileWriter = new FileWriter(@"log.txt");

                    if (fileWriter != null)
                        fileWriter.Write("First test string");
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                finally
                {
                    if(fileWriter != null)
                        fileWriter.Dispose();
                }
            }
            Console.ReadKey();
        }