using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Ingenious.Mvc.Web.Forms;
namespace Ingenious.Mvc.UnitTest.Web{
[TestFixture]
public sealed class HttpApplicationTest : UnitTestBase
{
private CustomHttpApplication _httpApplication;
private MockHttpBridge _httpBridge;
protected override void SetUp()
{
base.SetUp();
_httpApplication = new CustomHttpApplication(this);
_httpBridge = new MockHttpBridge();
HttpApplication.HttpBridge = _httpBridge;
}
[Test]
[ExpectedException(typeof(IdException), "No root task ID was specified. Override or set the Ingenious.Mvc.Web.Forms.HttpApplication.RootTaskId property.")]
public void TestSessionStartNoRootId()
{
_httpApplication.Session_Start(this, EventArgs.Empty);
}
[Test]
public void TestSessionStart()
{
_httpApplication.SetRootTaskId("navigator");
Assert.AreEqual(0, TaskManager.Tasks.Count);
_httpApplication.Session_Start(this, EventArgs.Empty);
Assert.IsTrue(_httpApplication.SessionStart);
Assert.AreEqual(1, TaskManager.Tasks.Count);
}
#region Supporting Types
private sealed class CustomHttpApplication : HttpApplication
{
private HttpApplicationTest _parent;
private bool _sessionStart;
private Id<INavigator> _rootTaskId;
public bool SessionStart
{
get
{
return _sessionStart;
}
}
protected override Id<INavigator> RootTaskId
{
get
{
return _rootTaskId;
}
}
public CustomHttpApplication(HttpApplicationTest parent)
{
_parent = parent;
}
protected override TaskManager GetTaskManager()
{
return _parent.TaskManager;
}
protected override void Configure(TaskManager taskManager)
{
_parent.Configure("Valid");
}
protected override void OnSessionStart(object sender, EventArgs e)
{
base.OnSessionStart(sender, e);
_sessionStart = true;
}
public void SetRootTaskId(Id<INavigator> rootTaskId)
{
_rootTaskId = rootTaskId;
}
}
private sealed class MockHttpBridge : HttpApplication.IHttpBridge
{
private string _appRelativeCurrentExecutionFilePath = "~/Default.aspx";
private string _rawUrl;
private string _lastRedirect;
public string AppRelativeCurrentExecutionFilePath
{
get
{
return _appRelativeCurrentExecutionFilePath;
}
set
{
_appRelativeCurrentExecutionFilePath = value;
}
}
public string RawUrl
{
get
{
return _rawUrl;
}
set
{
_rawUrl = value;
}
}
public string LastRedirect
{
get
{
return _lastRedirect;
}
}
public void Redirect(string url)
{
_lastRedirect = url;
}
}
#endregion
}
}
|