Initial
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using MileageTraker.Web.Controllers;
|
||||
using System;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using System.Web.Mvc;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests
|
||||
{
|
||||
/// <summary>
|
||||
///This is a test class for CreateLogControllerTest and is intended
|
||||
///to contain all CreateLogControllerTest Unit Tests
|
||||
///</summary>
|
||||
[TestFixture]
|
||||
public class CreateLogControllerTest
|
||||
{
|
||||
[Test]
|
||||
public void IndexTest()
|
||||
{
|
||||
var target = new CreateLogController();
|
||||
CreateLogViewModel model = null;
|
||||
ActionResult expected = null;
|
||||
ActionResult actual;
|
||||
|
||||
actual = target.Index(model);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
Assert.Inconclusive("Verify the correctness of this test method.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ExcelLibrary.SpreadSheet;
|
||||
using MileageTraker.Web.DAL;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.DAL
|
||||
{
|
||||
[TestFixture]
|
||||
public class VehicleImporterTests
|
||||
{
|
||||
[Test]
|
||||
public void Import_Gets_More_Than_One_Result()
|
||||
{
|
||||
var vehicles = VehicleImporter.Import("DAL\\Vehicles.xls");
|
||||
|
||||
Assert.That(vehicles.Count(), Is.GreaterThan(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Export_Saves_A_File()
|
||||
{
|
||||
var vehicles = VehicleImporter.Import("DAL\\Vehicles.xls");
|
||||
const string filename = @"VehiclesExport.xls";
|
||||
VehicleImporter.Export(vehicles, filename);
|
||||
Assert.That(File.Exists(filename));
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Web.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("Web.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("76250afd-71db-419d-9cac-e10201c622f0")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using MileageTraker.Web.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.Utility
|
||||
{
|
||||
[TestFixture]
|
||||
public class AlgorithmsTests
|
||||
{
|
||||
private const int _existingNumber = 2;
|
||||
private readonly DateTime _existingDate = DateTime.Today.AddDays(-1);
|
||||
|
||||
[Test]
|
||||
public void IsChronological_True_If_Greater_And_After()
|
||||
{
|
||||
var date = _existingDate.AddDays(1);
|
||||
const int number = _existingNumber + 1;
|
||||
var result = Algorithms.IsChronological(_existingDate, _existingNumber, date, number);
|
||||
|
||||
Assert.That(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsChronological_False_If_LessThan_And_After()
|
||||
{
|
||||
var date = _existingDate.AddDays(1);
|
||||
const int number = _existingNumber - 1;
|
||||
var result = Algorithms.IsChronological(_existingDate, _existingNumber, date, number);
|
||||
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsChronological_True_If_LessThan_And_Before()
|
||||
{
|
||||
var date = _existingDate.AddDays(-1);
|
||||
const int number = _existingNumber - 1;
|
||||
var result = Algorithms.IsChronological(_existingDate, _existingNumber, date, number);
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsChronological_False_If_GreaterThan_And_Before()
|
||||
{
|
||||
var date = _existingDate.AddDays(-1);
|
||||
const int number = _existingNumber + 1;
|
||||
var result = Algorithms.IsChronological(_existingDate, _existingNumber, date, number);
|
||||
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsChronological_True_If_Same_And_Before()
|
||||
{
|
||||
var date = _existingDate.AddDays(-1);
|
||||
const int number = _existingNumber;
|
||||
var result = Algorithms.IsChronological(_existingDate, _existingNumber, date, number);
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void IsChronological_True_If_Greater_And_SameTime()
|
||||
{
|
||||
var date = _existingDate;
|
||||
const int number = _existingNumber + 1;
|
||||
var result = Algorithms.IsChronological(_existingDate, _existingNumber, date, number);
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MileageTraker.Web.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.Utility
|
||||
{
|
||||
[TestFixture]
|
||||
public class CustomExtensionsTests
|
||||
{
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_Yesterday()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-1)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("Yesterday"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_Today()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("Today"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_TwoDaysAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-2)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("2 days ago"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_OneWeekAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-7)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("1 week ago"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_OneWeekOneDayAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-8)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("1 week, 1 day ago"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_OneWeekTwoDaysAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-9)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("1 week, 2 days ago"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TimeSpan_ToReadableString_TwoWeeksAgo()
|
||||
{
|
||||
var s = (DateTime.Today - DateTime.Today.AddDays(-7)).ToVerboseStringHistoric();
|
||||
|
||||
Assert.That(s, Is.EqualTo("1 week ago"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Web.Tests.ViewModels
|
||||
{
|
||||
[TestFixture]
|
||||
public class CreateLogViewModelTests
|
||||
{
|
||||
[Test]
|
||||
public void GetLog_Converts_To_Log()
|
||||
{
|
||||
var cityName = "My Town";
|
||||
var date = DateTime.Today.ToString("d");
|
||||
var employeeName = "Name";
|
||||
var endOdometer = "1234";
|
||||
var ethraId = "4567";
|
||||
string gasPurchased = "2.546";
|
||||
var mileageLogType = new MileageLogTypeWrapper {Enum = MileageLogType.Commuting};
|
||||
|
||||
var viewModel =
|
||||
new CreateLogViewModel
|
||||
{
|
||||
CityName = cityName,
|
||||
Date = date,
|
||||
EmployeeName = employeeName,
|
||||
EndOdometer = endOdometer,
|
||||
VehicleId = ethraId,
|
||||
GasPurchased = gasPurchased,
|
||||
LogType = mileageLogType
|
||||
};
|
||||
|
||||
var log = viewModel.GetLog();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ctor_Initializes_From_Log()
|
||||
{
|
||||
var cityName = "My Town";
|
||||
var date = DateTime.Today;
|
||||
var employeeName = "Name";
|
||||
var endOdometer = 1234;
|
||||
var ethraId = "4567";
|
||||
var gasPurchased = 2.546d;
|
||||
var mileageLogType = MileageLogType.Commuting;
|
||||
|
||||
var log =
|
||||
new Log
|
||||
{
|
||||
CityName = cityName,
|
||||
Date = date,
|
||||
EmployeeName = employeeName,
|
||||
EndOdometer = endOdometer,
|
||||
VehicleId = ethraId,
|
||||
GasPurchased = gasPurchased,
|
||||
LogType = mileageLogType
|
||||
};
|
||||
|
||||
var viewModel = new CreateLogViewModel(log);
|
||||
|
||||
Assert.That(viewModel.CityName, Is.EqualTo(cityName));
|
||||
Assert.That(viewModel.Date, Is.EqualTo(date.ToString("d")));
|
||||
Assert.That(viewModel.EmployeeName, Is.EqualTo(employeeName));
|
||||
Assert.That(viewModel.EndOdometer, Is.EqualTo(endOdometer.ToString()));
|
||||
Assert.That(viewModel.VehicleId, Is.EqualTo(ethraId));
|
||||
Assert.That(viewModel.GasPurchased, Is.EqualTo(gasPurchased.ToString()));
|
||||
Assert.That(viewModel.LogType.Enum, Is.EqualTo(mileageLogType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>
|
||||
</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{A2CF2B7A-A0A7-4A32-895C-A7B4DBC57722}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Web.Tests</RootNamespace>
|
||||
<AssemblyName>Web.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ExcelLibrary">
|
||||
<HintPath>..\packages\ExcelLibrary.1.2011.7.30\lib\ExcelLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Abstractions" />
|
||||
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="System.Web.Routing">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
|
||||
<Visible>False</Visible>
|
||||
</CodeAnalysisDependentAssemblyPaths>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CreateLogControllerTest.cs" />
|
||||
<Compile Include="DAL\VehicleImporterTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utility\AlgorithmsTests.cs" />
|
||||
<Compile Include="Utility\CustomExtensionsTests.cs" />
|
||||
<Compile Include="ViewModels\CreateLogViewModelTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="DAL\Vehicles.xls">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Web\Web.csproj">
|
||||
<Project>{36D4C321-E918-460F-B348-16A805F88884}</Project>
|
||||
<Name>Web</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ExcelLibrary" version="1.2011.7.30" />
|
||||
<package id="NUnit" version="2.6.0.12054" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user