示例#1
0
        static void Main(string[] args)
        {
            var sr = new ConfigStreamReader();
            ServiceContainer.RegisterInstance(sr);

            var reader = new ConfigReader2(@"C:\authentic\file\path.txt");
            reader.ReadConfigFile();
        }
        public void ReadConfigFile_FileOpenedAndContentsRead()
        {
            mockReader.Setup(x => x.Init(It.IsAny<string>()));
            mockReader.Setup(y => y.ReadLine());
            mockReader.Setup(z => z.Dispose()); // confirms that Dispose() call is made implicity via the using statement

            var cr = new ConfigReader2(phonyFilePath);
            cr.ReadConfigFile();

            mockReader.VerifyAll();
        }
        public void ReadConfigFile_FileOpenFailed_ExceptionThrown()
        {
            mockReader.Setup(x => x.Init(It.IsAny<string>())).Throws<Exception>();
            var cr = new ConfigReader2(phonyFilePath);
            bool result = false;

            try
            {
                cr.ReadConfigFile();
            }
            catch (Exception exc)
            {
                if (exc.Message.Contains(phonyFilePath))
                    result = true;
            }

            Assert.True(result);
        }