CustomerNumberCollectorTests.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 » CustomerNumberCollectorTests.cs
#region License
// Copyright (c) 2005 Griffin Caprio & Choy Rim. All rights reserved.
#endregion
#region Imports
using System;

using NUnit.Framework;
#endregion

namespace DotNetMock.Examples.Mainframe{
  [TestFixture]
  public class SerialNumberCollectorTests
  {  
    private MockMainframeConnection mockConnection = null;
    string[,] customerNumberScreen = null;
    string[,] mainMenu = null;
    CustomerNumberCollector customer = null;

    [SetUp]
    public void Init() 
    {
      mockConnection = new MockMainframeConnection();
      customerNumberScreen = new string[25,80];
      mainMenu = new string[25,80];
      customer = new CustomerNumberCollector(mockConnection);
      mockConnection.CreateScreen("MainMenu", mainMenu);
      mockConnection.CreateScreen("CustomerInformation", customerNumberScreen);
    }
    [TearDown]
    public void Destroy() 
    {
      mockConnection = null;
      customerNumberScreen = null;
    }
    [Test]
    [ExpectedException(typeof(ApplicationException))]
    public void InValidCustomerNumber()
    {
      setGeneralExpectations();
      mockConnection.SetExpectedKeyPress(MainframeConnection.Keys.Enter);
      mockConnection.SetField("CustomerInformation", 23, 2, "CUSTOMER NUMBER NOT FOUND");
      customer.CollectCustomerInformation("9999999");
    }
    [Test]
    public void ValidCustomerNumber()
    {
      setGeneralExpectations();
      mockConnection.SetField("CustomerInformation", 20, 4, "Pete Rose");
      mockConnection.SetField("CustomerInformation", 21, 4, "pete1234");
      mockConnection.SetField("CustomerInformation", 22, 4, "password");
      mockConnection.SetExpectedKeyPress(MainframeConnection.Keys.Enter);

      customer.CollectCustomerInformation("1234567");

      Assertion.AssertEquals("Pete Rose", customer.Name);
      Assertion.AssertEquals("pete1234", customer.UserName);
      Assertion.AssertEquals("password", customer.Password);
    }
    [Test]
    public void ValidCustomerNumberUpdate() 
    {
      setGeneralExpectations();
      mockConnection.SetField("CustomerInformation", 23, 3, "TRANSACTION ACCEPTED");
      mockConnection.SetField("CustomerInformation", 20, 4, "Pete Rose");
      mockConnection.SetField("CustomerInformation", 21, 4, "pete1234");
      mockConnection.SetField("CustomerInformation", 22, 4, "password");
      mockConnection.SetExpectedKeyPress(MainframeConnection.Keys.Enter);

      customer.UpdateInformation("1234567", "Babe Ruth", "baberuth", "babepass");

      Assertion.AssertEquals("Babe Ruth", customer.Name);
      Assertion.AssertEquals("baberuth", customer.UserName);
      Assertion.AssertEquals("babepass", customer.Password);
    }
    [Test]
    [ExpectedException(typeof(ApplicationException))]
    public void InvalidCustomerUpdate() 
    {
      setGeneralExpectations();
      mockConnection.SetExpectedKeyPress(MainframeConnection.Keys.Enter);
      mockConnection.SetField("CustomerInformation", 23, 2, "TRANSACTION FAILED");
      customer.UpdateInformation("1234567", "Babe Ruth", "baberuth", "babepass");
    }
    [Test]
    [ExpectedException(typeof(ApplicationException))]
    public void InValidCustomerNumberUpdateInformation()
    {
      setGeneralExpectations();
      mockConnection.SetExpectedKeyPress(MainframeConnection.Keys.Enter);
      mockConnection.SetField("CustomerInformation", 23, 2, "CUSTOMER NUMBER NOT FOUND");
      customer.UpdateInformation("9999999", "", "", "");
    }
    private void setGeneralExpectations()
    {
      mockConnection.SetExpectedConnectCalls(1);
      mockConnection.SetExpectedDisconnectCalls(1);
      mockConnection.SetExpectedSendKeyCalls(1);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.