MockMarshalByValueComponent.cs :  » Testing » MockObjects » DotNetMock » Framework » ComponentModel » 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 » Testing » MockObjects 
MockObjects » DotNetMock » Framework » ComponentModel » MockMarshalByValueComponent.cs
using System;
using System.Collections;
using System.ComponentModel;
using DotNetMock;

namespace DotNetMock.Framework.ComponentModel{
  /// <summary>
  /// Base MockObject for remotable components that are marshaled by value.
  /// </summary>
  public class MockMarshalByValueComponent : MockObject, IComponent, IDisposable, IServiceProvider
  {
    private IContainer _expectedContainer = null;
    private bool _expectedDesignMode = false;
    private ISite _expectedSite = null;
    private Hashtable _serviceProviders = null;
    
    private ExpectationCounter _getServiceCalls = new ExpectationCounter( "MockMarshalByValueComponent.GetServiceCalls" );

    /// <summary>
    /// Default COnstructor
    /// </summary>
    public MockMarshalByValueComponent() : base("MockMarshalByValueComponent")
    {
      _serviceProviders = new Hashtable();
    }
    #region Mock Methods
    /// <summary>
    /// Sets the expected object that implements the IContainer interface that should be returned
    /// by the Container property.
    /// </summary>
    /// <param name="container">Expected Container</param>
    public void SetExpectedContainer( IContainer container )
    {
      _expectedContainer = container;
    }
    /// <summary>
    /// Sets the expected value for the DesignMode property to return
    /// </summary>
    /// <param name="designMode">Expected Value</param>
    public void SetExpectedDesignMode( bool designMode )
    {
      _expectedDesignMode = designMode;
    }
    /// <summary>
    /// Sets the expected object, that implements the ISite interface, to be returned via the Site property
    /// </summary>
    /// <param name="site">Expected Site</param>
    public void SetExpectedSite( ISite site )
    {
      _expectedSite = site;
    }
    /// <summary>
    /// Sets the number of expected GetService() calls that are to be made on this object.
    /// </summary>
    /// <param name="count">Expected Count</param>
    public void SetExpectedGetServiceCalls( int count )
    {
      _getServiceCalls.Expected = count;
    }
    /// <summary>
    /// Sets the expected service provider to be returned from GetService() when called for the given
    /// Type
    /// </summary>
    /// <param name="serviceProvider">Expected IServiceProvider</param>
    /// <param name="serviceType">Type to associate with the Expected IServiceProvider</param>
    public void SetExpectedServiceProvider( IServiceProvider serviceProvider , Type serviceType )
    {
      _serviceProviders.Add( serviceType, serviceProvider );
    }
    #endregion

    #region Public Properties

    /// <summary>
    /// Gets the container for the component.
    /// </summary>
    public IContainer Container
    {
      get { return _expectedContainer; }
    }
    /// <summary>
    /// Gets a value indicating whether the component is currently in design mode.
    /// </summary>
    public bool DesignMode
    {
      get 
      {
        if ( _expectedSite == null )
        {
          return false;
        }
        return _expectedDesignMode;
      }
    }
    #endregion

    #region Implementation of IComponent

    /// <summary>
    /// Adds an event handler to listen to the Disposed event on the component.
    /// </summary>
    public event System.EventHandler Disposed;

    /// <summary>
    /// Gets or sets the site of the component.
    /// </summary>
    public System.ComponentModel.ISite Site
    {
      get
      {
        return _expectedSite;
      }
      set
      {
        _expectedSite = value;
      }
    }
    #endregion

    #region Implementation of IDisposable
    /// <summary>
    /// Releases all resources used by the MarshalByValueComponent.
    /// </summary>
    public void Dispose()
    {
      Dispose( false );
    }
    /// <summary>
    /// Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.
    /// </summary>
    /// <param name="dispose">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
    public void Dispose( bool dispose )
    {
      Disposed( this, null );
    }
    #endregion

    #region Implementation of IServiceProvider
    /// <summary>
    /// Gets the implementer of the IServiceProvider.
    /// </summary>
    /// <param name="serviceType">Gets the implementer of the IServiceProvider.</param>
    /// <returns>An Object that represents the implementer of the IServiceProvider.</returns>
    public object GetService(Type serviceType)
    {
      _getServiceCalls.Inc();
      
      foreach ( Type expectedType in _serviceProviders.Keys ) 
      {
        if ( expectedType.Equals( serviceType ) )
        {
          return _serviceProviders[ expectedType ];
        }
      }
      return null;
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.