public void TestComplexMessage()
        {
            var template = new MessageTemplate("Company",
                new Field[] {
                new Scalar("Name", FASTType.STRING, Operator.NONE, ScalarValue.UNDEFINED, false),
                new Scalar("Id", FASTType.U32, Operator.INCREMENT, ScalarValue.UNDEFINED, false),
                new Sequence("Employees",
                    new Field[] {
                        new Scalar("First Name", FASTType.STRING, Operator.COPY, ScalarValue.UNDEFINED, false),
                        new Scalar("Last Name", FASTType.STRING, Operator.COPY, ScalarValue.UNDEFINED, false),
                        new Scalar("Age", FASTType.U32, Operator.DELTA, ScalarValue.UNDEFINED, false)
                    }, false),
                new Group("Tax Information",
                    new Field[] {
                        new Scalar("EIN", FASTType.STRING, Operator.NONE, ScalarValue.UNDEFINED, false)
                    }, false)
            });
            var aaaInsurance = new Message(template);
            aaaInsurance.SetFieldValue(1, new StringValue("AAA Insurance"));
            aaaInsurance.SetFieldValue(2, new IntegerValue(5));

            var employees = new SequenceValue(template.GetSequence(
                        "Employees"));
            employees.Add(new FieldValue[] {
                new StringValue("John"), new StringValue("Doe"),
                new IntegerValue(45)
            });
            employees.Add(new FieldValue[] {
                new StringValue("Jane"), new StringValue("Doe"),
                new IntegerValue(48)
            });
            aaaInsurance.SetFieldValue(3, employees);
            aaaInsurance.SetFieldValue(4,
                new GroupValue(template.GetGroup("Tax Information"),
                    new FieldValue[] { new StringValue("99-99999999") }));

            var outStream = new MemoryStream();
            var output = new MessageOutputStream(outStream);
            output.RegisterTemplate(1, template);
            output.WriteMessage(aaaInsurance);

            var abcBuilding = new Message(template);
            abcBuilding.SetFieldValue(1, new StringValue("ABC Building"));
            abcBuilding.SetFieldValue(2, new IntegerValue(6));
            employees = new SequenceValue(template.GetSequence("Employees"));
            employees.Add(new FieldValue[] {
                new StringValue("Bob"), new StringValue("Builder"),
                new IntegerValue(3)
            });
            employees.Add(new FieldValue[] {
                new StringValue("Joe"), new StringValue("Rock"),
                new IntegerValue(59)
            });
            abcBuilding.SetFieldValue(3, employees);
            abcBuilding.SetFieldValue(4,
                new GroupValue(template.GetGroup("Tax Information"),
                    new FieldValue[] { new StringValue("99-99999999") }));
            output.WriteMessage(abcBuilding);

            var input = new MessageInputStream(new MemoryStream(
                        outStream.ToArray()));
            input.RegisterTemplate(1, template);

            GroupValue message = input.ReadMessage();
            Assert.AreEqual(aaaInsurance, message);

            message = input.ReadMessage();
            Assert.AreEqual(abcBuilding, message);
        }
 public void TestIOErrorOnWrite()
 {
     var output = new MessageOutputStream(new IOExceptionThrowingStream());
     output.RegisterTemplate(ObjectMother.ALLOC_INSTRCTN_TEMPLATE_ID, ObjectMother.AllocationInstruction());
     Message message = ObjectMother.BasicAllocationInstruction();
     try
     {
         output.WriteMessage(message);
         Assert.Fail();
     }
     catch (FastException e)
     {
         Assert.AreEqual(FastConstants.IO_ERROR, e.Code);
     }
 }
        public void TestMultipleMessages()
        {
            var outStream = new MemoryStream();
            var output = new MessageOutputStream(outStream);
            output.RegisterTemplate(ObjectMother.ALLOC_INSTRCTN_TEMPLATE_ID,
                ObjectMother.AllocationInstruction());

            var allocations = new SequenceValue(ObjectMother.AllocationInstruction()
                                                                      .GetSequence("Allocations"));
            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai1 = ObjectMother.NewAllocInstrctn("ltg0001", 1, 100.0, 23.4,
                    ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            allocations = new SequenceValue(ObjectMother.AllocationInstruction()
                                                        .GetSequence("Allocations"));
            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai2 = ObjectMother.NewAllocInstrctn("ltg0001", 1, 100.0, 23.4,
                    ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            allocations = new SequenceValue(ObjectMother.AllocationInstruction()
                                                        .GetSequence("Allocations"));
            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai3 = ObjectMother.NewAllocInstrctn("ltg0001", 1, 100.0, 23.4,
                    ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            output.WriteMessage(ai1);
            output.WriteMessage(ai2);
            output.WriteMessage(ai3);

            byte[] bytes = outStream.ToArray();
            var input = new MessageInputStream(new MemoryStream(
                        bytes));
            input.RegisterTemplate(ObjectMother.ALLOC_INSTRCTN_TEMPLATE_ID,
                ObjectMother.AllocationInstruction());

            Message message = input.ReadMessage();
            Assert.AreEqual(ai1, message);
            message = input.ReadMessage();
            Assert.AreEqual(ai2, message);
            Assert.AreEqual(ai3, input.ReadMessage());
        }