public void TestConnect()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Connect("bob"), "Connect(bob)");
            var logicalUnitList = new[] { "lu1", "lu2" };

            SessionExtensions.VerifyDelegate del =
                () => session.Connect(
                    "bob",
                    "27",
                    logicalUnitList,
                    ConnectFlags.NoLogin);
            session.VerifyCommand(del, "Connect(\"C:lu1,lu2@bob:27\")");

            Assert.Throws <ArgumentException>(() => session.Connect(string.Empty));

            // Force an exception.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Connect("foo"));

            session.Close();
        }
        public void TestEbcdic()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Ebcdic(), "Ebcdic()");
            session.VerifyCommand(() => session.Ebcdic(10), "Ebcdic(10)");
            session.VerifyCommand(() => session.Ebcdic(1, 2, 3), "Ebcdic(1,2,3)");
            session.VerifyCommand(() => session.Ebcdic(1, 2, 3, 4), "Ebcdic(1,2,3,4)");

            Assert.Throws <ArgumentOutOfRangeException>(() => session.Ebcdic(-1, 2, 3));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.Ebcdic(1, -1, 3));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.Ebcdic(-1, 1, 3, 4));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.Ebcdic(1, -1, 3, 4));

            // Force some exceptions.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Ebcdic());
            Assert.Throws <X3270ifCommandException>(() => session.Ebcdic(1));
            Assert.Throws <X3270ifCommandException>(() => session.Ebcdic(1, 2, 3));
            Assert.Throws <X3270ifCommandException>(() => session.Ebcdic(1, 2, 3, 4));

            session.Close();
        }
        public void TestQuery()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Query(QueryType.BindPluName), "Query(BindPluName)");

            Assert.AreEqual(session.Query(QueryType.Cursor).Result[0], "0 0");

            // Force an exception.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Query(QueryType.Formatted));

            session.Close();

            // Exercise 1-origin.
            session = new MockTaskSession(new MockTaskConfig {
                Origin = 1
            });
            session.Start();
            Assert.AreEqual(session.Query(QueryType.Cursor).Result[0], "1 1");

            // Make sure the history contains the actual value from the emulator.
            Assert.AreEqual(session.RecentCommands[0].Result[0], "0 0");

            session.Close();
        }
        public void TestEbcdic1()
        {
            var session = new MockTaskSession(new MockTaskConfig {
                Origin = 1
            });

            session.VerifyStart();

            session.VerifyCommand(() => session.Ebcdic(1, 2, 3), "Ebcdic(0,1,3)");
            session.VerifyCommand(() => session.Ebcdic(1, 2, 3, 4), "Ebcdic(0,1,3,4)");

            Assert.Throws <ArgumentOutOfRangeException>(() => session.Ebcdic(0, 2, 3));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.Ebcdic(1, 0, 3));

            session.Close();
        }
        public void TestWait()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Wait(WaitMode.Wait3270Mode), "Wait(3270Mode)");
            session.VerifyCommand(() => session.Wait(WaitMode.Output, 10), "Wait(10,Output)");

            // Force an exception.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Wait(WaitMode.Unlock));

            session.Close();
        }
        public void TestStringAt()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.StringAt(1, 0, "Fred"), "MoveCursor(1,0) String(Fred)");

            session.VerifyCommand(
                () => session.StringAt(new[]
            {
                new StringAtBlock {
                    Row = 1, Column = 0, Text = "Fred"
                },
                new StringAtBlock {
                    Row = 2, Column = 4, Text = "Smith"
                }
            }),
                "MoveCursor(1,0) String(Fred) MoveCursor(2,4) String(Smith)");

            session.VerifyCommand(
                () => session.StringAt(1, 0, "Fred", eraseEof: true),
                "MoveCursor(1,0) EraseEOF() String(Fred)");

            // Exercise row and column checking.
            Assert.Throws <ArgumentOutOfRangeException>(() => session.StringAt(-1, 0, "foo"));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.StringAt(0, -1, "foo"));

            // Force exceptions.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.StringAt(1, 0, "foo"));
            Assert.Throws <X3270ifCommandException>(() =>
            {
                var result = session.StringAt(new[]
                {
                    new StringAtBlock {
                        Row = 1, Column = 0, Text = "Fred"
                    },
                    new StringAtBlock {
                        Row = 2, Column = 4, Text = "Smith"
                    }
                });
            });

            session.Close();
        }
        public void TestReadBuffer()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.ReadBuffer(), "ReadBuffer(Ascii)");
            session.VerifyCommand(() => session.ReadBuffer(Session.ReadBufferType.Ascii), "ReadBuffer(Ascii)");
            session.VerifyCommand(() => session.ReadBuffer(Session.ReadBufferType.Ebcdic), "ReadBuffer(Ebcdic)");

            // Force an exception.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.ReadBuffer());

            session.Close();
        }
        public void TestString()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.String("Fred"), "String(Fred)");
            session.VerifyCommand(() => session.String("a\\b"), "String(\"a\\\\b\")");
            session.VerifyCommand(() => session.String("a\\b", quoteBackslashes: false), "String(\"a\\b\")");

            // Force an exception.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.String("foo"));

            session.Close();
        }
        public void TestCursor()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Up(), "Up()");
            session.VerifyCommand(() => session.Down(), "Down()");
            session.VerifyCommand(() => session.Left(), "Left()");
            session.VerifyCommand(() => session.Right(), "Right()");
            session.VerifyCommand(() => session.MoveCursor(0, 0), "MoveCursor(0,0)");
            session.VerifyCommand(() => session.Tab(), "Tab()");
            session.VerifyCommand(() => session.BackTab(), "BackTab()");

            // Force some exceptions.
            Assert.Throws <ArgumentOutOfRangeException>(() => session.MoveCursor(-1, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.MoveCursor(0, -1));

            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Up());
            Assert.Throws <X3270ifCommandException>(() => session.Down());
            Assert.Throws <X3270ifCommandException>(() => session.Left());
            Assert.Throws <X3270ifCommandException>(() => session.Right());
            Assert.Throws <X3270ifCommandException>(() => session.Tab());
            Assert.Throws <X3270ifCommandException>(() => session.BackTab());

            session.Close();
        }
Example #10
0
        public void TestAid()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Enter(), "Enter()");
            session.VerifyCommand(() => session.Clear(), "Clear()");
            session.VerifyCommand(() => session.PF(1), "PF(1)");
            session.VerifyCommand(() => session.PF(2), "PF(2)");
            session.VerifyCommand(() => session.PA(1), "PA(1)");
            session.VerifyCommand(() => session.PA(2), "PA(2)");

            // Force some exceptions.
            Assert.Throws <ArgumentOutOfRangeException>(() => session.PF(0));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.PF(25));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.PA(0));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.PA(4));

            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Enter());
            Assert.Throws <X3270ifCommandException>(() => session.Clear());
            Assert.Throws <X3270ifCommandException>(() => session.PF(1));
            Assert.Throws <X3270ifCommandException>(() => session.PA(1));

            session.Close();
        }
        public void TestDisconnect()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            session.VerifyCommand(() => session.Disconnect(), "Disconnect()");

            // Force an exception.
            session.ExceptionMode = true;
            session.AllFail       = true;
            Assert.Throws <X3270ifCommandException>(() => session.Disconnect());

            session.Close();
        }
        public void TestCursor1()
        {
            var session = new MockTaskSession(new MockTaskConfig {
                Origin = 1
            });

            session.VerifyStart();

            session.VerifyCommand(() => session.MoveCursor(1, 1), "MoveCursor(0,0)");

            // Force some exceptions.
            Assert.Throws <ArgumentOutOfRangeException>(() => session.MoveCursor(0, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() => session.MoveCursor(1, 0));

            session.Close();
        }
        public void TestTransfer()
        {
            var session = new MockTaskSession();

            session.VerifyStart();

            // Basic functionality.
            session.VerifyCommand(
                () => session.Transfer(
                    @"C:\foo.txt",
                    "FOO TXT A",
                    Direction.Send,
                    Mode.Ascii,
                    HostType.Vm,
                    new ParameterExistAction(ExistAction.Replace)),
                "Transfer(direction=Send,exist=Replace,host=Vm,\"hostfile=FOO TXT A\",\"localfile=C:\\\\foo.txt\",mode=Ascii)");

            // Bad parameter type.
            Assert.Throws <ArgumentException>(
                () => session.Transfer("foo.txt", "foo txt a", Direction.Send, Mode.Ascii, HostType.Vm, "wrong!"));
            Assert.Throws <ArgumentNullException>(
                () => session.Transfer(
                    "foo.txt",
                    "foo txt a",
                    Direction.Send,
                    Mode.Ascii,
                    HostType.Vm,
                    new ParameterExistAction(ExistAction.Replace),
                    null));

            // Bad file names.
            Assert.Throws <ArgumentException>(
                () => session.Transfer(string.Empty, "foo txt a", Direction.Send, Mode.Ascii, HostType.Vm));
            Assert.Throws <ArgumentException>(
                () => session.Transfer(null, "foo txt a", Direction.Send, Mode.Ascii, HostType.Vm));
            Assert.Throws <ArgumentException>(
                () => session.Transfer("foo.txt", string.Empty, Direction.Send, Mode.Ascii, HostType.Vm));
            Assert.Throws <ArgumentException>(
                () => session.Transfer("foo.txt", null, Direction.Send, Mode.Ascii, HostType.Vm));

            // Bad AsciiRemap.
            Assert.Throws <ArgumentException>(() => new ParameterAsciiRemap(false, 252));
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterAsciiRemap(true, 0));

            // Bad block size.
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterBlockSize(0));

            // Bad logical record length.
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterSendLogicalRecordLength(0));

            // Bad TsoSendAllocations.
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterTsoSendAllocation(TsoAllocationUnits.Cylinders, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterTsoSendAllocation(TsoAllocationUnits.Cylinders, 100, 0));
            Assert.Throws <ArgumentException>(() => new ParameterTsoSendAllocation(TsoAllocationUnits.Avblock, 100, 200));
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterTsoSendAllocation(TsoAllocationUnits.Avblock, 100, 200, 0));
            Assert.Throws <ArgumentException>(() => new ParameterTsoSendAllocation(TsoAllocationUnits.Cylinders, 100, 200, 300));

            // Bad buffer size.
            Assert.Throws <ArgumentOutOfRangeException>(() => new ParameterBufferSize(0));

            // All possible options.
            session.VerifyCommand(
                () => session.Transfer(
                    @"C:\foo.txt",
                    "FOO TXT A",
                    Direction.Send,
                    Mode.Ascii,
                    HostType.Tso,
                    new ParameterAsciiCr(false),
                    new ParameterAsciiRemap(true, 252),
                    new ParameterExistAction(ExistAction.Replace),
                    new ParameterSendRecordFormat(RecordFormat.Fixed),
                    new ParameterSendLogicalRecordLength(80),
                    new ParameterBlockSize(1024),
                    new ParameterTsoSendAllocation(TsoAllocationUnits.Avblock, 100, 200, 300),
                    new ParameterBufferSize(4096)),
                "Transfer(allocation=Avblock,avblock=300,blocksize=1024,buffersize=4096,cr=keep,direction=Send,exist=Replace,host=Tso,\"hostfile=FOO TXT A\",\"localfile=C:\\\\foo.txt\",lrecl=80,mode=Ascii,primaryspace=100,recfm=Fixed,remap=yes,secondaryspace=200,windowscodepage=252)");

            // Some ASCII option variations.
            session.VerifyCommand(
                () =>
            {
                return(session.Transfer(
                           @"C:\foo.txt",
                           "FOO TXT A",
                           Direction.Send,
                           Mode.Ascii,
                           HostType.Tso,
                           new ParameterAsciiCr(true),
                           new ParameterAsciiRemap(false)));
            },
                "Transfer(cr=add,direction=Send,host=Tso,\"hostfile=FOO TXT A\",\"localfile=C:\\\\foo.txt\",mode=Ascii,remap=no)");

            // Same thing, using the IEnumerable API.
            session.VerifyCommand(
                () =>
            {
                return(session.Transfer(
                           @"C:\foo.txt",
                           "FOO TXT A",
                           Direction.Send,
                           Mode.Ascii,
                           HostType.Tso,
                           new List <Parameter>
                {
                    new ParameterAsciiCr(true),
                    new ParameterAsciiRemap(false)
                }));
            },
                "Transfer(cr=add,direction=Send,host=Tso,\"hostfile=FOO TXT A\",\"localfile=C:\\\\foo.txt\",mode=Ascii,remap=no)");

            // AsciiCr without Ascii.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Receive,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterAsciiCr(true));
            });

            // Same thing, using the IEnumerable API.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Receive,
                    Mode.Binary,
                    HostType.Tso,
                    new List <Parameter> {
                    new ParameterAsciiCr(true)
                });
            });

            // AsciiRemap without Ascii.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Receive,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterAsciiRemap(true));
            });

            // Lrecl without send.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Receive,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterSendLogicalRecordLength(80));
            });

            // Lrecl on CICS.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Cics,
                    new ParameterSendLogicalRecordLength(80));
            });

            // Recfm without send.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Receive,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterSendRecordFormat(RecordFormat.Fixed));
            });

            // Recfm on CICS.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Cics,
                    new ParameterSendRecordFormat(RecordFormat.Fixed));
            });

            // TSO allocation without send.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Receive,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterTsoSendAllocation(TsoAllocationUnits.Cylinders, 100));
            });

            // TSO allocation on non-TSO.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Vm,
                    new ParameterTsoSendAllocation(TsoAllocationUnits.Cylinders, 100));
            });

            // Append with recfm.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterExistAction(ExistAction.Append),
                    new ParameterSendRecordFormat(RecordFormat.Fixed));
            });

            // Append with lrecl.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterExistAction(ExistAction.Append),
                    new ParameterSendLogicalRecordLength(80));
            });

            // Append with TSO allocation.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Tso,
                    new ParameterExistAction(ExistAction.Append),
                    new ParameterTsoSendAllocation(TsoAllocationUnits.Cylinders, 100));
            });

            // Blocksize without TSO.
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Cics,
                    new ParameterBlockSize(1024));
            });
            Assert.Throws <ArgumentException>(
                () =>
            {
                var result = session.Transfer(
                    "foo.txt",
                    "FOO.TXT",
                    Direction.Send,
                    Mode.Binary,
                    HostType.Vm,
                    new ParameterBlockSize(1024));
            });

            session.Close();
        }