MockMarshalByValueComponentTests.cs :  » Testing » MockObjects » DotNetMock » Framework » Tests » 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 » Tests » ComponentModel » MockMarshalByValueComponentTests.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using DotNetMock.Framework.ComponentModel;
using NUnit.Framework;

namespace DotNetMock.Framework.Tests.ComponentModel{
  [TestFixture]
  public class MockMarshalByValueComponentTests 
  {
    private MockMarshalByValueComponent _mockComponent = null;

    private class DummySite : ISite
    {

    
      #region Implementation of ISite
      public System.ComponentModel.IComponent Component
      {
        get
        {
          return null;
        }
      }

      public System.ComponentModel.IContainer Container
      {
        get
        {
          return null;
        }
      }

      public bool DesignMode
      {
        get
        {
          return true;
        }
      }

      public string Name
      {
        get
        {
          return null;
        }
        set
        {
        }
      }
      #endregion

      #region Implementation of IServiceProvider
      public object GetService(System.Type serviceType)
      {
        return null;
      }
      #endregion
    }


    [SetUp]
    public void Init() 
    {
      _mockComponent = new MockMarshalByValueComponent();  
    }
    [TearDown]
    public void Destroy()
    {
      _mockComponent = null;
    }

    [Test]
    public void ExpectedContainer()
    {
      Container contain =  new Container();
      _mockComponent.SetExpectedContainer( contain );

      Assertion.AssertEquals( "Containers do not equal.", contain, _mockComponent.Container );
    }
    [Test]
    public void ExpectedSite()
    {
      ISite dummySite = new DummySite();
      _mockComponent.SetExpectedSite( dummySite );

      Assertion.AssertEquals( "Sites do not equal.", dummySite, _mockComponent.Site );
    }
    [Test]
    public void ExpectedDesignMode()
    {
      Assertion.Assert( "In design mode", !_mockComponent.DesignMode );
      _mockComponent.SetExpectedSite( new DummySite() );
      _mockComponent.SetExpectedDesignMode( true );
      Assertion.Assert( "Not in design mode", _mockComponent.DesignMode );

      _mockComponent.SetExpectedDesignMode( false );
      Assertion.Assert( "Not in design mode", !_mockComponent.DesignMode );
    }
    [Test]
    public void ExpectedGetServiceCount()
    {
      _mockComponent.SetExpectedGetServiceCalls( 2 );
      _mockComponent.GetService( null );
      _mockComponent.GetService( null );
      _mockComponent.Verify();
    }
    [Test]
    [ExpectedException(typeof(AssertionException))]
    public void ExpectedGetServiceCountFails()
    {
      _mockComponent.SetExpectedGetServiceCalls( 3 );
      _mockComponent.GetService( null );
      _mockComponent.GetService( null );
      _mockComponent.Verify();
    }
    [Test]
    public void GetServiceValid()
    {
      IServiceProvider container1 = new ServiceContainer();
      IServiceProvider container2 = new ServiceContainer();

      _mockComponent.SetExpectedServiceProvider( container1, typeof(string) );
      _mockComponent.SetExpectedServiceProvider( container2, typeof(int) );

      Assertion.AssertEquals( "Services do not equal.", container1, _mockComponent.GetService( typeof(string) ) );
      Assertion.AssertEquals( "Services do not equal.", container2, _mockComponent.GetService( typeof(int) ) );
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.