MethodSignatureTests.cs :  » Testing » MockObjects » DotNetMock » Tests » Dynamic » 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 » Tests » Dynamic » MethodSignatureTests.cs
using System;
using System.Reflection;
using DotNetMock.Dynamic;
using NUnit.Framework;
namespace DotNetMock.Tests.Dynamic{
  [TestFixture]
  public class MethodSignatureTest
  {
    #region Test Cases
    /// <summary>
    /// Test Equals method.
    /// </summary>
    [Test]
    public void TestEquals( )
    {
      MethodSignature sign1 = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      MethodSignature sign2 = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      MethodSignature sign3 = new MethodSignature( "Method2", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      MethodSignature sign4 = new MethodSignature( "Method1", typeof ( void ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      MethodSignature sign5 = new MethodSignature( "Method1", typeof ( Exception ), typeof ( object ), typeof ( Exception ) );
      Assert.IsTrue( sign1.Equals( sign2 ), "sign1.Equals(sign2) shall be true." );
      Assert.IsFalse( sign1.Equals( sign3 ), "sign1.Equals(sign3) shall be false." );
      Assert.IsFalse( sign1.Equals( sign4 ), "sign1.Equals(sign4) shall be false." );
      Assert.IsFalse( sign1.Equals( sign5 ), "sign1.Equals(sign5) shall be false." );
    }
    /// <summary>
    /// New instance of signature can be created from MethodInfo type parameter.
    /// </summary>
    [Test]
    public void ConstructorWithMethodInfoParameter( )
    {
      MethodInfo methodInfo = typeof ( MethodSignatureTest ).GetMethod( "TestMethod" );
      MethodSignature signature1 = new MethodSignature( methodInfo );
      MethodSignature signature2 = new MethodSignature( "TestMethod", typeof ( int ), typeof ( object ), typeof ( int ) );
      Assert.AreEqual( signature1, signature2, "signature1 shall be equal to signature2." );
    }
    /// <summary>
    /// Test ToString() routine.
    /// </summary>
    [Test]
    public void TestToString( )
    {
      MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      string actual = sign.ToString( );
      string expected = "System.Exception Method1(System.Boolean, System.Object, System.Exception)";
      Assert.AreEqual( expected, actual );
    }
    [Test]
      public void TestNotEqualToNull()
    {
      MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      Assert.IsFalse( sign.Equals(null) );
    }
    [Test]
    public void TestNotEqualToNonMethodSignatureObject()
    {
      MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      Assert.IsFalse( sign.Equals(new MockObject()) );
    }
    [Test]
      public void TestGetHashCode()
    {
      MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      Assert.IsNotNull( sign.GetHashCode() );
    }
    [Test]
      public void TestNotEqualsDifferentParameterTypes()
    {
      MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) );
      MethodSignature sign1 = new MethodSignature( "Method1", typeof ( Exception ), typeof ( object ), typeof ( bool ), typeof ( Exception ) );
      Assert.IsFalse( sign.Equals(sign1) );
    }
    #endregion

    /// <summary>
    /// Method used for testing. This method is not being called but simply here to supply MethodInfo
    /// structure for testing.
    /// </summary>
    public int TestMethod( object obj, int i )
    {
      throw new InvalidOperationException( "This method is for testing purposes only and shall never be called." );
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.