DefaultNavigatorFactoryTest.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » UnitTest » Factories » 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 » Factories » DefaultNavigatorFactoryTest.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.Factories;
using Ingenious.Mvc.UnitTest.MockTypes;

namespace Ingenious.Mvc.UnitTest.Factories{
  /// <summary>
  /// Unit tests the <see cref="DefaultNavigatorFactory"/> class.
  /// </summary>
  public sealed class DefaultNavigatorFactoryTest : UnitTestBase
  {
    private INavigatorFactory _factory;

    protected override void SetUp()
    {
      _factory = DefaultNavigatorFactory.Instance;
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestNullNavigator()
    {
      _factory.Create(null, null, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestNullTask()
    {
      _factory.Create(new NavigatorInfo("Test"), null, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestNullViewManager()
    {
      _factory.Create(new NavigatorInfo("Test"), CreateTask(), null);
    }

    [Test]
    [ExpectedException(typeof(FactoryException), "There is no type specified for the navigator with ID 'Test'.")]
    public void TestNullType()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      _factory.Create(navigatorInfo, CreateTask(), new MockViewManager(TaskManager));
    }

    [Test]
    [ExpectedException(typeof(FactoryException), "There is no starting view specified for the navigator with ID 'Test'.")]
    public void TestNullStartingView()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      navigatorInfo.Type = typeof(MockNavigator);
      _factory.Create(navigatorInfo, CreateTask(), new MockViewManager(TaskManager));
    }

    [Test]
    [ExpectedException(typeof(FactoryException), "The property 'Id' on type 'Ingenious.Mvc.UnitTest.Factories.DefaultNavigatorFactoryTest+NoConstructorNoProperty' is not writable.")]
    public void TestNoConstructorNoProperty()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      navigatorInfo.Type = typeof(NoConstructorNoProperty);
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      _factory.Create(navigatorInfo, CreateTask(), new MockViewManager(TaskManager));
    }

    [Test]
    public void TestImplementsConstructor()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      navigatorInfo.Type = typeof(ImplementsConstructor);
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      MockViewManager viewManager = new MockViewManager(TaskManager);
      ImplementsConstructor navigator = (ImplementsConstructor) _factory.Create(navigatorInfo, CreateTask(), viewManager);
      Assert.AreEqual("Test", navigator.Id.ToString());
      Assert.AreEqual(TaskManager, navigator.Task.Manager);
      Assert.AreEqual("v", navigator.StartingViewId.ToString());
      Assert.AreEqual(viewManager, navigator.ViewManager);
    }

    [Test]
    public void TestImplementsProperty()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      navigatorInfo.Type = typeof(ImplementsProperty);
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      MockViewManager viewManager = new MockViewManager(TaskManager);
      ImplementsProperty navigator = (ImplementsProperty) _factory.Create(navigatorInfo, CreateTask(), viewManager);
      Assert.AreEqual("Test", navigator.Id.ToString());
      Assert.AreEqual(TaskManager, navigator.Task.Manager);
      Assert.AreEqual("v", navigator.StartingViewId.ToString());
      Assert.AreEqual(viewManager, navigator.ViewManager);
    }

    [Test]
    public void TestCustomConfiguration()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      navigatorInfo.Type = typeof(ConfigurableNavigator);
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      navigatorInfo.CustomConfiguration = new object();
      MockViewManager viewManager = new MockViewManager(TaskManager);
      ConfigurableNavigator navigator = (ConfigurableNavigator) _factory.Create(navigatorInfo, CreateTask(), viewManager);
      Assert.AreEqual("Test", navigator.Id.ToString());
      Assert.AreEqual(TaskManager, navigator.Task.Manager);
      Assert.AreEqual("v", navigator.StartingViewId.ToString());
      Assert.AreEqual(viewManager, navigator.ViewManager);
      Assert.AreEqual(navigatorInfo.CustomConfiguration, navigator.CustomConfiguration);
    }

    [Test]
    public void TestInitialize()
    {
      NavigatorInfo navigatorInfo = new NavigatorInfo("Test");
      navigatorInfo.Type = typeof(MockNavigator);
      navigatorInfo.StartViewInfo = new ViewInfo("v");
      MockViewManager viewManager = new MockViewManager(TaskManager);
      MockNavigator navigator = (MockNavigator) _factory.Create(navigatorInfo, CreateTask(), viewManager);
      Assert.AreEqual("Test", navigator.Id.ToString());
      Assert.AreEqual(TaskManager, navigator.Task.Manager);
      Assert.AreEqual("v", navigator.StartingViewId.ToString());
      Assert.AreEqual(viewManager, navigator.ViewManager);
      Assert.IsTrue(navigator.Initialized);
    }

    #region Supporting Types

    private abstract class NavigatorBase : INavigator
    {
      public abstract Id<INavigator> Id
      {
        get;
      }

      public abstract Task Task
      {
        get;
      }

      public abstract Id<IView> StartingViewId
      {
        get;
      }

      public virtual bool CanNavigateTo(string viewId)
      {
        return CanNavigateTo(viewId);
      }

      public virtual bool CanNavigateTo(Enum viewId)
      {
        return CanNavigateTo(viewId);
      }

      public virtual bool CanNavigateTo(Id<IView> viewId)
      {
        return true;
      }

      public IView NavigateTo(Id<IView> viewId)
      {
        return NavigateTo(viewId, null);
      }

      public abstract IView NavigateTo(Id<IView> viewId, object viewData);

      public virtual void Initialize()
      {
      }
    }

    private sealed class DoesNotImplementINavigator
    {
    }

    private sealed class NoConstructorNoProperty : NavigatorBase
    {
      public IViewManager ViewManager
      {
        get
        {
          return null;
        }
      }

      public override Id<INavigator> Id
      {
        get
        {
          return Id<INavigator>.Empty;
        }
      }

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

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

      public NoConstructorNoProperty()
      {
      }

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

    private sealed class ImplementsConstructor : NavigatorBase
    {
      private Id<INavigator> _id;
      private Task _task;
      private Id<IView> _startingViewId;
      private IViewManager _viewManager;

      public IViewManager ViewManager
      {
        get
        {
          return _viewManager;
        }
      }

      public override Id<INavigator> Id
      {
        get
        {
          return _id;
        }
      }

      public override Task Task
      {
        get
        {
          return _task;
        }
      }

      public override Id<IView> StartingViewId
      {
        get
        {
          return _startingViewId;
        }
      }

      public ImplementsConstructor(Id<INavigator> id, Task task, Id<IView> startingViewId, IViewManager viewManager)
      {
        _id = id;
        _task = task;
        _startingViewId = startingViewId;
        _viewManager = viewManager;
      }

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

    private class ImplementsProperty : INavigator
    {
      private Id<INavigator> _id;
      private Task _task;
      private Id<IView> _startingViewId;
      private IViewManager _viewManager;

      public Id<INavigator> Id
      {
        get
        {
          return _id;
        }
        set
        {
          _id = value;
        }
      }

      public Task Task
      {
        get
        {
          return _task;
        }
        set
        {
          _task = value;
        }
      }

      public Id<IView> StartingViewId
      {
        get
        {
          return _startingViewId;
        }
        set
        {
          _startingViewId = value;
        }
      }

      public IViewManager ViewManager
      {
        get
        {
          return _viewManager;
        }
        set
        {
          _viewManager = value;
        }
      }

      public virtual bool CanNavigateTo(string viewId)
      {
        return CanNavigateTo(viewId);
      }

      public virtual bool CanNavigateTo(Enum viewId)
      {
        return CanNavigateTo(viewId);
      }

      public virtual bool CanNavigateTo(Id<IView> viewId)
      {
        return true;
      }

      public IView NavigateTo(Id<IView> viewId)
      {
        return NavigateTo(viewId, null);
      }

      public IView NavigateTo(Id<IView> viewId, object viewData)
      {
        return null;
      }

      public void Initialize()
      {
      }
    }

    private sealed class ConfigurableNavigator : ImplementsProperty, ICustomConfigurable
    {
      private object _customConfiguration;

      public object CustomConfiguration
      {
        get
        {
          return _customConfiguration;
        }
      }

      public void SetCustomConfiguration(object customConfiguration)
      {
        _customConfiguration = customConfiguration;
      }
    }

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