public void GetDataTest_ValidFileName_ReturnsValidData() { var expected = new Department { DeptId = 1 }; var dataTable = new DataTable("Sample"); dataTable.Columns.Add(new DataColumn { ColumnName = "DeptId", DataType = typeof(int) }); DataRow dr = dataTable.NewRow(); dr[0] = 1; dataTable.Rows.Add(dr); _helperMock.Setup(x => x.FileExists(It.IsAny <string>())).Returns(true); _helperMock.Setup(x => x.GetDataTableFromCSVFile(It.IsAny <string>())).Returns(dataTable); var obj = new CSVProcessorRepository(_logger.Object, _helperMock.Object); var data = obj.GetData("Departments.csv"); var actual = data.FirstOrDefault() as Department; Assert.AreEqual(expected.DeptId, actual.DeptId); }
public void WriteDataTest_InvalidFile_ReturnsFalse() { _helperMock.Setup(x => x.FileExists(It.IsAny <string>())).Returns(false); var obj = new CSVProcessorRepository(_logger.Object, _helperMock.Object); var actual = obj.WriteData(null, null); Assert.IsFalse(actual); }
public void GetDataTest_FileNotExists_ReturnsNull() { _helperMock.Setup(x => x.FileExists(It.IsAny <string>())).Returns(false); var obj = new CSVProcessorRepository(_logger.Object, _helperMock.Object); var actual = obj.GetData("Sample.csv"); Assert.IsNull(actual); }
public void WriteDataTest_ValidDataAndFile_ReturnsTrue() { _helperMock.Setup(x => x.FileExists(It.IsAny <string>())).Returns(true); _helperMock.Setup(x => x.AppendDataTofile(It.IsAny <string>(), It.IsAny <string>())).Returns(true); var obj = new CSVProcessorRepository(_logger.Object, _helperMock.Object); var actual = obj.WriteData("Sample.csv", "1,1,1,2,3"); Assert.IsTrue(actual); }