WizardViewManagerTest.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » UnitTest » Windows » Forms » 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 » Windows » Forms » ViewManagers » WizardViewManagerTest.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;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.UnitTest.MockTypes;
using Ingenious.Mvc.Navigators;
using Ingenious.Mvc.ViewManagers;
using Ingenious.Mvc.Windows.Forms.ViewManagers;
using Ingenious.Mvc.Windows.Forms.Views;

namespace Ingenious.Mvc.UnitTest.Windows.Forms.ViewManagers{
  /// <summary>
  /// Unit tests the <see cref="WizardViewManager"/> class.
  /// </summary>
  public sealed class WizardViewManagerTest : UnitTestBase
  {
    private WizardViewManager _viewManager;

    protected override void SetUp()
    {
      _viewManager = new WizardViewManager("vm", TaskManager);
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The wizard view manager with ID 'viewManager' does not have a container view ID specified for it. You must specify the ID of the view to be used as a container for the wizard via the WizardViewManager.ContainerViewId property.")]
    public void TestNoContainerView()
    {
      Configure("ValidSimple");
      //clear the custom config, thus clearing the container view info
      TaskManager.ConfigurationInfo.NavigatorInfos["navigator"].ViewManagerInfo.CustomConfiguration = new WizardViewManager.CustomConfiguration();
      TaskManager.StartTask("navigator");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The wizard view manager with ID 'viewManager' has container view with ID 'view' specified for it. However, this view is of type 'Ingenious.Mvc.UnitTest.MockTypes.MockView' and does not implement the required interface 'Ingenious.Mvc.Windows.Forms.Views.IFormView'.")]
    public void TestDoesntImplementIFormView()
    {
      Configure("DoesntImplementIFormView");
      TaskManager.StartTask("navigator");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The wizard view manager with ID 'viewManager' has container view with ID 'view' specified for it. However, this view is of type 'Ingenious.Mvc.UnitTest.Windows.Forms.ViewManagers.WizardViewManagerTest+MockForm' and does not implement the required interface 'Ingenious.Mvc.Windows.Forms.Views.IUserControlContainer'.")]
    public void TestDoesntImplementIUserControlContainer()
    {
      Configure("DoesntImplementIUserControlContainer");
      TaskManager.StartTask("navigator");
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The view with ID 'view1' has type 'Ingenious.Mvc.UnitTest.MockTypes.MockView' as its type, but that type does not implement the required interface 'Ingenious.Mvc.Windows.Forms.Views.IUserControlView'.")]
    public void TestDoesntImplementIUserControlView()
    {
      Configure("DoesntImplementIUserControlView");
      TaskManager.StartTask("navigator");
    }

    [Test]
    public void TestValidSimple()
    {
      Configure("ValidSimple");
      Task task = TaskManager.StartTask("navigator");
      INavigator navigator = TaskManager.GetNavigatorForTask(task);
      WizardViewManager viewManager = (WizardViewManager) TaskManager.GetViewManagerForTask(task);
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.IsTrue((viewManager.GetContainerFormForTask(task) as MockFormView).WasModal);
      Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
    }

    [Test]
    public void TestValidComplex()
    {
      Configure("ValidComplex");
      Task task = TaskManager.StartTask("navigator");
      WizardNavigator navigator = (WizardNavigator) TaskManager.GetNavigatorForTask(task);
      WizardViewManager viewManager = (WizardViewManager) TaskManager.GetViewManagerForTask(task);
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.IsTrue((viewManager.GetContainerFormForTask(task) as MockFormView).WasModal);
      Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
      //go to view2
      navigator.NavigateToNext();
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.AreEqual("view2", viewManager.ActiveView.Id.ToString());
      //back to view1
      navigator.NavigateToPrevious();
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
      //through to view5
      navigator.NavigateToNext();
      navigator.NavigateToNext();
      navigator.NavigateToNext();
      navigator.NavigateToNext();
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.AreEqual("view5", viewManager.ActiveView.Id.ToString());
      //back to view1 again
      navigator.NavigateToPrevious();
      navigator.NavigateToPrevious();
      navigator.NavigateToPrevious();
      navigator.NavigateToPrevious();
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
    }

    [Test]
    public void TestValidNonModal()
    {
      Configure("ValidNonModal");
      Task task = TaskManager.StartTask("navigator");
      INavigator navigator = TaskManager.GetNavigatorForTask(task);
      WizardViewManager viewManager = (WizardViewManager) TaskManager.GetViewManagerForTask(task);
      Assert.IsNotNull(viewManager.ActiveView);
      Assert.IsFalse((viewManager.GetContainerFormForTask(task) as MockFormView).WasModal);
      Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestSetCustomConfigurationNull()
    {
      ((ICustomConfigurable) _viewManager).SetCustomConfiguration(null);
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "The WizardViewManager requires an instance of 'Ingenious.Mvc.Windows.Forms.ViewManagers.WizardViewManager+CustomConfiguration' for its custom configuration but was given an instance of 'System.String'.")]
    public void TestSetCustomConfigurationWrongType()
    {
      ((ICustomConfigurable) _viewManager).SetCustomConfiguration("test");
    }

    [Test]
    public void TestSetCustomConfigurationValid()
    {
      Ingenious.Mvc.Windows.Forms.ViewManagers.WizardViewManager.CustomConfiguration customConfig = new Ingenious.Mvc.Windows.Forms.ViewManagers.WizardViewManager.CustomConfiguration();
      customConfig.ContainerName = "containerName";
      customConfig.ContainerViewId = "containerViewId";
      ((ICustomConfigurable) _viewManager).SetCustomConfiguration(customConfig);
      Assert.AreEqual("containerName", _viewManager.ContainerName);
      Assert.AreEqual("containerViewId", _viewManager.ContainerViewId.ToString());
    }

    #region Supporting Types

    private sealed class MockForm : IFormView
    {
      public bool LeaveOpen
      {
        get
        {
          return false;
        }
      }

      public bool IsModal
      {
        get
        {
          return false;
        }
      }

      public bool IsMdiChild
      {
        get
        {
          return false;
        }
      }

      public bool IsFloating
      {
        get
        {
          return false;
        }
      }

      public Id<IView> ParentId
      {
        get
        {
          return Id<IView>.Empty;
        }
      }

      public IController Controller
      {
        get
        {
          return null;
        }
        set
        {
        }
      }

      [field: NonSerialized]
      public event EventHandler<EventArgs> Activated;
      [field: NonSerialized]
      public event EventHandler<EventArgs> Deactivated;

      public bool SingleInstance
      {
        get
        {
          return false;
        }
      }

      public void Close()
      {
      }

      public void SetParent(IFormView parentView)
      {
      }

      public void ChildOpening(Ingenious.Mvc.Windows.Forms.Views.IFormView childView)
      {
      }

      public void ChildClosed(Ingenious.Mvc.Windows.Forms.Views.IFormView childView)
      {
      }

      public void Show(bool modal)
      {
      }

      public event EventHandler<EventArgs> Closed;

      public Id<IView> Id
      {
        get
        {
          return Id<IView>.Empty;
        }
        set
        {
        }
      }

      public void Initialize()
      {
      }

      public void SetData(object data)
      {
      }

      public Task Task
      {
        get
        {
          return null;
        }
        set
        {
        }
      }
    }

    #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.