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(); }
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")); } }
public void Should_Not_Throw_Exception_If_File_Exists() { //Arrange using (_csvReader = new CSVReader()) { //Act & Assert Assert.DoesNotThrow(() => _csvReader.Open(ContactsFile)); } }
//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); } }
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); } }
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); } }
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); } }
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); } }
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); } }