コード例 #1
0
ファイル: CSVReaderTest.cs プロジェクト: shubhu1953/CSharp
        public void ShouldOpenFileAndReadStream()
        {
            var mockstream = new Mock <Stream>();

            mockstream.Setup(x => x.CanRead).Returns(true);
            var streamreader = new StreamReader(mockstream.Object);

            _csvReader.Open(Filename);

            var stream = _csvReader.GetStream();

            Assert.That(stream, Is.EqualTo(streamreader));

            _csvReader.Close();
        }
コード例 #2
0
 public void Should_Throw_Exception_If_File_Does_Not_Exist()
 {
     //Arrange
     using (_csvReader = new CSVReader())
     {
         //Act & Assert
         Assert.Throws(typeof(FileNotFoundException), () => _csvReader.Open("Not_Exists"));
     }
 }
コード例 #3
0
 public void Should_Not_Throw_Exception_If_File_Exists()
 {
     //Arrange
     using (_csvReader = new CSVReader())
     {
         //Act & Assert
         Assert.DoesNotThrow(() => _csvReader.Open(ContactsFile));
     }
 }
コード例 #4
0
 //Keep the open method for backward compatibility
 public void Open(string fileName, Mode mode)
 {
     if (mode == Mode.Read)
     {
         _csvReader.Open(fileName);
     }
     else if (mode == Mode.Write)
     {
         _csvWriter.Open(fileName);
     }
 }
コード例 #5
0
 public void Should_Read_Line_When_Contact_Exists_In_File()
 {
     //Arrange
     using (_csvReader = new CSVReader())
     {
         //Act
         _csvReader.Open(ContactsFile);
         string name    = "";
         string address = "";
         bool   canRead = _csvReader.Read(name, address);
         //Assert
         Assert.True(canRead);
     }
 }
コード例 #6
0
        public void Should_Not_Read_Contacts_If_There_Is_No_Contact()
        {
            //Arrange
            using (_csvReader = new CSVReader())
            {
                //Act
                _csvReader.Open(NoContactsFile);
                string name    = "";
                string address = "";
                bool   canRead = _csvReader.Read(name, address);

                //Assert
                Assert.False(canRead);
            }
        }
コード例 #7
0
        public void Should_Not_Return_Read_Contacts_If_There_Is_No_Contact()
        {
            //Arrange
            using (_csvReader = new CSVReader())
            {
                //Act
                _csvReader.Open(NoContactsFile);
                string name, address;
                bool   canRead = _csvReader.Read(out name, out address);

                //Assert
                Assert.False(canRead);
                Assert.IsEmpty(name);
                Assert.IsEmpty(address);
            }
        }
コード例 #8
0
        public void Should_Return_Columns_Read_When_Contact_Exists_In_File()
        {
            //Arrange
            using (_csvReader = new CSVReader())
            {
                //Act
                _csvReader.Open(ContactsFile);
                string name, address;
                bool   canRead = _csvReader.Read(out name, out address);

                //Assert
                Assert.AreEqual(name, "Shelby Macias");
                Assert.AreEqual(address, "3027 Lorem St.|Kokomo|Hertfordshire|L9T 3D5|England");
                Assert.True(canRead);
            }
        }
コード例 #9
0
ファイル: CSVReaderWriter.cs プロジェクト: shubhu1953/CSharp
        public void Open(string fileName, Mode mode)
        {
            switch (mode)
            {
            case Mode.Read:
                _csvReader.Open(fileName);
                break;

            case Mode.Write:
                _csvWriter.Open(fileName);
                break;

            default:
                throw new Exception("Unknown file mode for " + fileName);
            }
        }