Import FuelLog
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MileageTraker.Web.DAL;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.DAL
|
||||
{
|
||||
[TestFixture]
|
||||
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();
|
||||
Assert.That(fuelLogs, Has.Count.EqualTo(191));
|
||||
foreach (var fuelLog in fuelLogs)
|
||||
{
|
||||
Console.WriteLine("{0} {1} {2} {3}", fuelLog.Date, fuelLog.DriverFullName, fuelLog.TagNumber, fuelLog.CityName);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_Gets_All_Fields()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + "OneLog.csv").ToList();
|
||||
Assert.That(fuelLogs, Has.Count.EqualTo(1));
|
||||
|
||||
var fuelLog = fuelLogs[0];
|
||||
Assert.That(fuelLog.Date, Is.EqualTo(new DateTime(2015,7,1, 8,8,0)));
|
||||
Assert.That(fuelLog.DriverFullName, Is.EqualTo("Sherry Seal"));
|
||||
Assert.That(fuelLog.TagNumber, Is.EqualTo("4584GA"));
|
||||
Assert.That(fuelLog.Odometer, Is.EqualTo(129368));
|
||||
Assert.That(fuelLog.CityName, Is.EqualTo("Mooresburg"));
|
||||
Assert.That(fuelLog.MPG, Is.EqualTo(19.2));
|
||||
Assert.That(fuelLog.GasPurchased, Is.EqualTo(2.442));
|
||||
Assert.That(fuelLog.TotalPrice, Is.EqualTo(4.99));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_Bad_Format_Gets_No_Results()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + "BadFormat.csv").ToList();
|
||||
Assert.That(fuelLogs.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_NonFuel_Does_Not_Import()
|
||||
{
|
||||
var fuelLogs = FuelmanCsvImporter.Import(LogFolder + "OneCarWashOneFuel.csv").ToList();
|
||||
Assert.That(fuelLogs.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_BadDate()
|
||||
{
|
||||
FuelmanCsvImporter.Import(LogFolder + "BadDate.csv").ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_MissingField()
|
||||
{
|
||||
FuelmanCsvImporter.Import(LogFolder + "MissingField.csv").ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_No_File()
|
||||
{
|
||||
FuelmanCsvImporter.Import(LogFolder + "No File Here.csv").ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ImportException))]
|
||||
public void Import_Xls()
|
||||
{
|
||||
FuelmanCsvImporter.Import(@"DAL\LogDocs\" + "Logs.xls").ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user