52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using MeetTheTeacher.Export;
|
|
|
|
namespace MeetTheTeacher.Test.Export;
|
|
|
|
public sealed class CsvDataExporterTests : ExporterTestBase, IDisposable
|
|
{
|
|
private readonly CsvDataExporter _csvDataExporter;
|
|
|
|
public CsvDataExporterTests()
|
|
{
|
|
_csvDataExporter = new CsvDataExporter();
|
|
}
|
|
|
|
protected override string FileExtension => "csv";
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clean up the test file.
|
|
if (File.Exists(FilePath))
|
|
{
|
|
File.Delete(FilePath);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_Valid()
|
|
{
|
|
SimpleCheck();
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_FileExisted()
|
|
{
|
|
File.WriteAllText(FilePath, "some content");
|
|
|
|
// still has to work
|
|
SimpleCheck();
|
|
}
|
|
|
|
private void SimpleCheck()
|
|
{
|
|
_csvDataExporter.Export(SampleData, FileName);
|
|
|
|
File.Exists(FilePath).Should().BeTrue();
|
|
|
|
string[] rows = File.ReadAllLines(FilePath);
|
|
rows.Length.Should().Be(3, "Header + 2 data rows");
|
|
rows[0].Should().Be("Name;Age");
|
|
rows[1].Should().Be("John;30");
|
|
rows[2].Should().Be("Jane;25");
|
|
}
|
|
}
|