#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Ingenious.Mvc;
using Ingenious.Mvc.Windows.Forms;
namespace Ingenious.Mvc.UnitTest.Windows{
/// <summary>
/// Unit tests the <see cref="ApplicationContext"/> class.
/// </summary>
public sealed class ApplicationContextTest : UnitTestBase
{
private ApplicationContext _applicationContext;
private bool _threadExited;
protected override void SetUp()
{
base.SetUp();
CustomApplicationContext.Parent = this;
_threadExited = false;
_applicationContext = new CustomApplicationContext("Task Data");
}
[Test]
[ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.INavigator was illegally provided for argument 'startingNavigator'.")]
public void TestStartingNavigatorEmpty()
{
_applicationContext = new ApplicationContext(Id<INavigator>.Empty);
}
[Test]
public void TestValid()
{
_applicationContext.ThreadExit += delegate
{
_threadExited = true;
};
Assert.IsNotNull(_applicationContext.MainTask);
Assert.AreEqual("Task Data", _applicationContext.MainTask.Data);
INavigator navigator = _applicationContext.MainTask.Manager.GetNavigatorForTask(_applicationContext.MainTask);
Assert.IsNotNull(navigator);
Assert.AreEqual("navigator", navigator.Id.ToString());
Assert.IsFalse(_threadExited);
//end the task
_applicationContext.MainTask.End();
//and make sure the thread was shut down
Assert.IsTrue(_threadExited);
}
#region Supporting Types
private sealed class CustomApplicationContext : ApplicationContext
{
//no way to pass into constructor since the base constructor calls the virtual methods
public static ApplicationContextTest Parent;
public CustomApplicationContext(object taskData) : base("navigator", taskData)
{
}
protected override TaskManager GetTaskManager()
{
return Parent.TaskManager;
}
protected override void Configure(TaskManager taskManager)
{
//this will configure the same task manager returned by GetTaskManager
Parent.Configure("Valid");
}
}
#endregion
}
}
|