ex-int-02-meet-the-teacher/MeetTheTeacher.Test/Export/CsvDataExporterTests.cs
github-classroom[bot] 1be1863b20
Initial commit
2025-04-24 07:02:41 +00:00

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");
}
}