113 lines
2.9 KiB
C#
113 lines
2.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using MileageTraker.Web.Models;
|
|
using MileageTraker.Web.Utility;
|
|
using MileageTraker.Web.ViewModels;
|
|
using MileageTraker.Web.ViewModels.CreateLog;
|
|
using MileageTraker.Web.ViewModels.Log;
|
|
using NUnit.Framework;
|
|
using ImportLogViewModel = MileageTraker.Web.ViewModels.Log.ImportLogViewModel;
|
|
|
|
namespace Web.Tests.Utility
|
|
{
|
|
[TestFixture]
|
|
public class CustomExtensionsTests
|
|
{
|
|
[Test]
|
|
public void TimeSpan_ToVerboseStringHistoric_Yesterday()
|
|
{
|
|
var s = (DateTime.Today - DateTime.Today.AddDays(-1)).ToVerboseStringHistoric();
|
|
|
|
Assert.That(s, Is.EqualTo("Yesterday"));
|
|
}
|
|
|
|
[Test]
|
|
public void TimeSpan_ToVerboseStringHistoric_Today()
|
|
{
|
|
var s = (DateTime.Today - DateTime.Today).ToVerboseStringHistoric();
|
|
|
|
Assert.That(s, Is.EqualTo("Today"));
|
|
}
|
|
|
|
[Test]
|
|
public void TimeSpan_ToVerboseStringHistoric_TwoDaysAgo()
|
|
{
|
|
var s = (DateTime.Today - DateTime.Today.AddDays(-2)).ToVerboseStringHistoric();
|
|
|
|
Assert.That(s, Is.EqualTo("2 days ago"));
|
|
}
|
|
|
|
[Test]
|
|
public void TimeSpan_ToVerboseStringHistoric_OneWeekAgo()
|
|
{
|
|
var s = (DateTime.Today - DateTime.Today.AddDays(-7)).ToVerboseStringHistoric();
|
|
|
|
Assert.That(s, Is.EqualTo("1 week ago"));
|
|
}
|
|
|
|
[Test]
|
|
public void TimeSpan_ToVerboseStringHistoric_OneWeekOneDayAgo()
|
|
{
|
|
var s = (DateTime.Today - DateTime.Today.AddDays(-8)).ToVerboseStringHistoric();
|
|
|
|
Assert.That(s, Is.EqualTo("1 week, 1 day ago"));
|
|
}
|
|
|
|
[Test]
|
|
public void TimeSpan_ToVerboseStringHistoric_OneWeekTwoDaysAgo()
|
|
{
|
|
var s = (DateTime.Today - DateTime.Today.AddDays(-9)).ToVerboseStringHistoric();
|
|
|
|
Assert.That(s, Is.EqualTo("1 week, 2 days ago"));
|
|
}
|
|
|
|
[Test]
|
|
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 (ImportLogViewModel).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");
|
|
}
|
|
}
|
|
}
|