Admin import functional
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
using System.IO;
|
||||
using MileageTraker.Web.DAL;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.DAL
|
||||
{
|
||||
[TestFixture]
|
||||
public class LogImportTemplateWriterTests
|
||||
{
|
||||
[Test]
|
||||
public void LogImportTemplteWriterTests()
|
||||
{
|
||||
var bytes = LogImportTemplateWriter.Write();
|
||||
using (var fs = new FileStream("LogImport.xls", FileMode.Create))
|
||||
fs.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Linq;
|
||||
using MileageTraker.Web.DAL;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.DAL
|
||||
{
|
||||
[TestFixture]
|
||||
public class LogImporterTests
|
||||
{
|
||||
private const string LogFolder = @"DAL\LogDocs\";
|
||||
|
||||
[Test]
|
||||
public void Import_Gets_More_Than_One_Result()
|
||||
{
|
||||
var logs = LogImporter.Import(LogFolder + "Logs.xls").ToList();
|
||||
|
||||
Assert.That(logs.Count(), Is.GreaterThan(0));
|
||||
var first = logs.First();
|
||||
Assert.That(first.VehicleId, Is.EqualTo("3572"));
|
||||
Assert.That(first.Date, Is.EqualTo("3/4/2013"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(LogImportException))]
|
||||
public void Import_Incorrect_ColumnHeaders()
|
||||
{
|
||||
LogImporter.Import(LogFolder + "Logs_IncorrectHeaders.xls");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Import_TemplateTest()
|
||||
{
|
||||
var logs = LogImporter.Import(LogFolder + "MileageTraker_ImportTemplate.xls");
|
||||
Assert.That(logs.Count(), Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.CreateLog;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.Utility
|
||||
@@ -8,7 +12,7 @@ namespace Web.Tests.Utility
|
||||
public class CustomExtensionsTests
|
||||
{
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_Yesterday()
|
||||
public void TimeSpan_ToVerboseStringHistoric_Yesterday()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-1)).ToVerboseStringHistoric();
|
||||
|
||||
@@ -16,7 +20,7 @@ namespace Web.Tests.Utility
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_Today()
|
||||
public void TimeSpan_ToVerboseStringHistoric_Today()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today).ToVerboseStringHistoric();
|
||||
|
||||
@@ -24,7 +28,7 @@ namespace Web.Tests.Utility
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_TwoDaysAgo()
|
||||
public void TimeSpan_ToVerboseStringHistoric_TwoDaysAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-2)).ToVerboseStringHistoric();
|
||||
|
||||
@@ -32,7 +36,7 @@ namespace Web.Tests.Utility
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_OneWeekAgo()
|
||||
public void TimeSpan_ToVerboseStringHistoric_OneWeekAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-7)).ToVerboseStringHistoric();
|
||||
|
||||
@@ -40,7 +44,7 @@ namespace Web.Tests.Utility
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_OneWeekOneDayAgo()
|
||||
public void TimeSpan_ToVerboseStringHistoric_OneWeekOneDayAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-8)).ToVerboseStringHistoric();
|
||||
|
||||
@@ -48,7 +52,7 @@ namespace Web.Tests.Utility
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_OneWeekTwoDaysAgo()
|
||||
public void TimeSpan_ToVerboseStringHistoric_OneWeekTwoDaysAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-9)).ToVerboseStringHistoric();
|
||||
|
||||
@@ -56,11 +60,51 @@ namespace Web.Tests.Utility
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_TwoWeeksAgo()
|
||||
public void TimeSpan_ToVerboseStringHistoric_TwoWeeksAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-7)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("1 week ago"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Type_GetPropertyNames()
|
||||
{
|
||||
var propertyNames = (typeof (LogImportViewModel).GetPropertyNames()).ToList();
|
||||
|
||||
Assert.That(propertyNames, Has.Member("Vehicle ID"));
|
||||
Assert.That(propertyNames, Has.Count.GreaterThan(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Enum_ParseWithDisplayNames_Short()
|
||||
{
|
||||
var result = typeof (MileageLogType).ParseWithDisplayNames("Comm");
|
||||
|
||||
Assert.That(result, Is.EqualTo(MileageLogType.Commuting));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Enum_ParseWithDisplayNames_Long()
|
||||
{
|
||||
var result = typeof (MileageLogType).ParseWithDisplayNames("Gas Purchase");
|
||||
|
||||
Assert.That(result, Is.EqualTo(MileageLogType.GasPurchase));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Enum_ParseWithDisplayNames_Default()
|
||||
{
|
||||
var result = typeof (MileageLogType).ParseWithDisplayNames("GasPurchase");
|
||||
|
||||
Assert.That(result, Is.EqualTo(MileageLogType.GasPurchase));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void Enum_ParseWithDisplayNames_Invalid()
|
||||
{
|
||||
typeof (MileageLogType).ParseWithDisplayNames("None");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.CreateLog;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.ViewModels.CreateLog
|
||||
{
|
||||
[TestFixture]
|
||||
public class LogImportViewModelTests
|
||||
{
|
||||
private LogImportViewModel GetTestModel()
|
||||
{
|
||||
return new LogImportViewModel
|
||||
{
|
||||
CityName = "City",
|
||||
Date = "10-20-2010",
|
||||
EndOdometer = "10010",
|
||||
GasPurchased = "1.123",
|
||||
LogType = "Commuting",
|
||||
Notes = "My Note",
|
||||
Purpose = "Training",
|
||||
VehicleId = "1021"
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: probably no longer need getlog
|
||||
[Test]
|
||||
public void GetLog_Correct()
|
||||
{
|
||||
var vm = GetTestModel();
|
||||
var log = vm.GetLog();
|
||||
Assert.That(log.CityName, Is.EqualTo(vm.CityName));
|
||||
Assert.That(log.Date, Is.EqualTo(new DateTime(2010,10,20)));
|
||||
Assert.That(log.Purpose.Purpose, Is.EqualTo("Training"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(AutoMapperMappingException))]
|
||||
public void GetLog_GasPurchased_NotNumber()
|
||||
{
|
||||
var vm = GetTestModel();
|
||||
vm.Date = "wrong";
|
||||
vm.GetLog();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(AutoMapperMappingException))]
|
||||
public void GetLog_Purpose_NotValid()
|
||||
{
|
||||
var vm = GetTestModel();
|
||||
vm.Purpose = "uh huh nope";
|
||||
var log = vm.GetLog();
|
||||
Assert.That(log.CityName, Is.EqualTo(vm.CityName));
|
||||
Assert.That(log.Date, Is.EqualTo(new DateTime(2010, 10, 20)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AutoMapper, Version=2.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Web\bin\AutoMapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ExcelLibrary">
|
||||
<HintPath>..\packages\ExcelLibrary.1.2011.7.30\lib\ExcelLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -84,6 +88,8 @@
|
||||
</CodeAnalysisDependentAssemblyPaths>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DAL\LogImporterTests.cs" />
|
||||
<Compile Include="DAL\LogImportTemplateWriterTests.cs" />
|
||||
<Compile Include="DAL\UserImporterTests.cs" />
|
||||
<Compile Include="DAL\VehicleImporterTests.cs" />
|
||||
<Compile Include="Utility\CryptoTests.cs" />
|
||||
@@ -91,6 +97,7 @@
|
||||
<Compile Include="Utility\AlgorithmsTests.cs" />
|
||||
<Compile Include="Utility\CustomExtensionsTests.cs" />
|
||||
<Compile Include="ViewModels\CreateLog\CreateLogViewModelTests.cs" />
|
||||
<Compile Include="ViewModels\CreateLog\LogImportViewModelTests.cs" />
|
||||
<Compile Include="ViewModels\Log\LogViewModelTests.cs" />
|
||||
<Compile Include="ViewModels\User\CreateUserViewModelTests.cs" />
|
||||
<Compile Include="ViewModels\User\EditUserViewModelTests.cs" />
|
||||
@@ -111,6 +118,18 @@
|
||||
<Content Include="DAL\UserEmails.xls">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="DAL\LogDocs\Logs.xls">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="DAL\LogDocs\Logs_IncorrectHeaders.xls">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="DAL\LogDocs\MileageTraker_ImportTemplate.xls">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="DAL\LogDocs\Logs_ErrorForEveryRow.xls">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
|
||||
@@ -12,4 +12,7 @@
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<connectionStrings>
|
||||
<add name="MileageTrakerContext" connectionString="Data Source=localhost;Initial Catalog=MileageTraker;Integrated Security=True;Connect Timeout=60" providerName="System.Data.SqlClient" />
|
||||
</connectionStrings>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user