MockMainframeConnection.cs :  » Testing » MockObjects » DotNetMock » Examples » Mainframe » 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 » Examples » Mainframe » MockMainframeConnection.cs
using System;
using System.Collections;
using DotNetMock;

namespace DotNetMock.Examples.Mainframe{
  public class MockMainframeConnection : IMainframeConnection
  {
    private ExpectationCounter _connectCalls = new ExpectationCounter("MockMainframeConnection.ConnectCalls");
    private ExpectationCounter _disconnectCalls = new ExpectationCounter("MockMainframeConnection.DisconnectCalls");
    private ExpectationCounter _sendKeyCalls = new ExpectationCounter("MockMainframeConnection.SendCalls");
    private ExpectationValue _keyPress = new ExpectationValue("MockMainframeConnection.KeyPress");

    private Hashtable _screens = null;
    private string[,] _currentScreen = null;

    public MockMainframeConnection() {
      _screens = new Hashtable();
    }
    public void CreateScreen(string screenName, string[,] screen)
    {
      foreach (string key in _screens.Keys)
      {
        if (key.Equals(screenName)) 
        {
          throw new ApplicationException("Cannot add duplicate screen: " + screenName);
        }
      }
      _screens.Add(screenName, screen);
    }
    public void SetField(string screenName, int row, int column, string message)
    {
      string[,] screen = (string[,])_screens[screenName];
      if (screen == null) 
      {
        throw new ApplicationException("No valid screen setup for that screen name: " + screenName);
      }
      char[ ]messageArray = message.ToCharArray();
      int currentColumn = column - 1;
      int currentRow = row - 1;
      for (int i = 0; i < messageArray.Length; i++) 
      {
        screen[currentRow, currentColumn] = messageArray[i].ToString();
        currentColumn++;
      }
    }

    public void SetExpectedConnectCalls(int calls) 
    {
      _connectCalls.Expected = calls;
    }
    public void SetExpectedDisconnectCalls(int calls) 
    {
      _disconnectCalls.Expected = calls;
    }
    public void SetExpectedKeyPress(MainframeConnection.Keys key)
    {
      _keyPress.Expected = key;      
    }
    public void SetExpectedSendKeyCalls(int calls) 
    {
      _sendKeyCalls.Expected = calls;
    }
    #region IMainframeConnection Implementation
    public void Connect(string sessionID) 
    {
      _connectCalls.Inc();
    }
    public void SetScreen(string screenName)
    {
      bool found = false;
      foreach (string key in _screens.Keys)
      {
        if (key.Equals(screenName))
        {
          found = true;
        }
      }
      if (!found) 
      {
        throw new ApplicationException("A screen named " + screenName + " has not been setup");
      }
      _currentScreen = (string[,])_screens[screenName];  
    }
    public void PutField(int row, int column, string message, int length)
    {
      char[ ]messageArray = message.ToCharArray();
      int currentColumn = column - 1;
      int currentRow = row - 1;
      for (int i = 0; i < messageArray.Length; i++) 
      {
        _currentScreen[currentRow, currentColumn] = messageArray[i].ToString();
        currentColumn++;
      }
    }
    public string GetField(int row, int column, int length)
    {
      string output = "";
      int currentRow = row - 1;
      int currentColumn = column - 1;
      int currentLength = length;
      int i = 0;
      try 
      {
        for (i = 1; i <= currentLength; i++)
        {
          output += _currentScreen[currentRow,currentColumn];
          currentColumn++;
        }
      }
      catch (System.Exception ex)
      {
        throw new System.Exception("Current Row: " + currentRow.ToString() + "  Current Column: " + currentColumn.ToString() + "   Current Length: " + currentLength.ToString() + " I: " + i.ToString() + Environment.NewLine + "Exception Message: " + ex.Message);
      }
      return output;  
    }
    public void SendKey(MainframeConnection.Keys key)
    {
      _sendKeyCalls.Inc();
      _keyPress.Actual = key;
    }
    public void Wait() 
    {
    }
    public void Disconnect()
    {
      _disconnectCalls.Inc();
    }
    #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.