Esempio n. 1
0
        public void CheckValidFileWithStubs()
        {
            // arrange
            var fileName = "test.txt";
            var content  = "test";
            //File.WriteAllText(fileName, content);
            var fs = new SIFileSystem();

            fs.ReadAllTextString = delegate(string f)
            {
                Assert.IsTrue(f == fileName);
                return(content);
            };
            // act
            //var test = new TestReader();
            var test = new TestReaderWithStubs(fs);

            test.LoadFile(fileName);
            // assert
            Assert.AreEqual(content, test.Content);
        }
Esempio n. 2
0
        public void CheckValidFileWithStubs()
        {
            // arrange 
            var fileName = "test.txt";
            var content = "test";
            //File.WriteAllText(fileName, content); 
            var fs = new SIFileSystem();
            fs.ReadAllTextString = delegate(string f)
                                       {
                                           Assert.IsTrue(f == fileName);
                                           return content;
                                       };

            // act 
            //var test = new TestReader(); 
            var test = new TestReaderWithStubs(fs);
            test.LoadFile(fileName);

            // assert 
            Assert.AreEqual(content, test.Content);
        }
        public void GetFileContentUsingInterface(string fileName)
        {
            //Arrange
            var Ifs = new SIFileSystem();
            Ifs.ReadAllTextString = fName =>
            {
                if (fName == null)
                    throw new InvalidOperationException("File Name Can't be NULL");
                else if (fName.Length == 0)
                    throw new InvalidOperationException("Length of File Name Can't be Zero");
                else
                    return fName;
            };

            //Act
            var test = new UnitTestExample(Ifs);
            string result = test.GetFileContentUsingInterface(fileName);

            //Assert
            PexAssert.AreEqual(fileName, result);
        }