This project is read-only.

Project: TrialApplication


The test class used to validate a serial number:
[TestClass]
public class ApplicationServiceTest
{
	private const string Serial = "001";

	[TestMethod]
	public void CheckNullSerialIsNotValid()
	{
		this.InitializeService()
			.IsValid(null)
			.Should("Null serial is classified as valid.")
			.Be
			.False();
	}

	[TestMethod]
	public void CheckNotValidSerialIsNotValid()
	{
		this.InitializeService()
			.IsValid(Serial)
			.Should("Not existing serial is classified as valid.")
			.Be
			.False();
	}

	[TestMethod]
	public void CheckValidSerialExpiredIsNotValid()
	{
		InitializeService(new Application { Serial = Serial, ExpirationDate = DateTime.Now.AddDays(15) })
			.IsValid(Serial)
			.Should("Valid serial but expired is classified as valid.")
			.Be
			.False();
	}

	[TestMethod]
	public void CheckValidSerialIsValid()
	{
		InitializeService(new Application { Serial = Serial, ExpirationDate = DateTime.Now })
			.IsValid(Serial)
			.Should("Valid serial is classified as not valid.")
			.Be
			.True();
	}

	private ApplicationService InitializeService(params Application[] applicationCollection)
	{
		var applicationContext = new Mock<IApplicationContext>();

		var applicationRepository = GetRepository(applicationCollection);

		applicationContext
			.SetupGet(x => x.ApplicationRepository)
			.Returns(applicationRepository.Object);

		return new ApplicationService(applicationContext.Object);
	}

	private Mock<IRepository<Application>> GetRepository(params Application[] applicationCollection)
	{
		var applicationRepository = new Mock<IRepository<Application>>();

		var list = 
			new List<Application>(applicationCollection)
				.AsQueryable();

		applicationRepository
			.SetupGet(x => x.Provider)
			.Returns(list.Provider);

		applicationRepository
			.SetupGet(x => x.Expression)
			.Returns(list.Expression);

		return applicationRepository;
	}
}

Last edited Oct 5, 2011 at 1:14 PM by teoarch, version 2

Comments

No comments yet.