ViewManagerBaseTest.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » UnitTest » ViewManagers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Web Frameworks » Ingenious MVC 
Ingenious MVC » Ingenious » Mvc » UnitTest » ViewManagers » ViewManagerBaseTest.cs
#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 NUnit.Framework;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.ViewManagers;
using Ingenious.Mvc.UnitTest.MockTypes;

namespace Ingenious.Mvc.UnitTest.ViewManagers{
  /// <summary>
  /// Unit tests the <see cref="ViewManagerBase"/> class.
  /// </summary>
  public sealed class ViewManagerBaseTest : UnitTestBase
  {
    private ConcreteViewManager _viewManager;

    protected override void SetUp()
    {
      Id<IViewManager> id = "vm";
      _viewManager = new ConcreteViewManager(id, TaskManager);
    }

    [Test]
    [ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IViewManager was illegally provided for argument 'id'.")]
    public void TestConstructorIdEmpty()
    {
      _viewManager = new ConcreteViewManager(Id<IViewManager>.Empty, TaskManager);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestConstructorTaskManagerNull()
    {
      _viewManager = new ConcreteViewManager("vm", null);
    }

    [Test]
    public void TestConstructor()
    {
      Id<IViewManager> id = "vm";
      _viewManager = new ConcreteViewManager(id, TaskManager);
      Assert.AreEqual(id, _viewManager.Id);
      Assert.AreSame(TaskManager, _viewManager.TaskManager);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestActivateTaskNull1()
    {
      _viewManager.Activate(null, (string) null, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestActivateTaskNull2()
    {
      _viewManager.Activate(null, (Enum) null, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestActivateViewIdNull1()
    {
      _viewManager.Activate(CreateTask(), (string) null, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestActivateViewIdNull2()
    {
      _viewManager.Activate(CreateTask(), (Enum) null, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestCreateViewNullTask()
    {
      _viewManager.CreateView(null, "viewId");
    }

    [Test]
    [ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IView was illegally provided for argument 'viewId'.")]
    public void TestCreateViewViewIdEmpty()
    {
      _viewManager.CreateView(CreateTask(), Id<IView>.Empty);
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "No configuration has been supplied via the TaskManager.Configuration property.")]
    public void TestCreateViewNoConfiguration()
    {
      _viewManager.CreateView(CreateTask(), "v");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "A view with ID 'v' could not be found.")]
    public void TestCreateViewViewNotFound()
    {
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      _viewManager.CreateView(CreateTask(), "v");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "There is no type specified for the view with ID 'v'.")]
    public void TestCreateViewNoTypeForView()
    {
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("v"));
      _viewManager.CreateView(CreateTask(), "v");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The view with ID 'v' has controller with ID 'c', but no type has been provided for the controller.")]
    public void TestCreateViewNoTypeForController()
    {
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      TaskManager.ConfigurationInfo.ViewFactory = new MockViewFactory();
      ViewInfo viewInfo = new ViewInfo("v");
      viewInfo.Type = typeof(MockView);
      viewInfo.ControllerInfo = new ControllerInfo("c");
      TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
      _viewManager.CreateView(CreateTask(), "v");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The configured view factory failed to create a view instance for the view with ID 'v'.")]
    public void TestCreateViewFactoryFailure()
    {
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      TaskManager.ConfigurationInfo.ViewFactory = new MockViewFactory();
      ViewInfo viewInfo = new ViewInfo("v");
      viewInfo.Type = typeof(MockView);
      viewInfo.ControllerInfo = new ControllerInfo("c");
      viewInfo.ControllerInfo.Type = typeof(MockController);
      TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
      _viewManager.CreateView(CreateTask(), "v");
    }

    [Test]
    public void TestValidNoController()
    {
      MockView view = new MockView();
      MockViewFactory viewFactory = new MockViewFactory();
      viewFactory.View = view;
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      TaskManager.ConfigurationInfo.ViewFactory = viewFactory;
      ViewInfo viewInfo = new ViewInfo("v");
      viewInfo.Type = typeof(MockView);
      TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
      NavigatorInfo navigatorInfo = new NavigatorInfo("n");
      navigatorInfo.Type = typeof(MockNavigator);
      ViewManagerInfo viewManagerInfo = new ViewManagerInfo("vm");
      viewManagerInfo.Type = typeof(Ingenious.Mvc.UnitTest.MockTypes.MockViewManager);
      navigatorInfo.ViewManagerInfo = viewManagerInfo;
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      TaskManager.ConfigurationInfo.NavigatorInfos.Add(navigatorInfo);
      Task t = TaskManager.StartTask("n");
      MockView createdView = (MockView) _viewManager.CreateView(t, "v");
      Assert.IsNotNull(createdView);
      Assert.IsNull(createdView.Controller);
    }

    [Test]
    public void TestCreateViewValid()
    {
      MockView view = new MockView();
      MockViewFactory viewFactory = new MockViewFactory();
      viewFactory.View = view;
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      TaskManager.ConfigurationInfo.ViewFactory = viewFactory;
      ViewInfo viewInfo = new ViewInfo("v");
      viewInfo.Type = typeof(MockView);
      viewInfo.ControllerInfo = new ControllerInfo("c");
      viewInfo.ControllerInfo.Type = typeof(MockController);
      TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
      NavigatorInfo navigatorInfo = new NavigatorInfo("n");
      navigatorInfo.Type = typeof(MockNavigator);
      ViewManagerInfo viewManagerInfo = new ViewManagerInfo("vm");
      viewManagerInfo.Type = typeof(Ingenious.Mvc.UnitTest.MockTypes.MockViewManager);
      navigatorInfo.ViewManagerInfo = viewManagerInfo;
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      TaskManager.ConfigurationInfo.NavigatorInfos.Add(navigatorInfo);
      Task t = TaskManager.StartTask("n");
      IView createdView = _viewManager.CreateView(t, "v");
      Assert.IsNotNull(createdView);
      Assert.AreSame(view, createdView);
    }

    #region Supporting Types

    private sealed class ConcreteViewManager : ViewManagerBase
    {
      public new TaskManager TaskManager
      {
        get
        {
          return base.TaskManager;
        }
      }

      public ConcreteViewManager(Id<IViewManager> id, TaskManager taskManager) : base(id, taskManager)
      {
      }

      public IView CreateView(Task task, Id<IView> viewId)
      {
        return ViewManagerBase.CreateView(task, viewId);
      }

      public override IView Activate(Task task, Id<IView> viewId, object viewData)
      {
        return null;
      }
    }

    #endregion
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.