Add TSV support.
Import Upload
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MileageTraker.Web.DAL;
|
||||
using NUnit.Framework;
|
||||
@@ -9,12 +10,11 @@ namespace Web.Tests.DAL
|
||||
public class FuelmanCsvImporterTests
|
||||
{
|
||||
private const string LogFolder = @"DAL\FuelLogDocs\";
|
||||
private const string CsvFilename = "TRN85E_150837_2015-07-31_1C758D97D46F565.csv";
|
||||
|
||||
|
||||
[Test]
|
||||
public void Import_Gets_More_Than_One_Result()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + CsvFilename).ToList();
|
||||
var fuelLogs = FuelmanCsvImporter.Import(new FileInfo(LogFolder + "TRN85E_150837_2015-07-31_1C758D97D46F565.csv"));
|
||||
Assert.That(fuelLogs, Has.Count.EqualTo(191));
|
||||
foreach (var fuelLog in fuelLogs)
|
||||
{
|
||||
@@ -25,7 +25,7 @@ namespace Web.Tests.DAL
|
||||
[Test]
|
||||
public void Import_Gets_All_Fields()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + "OneLog.csv").ToList();
|
||||
var fuelLogs = FuelmanCsvImporter.Import(new FileInfo(LogFolder + "OneLog.csv")).ToList();
|
||||
Assert.That(fuelLogs, Has.Count.EqualTo(1));
|
||||
|
||||
var fuelLog = fuelLogs[0];
|
||||
@@ -39,17 +39,28 @@ namespace Web.Tests.DAL
|
||||
Assert.That(fuelLog.TotalPrice, Is.EqualTo(4.99));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_Tsv()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(new FileInfo(LogFolder + "August2015Fuelman.txt"));
|
||||
Assert.That(fuelLogs, Has.Count.EqualTo(197));
|
||||
foreach (var fuelLog in fuelLogs)
|
||||
{
|
||||
Console.WriteLine("{0} {1} {2} {3}", fuelLog.Date, fuelLog.DriverFullName, fuelLog.TagNumber, fuelLog.CityName);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_Bad_Format_Gets_No_Results()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + "BadFormat.csv").ToList();
|
||||
var fuelLogs = FuelmanCsvImporter.Import(new FileInfo(LogFolder + "BadFormat.csv"));
|
||||
Assert.That(fuelLogs.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_NonFuel_Does_Not_Import()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + "OneCarWashOneFuel.csv").ToList();
|
||||
var fuelLogs = FuelmanCsvImporter.Import(new FileInfo(LogFolder + "OneCarWashOneFuel.csv"));
|
||||
Assert.That(fuelLogs.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
@@ -57,28 +68,28 @@ namespace Web.Tests.DAL
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_BadDate()
|
||||
{
|
||||
FuelmanCsvImporter.Import(LogFolder + "BadDate.csv").ToList();
|
||||
FuelmanCsvImporter.Import(new FileInfo(LogFolder + "BadDate.csv"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_MissingField()
|
||||
{
|
||||
FuelmanCsvImporter.Import(LogFolder + "MissingField.csv").ToList();
|
||||
FuelmanCsvImporter.Import(new FileInfo(LogFolder + "MissingField.csv"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_No_File()
|
||||
{
|
||||
FuelmanCsvImporter.Import(LogFolder + "No File Here.csv").ToList();
|
||||
FuelmanCsvImporter.Import(new FileInfo(LogFolder + "No File Here.csv"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_Xls()
|
||||
{
|
||||
FuelmanCsvImporter.Import(@"DAL\LogDocs\" + "Logs.xls").ToList();
|
||||
FuelmanCsvImporter.Import(new FileInfo(@"DAL\LogDocs\" + "Logs.xls"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user