public void Deserialize_ThrowsExecption_IfMessageIsGreaterThan35Bytes()
        {
            var       bytes = new byte[53];
            Exception ex    = Assert.Throws <Exception>(() => CancelledOrderSerializer.Deserialize(bytes));

            Assert.Equal("Canceled Order Message must be of Size : 52", ex.Message);
        }
        public void Deserialize_ThrowsExecption_IfMessageIsNothaveValidType()
        {
            var       bytes = new byte[52];
            Exception ex    = Assert.Throws <Exception>(() => CancelledOrderSerializer.Deserialize(bytes));

            Assert.Equal("Invalid Message", ex.Message);
        }
Exemple #3
0
        private void OnMessage(byte[] body)
        {
            var    type = Serializer.GetMessageType(body);
            object obj  = null;

            switch (type)
            {
            case MessageType.Cancel:
                obj = CancelledOrderSerializer.Deserialize(body);
                break;

            case MessageType.Fill:
                obj = FillSerializer.Deserialize(body);
                break;

            case MessageType.OrderTrigger:
                obj = OrderTriggerSerializer.Deserialize(body);
                break;

            default:
                //TODO
                break;
            }
            var message = new Message(type.Value, body, obj);

            _inboundChannelWritter.TryWrite(message);
        }
Exemple #4
0
        public void Deserialize_ThrowsExecption_IfMessageIsNothaveValidType()
        {
            var       bytes = new byte[68];
            Exception ex    = Assert.Throws <Exception>(() => CancelledOrderSerializer.Deserialize(bytes));

            Assert.Equal(Types.Constant.INVALID_MESSAGE, ex.Message);
        }
        public void Deserialize_ThrowsExecption_IfVersionIsNotSet()
        {
            var bytes = new byte[52];

            bytes[4] = (byte)MessageType.Cancel;
            Exception ex = Assert.Throws <Exception>(() => CancelledOrderSerializer.Deserialize(bytes));

            Assert.Equal("version mismatch", ex.Message);
        }
Exemple #6
0
        public void Deserialize_ThrowsExecption_IfVersionIsNotSet()
        {
            var bytes = new byte[68];

            bytes[4] = (byte)MessageType.Cancel;
            Exception ex = Assert.Throws <Exception>(() => CancelledOrderSerializer.Deserialize(bytes));

            Assert.Equal(Types.Constant.INVALID_VERSION, ex.Message);
        }
        public void Deserialize_Doesnotthrowexception_Min()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MinValue, Timestamp = int.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, Cost = Quantity.MinValue
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(52, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(OrderId.MinValue, cancelledOrder.OrderId);
            Assert.Equal(int.MinValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(int.MinValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.UserRequested, cancelledOrder.CancelReason);
            Assert.Equal(Quantity.MinValue, cancelledOrder.Cost);
        }
        public void Deserialize_Doesnotthrowexception()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = 12345678, RemainingQuantity = 56789, Timestamp = 404, CancelReason = CancelReason.ValidityExpired, Cost = 12.13m
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(52, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal((OrderId)12345678, cancelledOrder.OrderId);
            Assert.Equal(56789, cancelledOrder.RemainingQuantity);
            Assert.Equal(404, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.ValidityExpired, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)12.13m, cancelledOrder.Cost);
        }
Exemple #9
0
        public void Deserialize_Doesnotthrowexception_Min()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = ulong.MinValue, Timestamp = long.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, RemainingOrderAmount = decimal.MinValue
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(56, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(ulong.MinValue, cancelledOrder.OrderId);
            Assert.Equal((Quantity)int.MinValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(long.MinValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.UserRequested, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)decimal.MinValue, cancelledOrder.RemainingOrderAmount);
        }
Exemple #10
0
        public void Deserialize_Doesnotthrowexception_Max()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MaxValue, Timestamp = int.MaxValue, RemainingQuantity = int.MaxValue, CancelReason = CancelReason.ValidityExpired, RemainingOrderAmount = decimal.MaxValue
            });

            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(52, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(OrderId.MaxValue, cancelledOrder.OrderId);
            Assert.Equal((Quantity)int.MaxValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(int.MaxValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.ValidityExpired, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)decimal.MaxValue, cancelledOrder.RemainingOrderAmount);
        }
Exemple #11
0
        public void Deserialize_Doesnotthrowexception_Min()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MinValue, Timestamp = int.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, Cost = Quantity.MinValue, Fee = Quantity.MinValue
            }, bytes);
            var messageLength = BitConverter.ToInt32(bytes.Slice(0));

            Assert.Equal(68, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(OrderId.MinValue, cancelledOrder.OrderId);
            Assert.Equal(int.MinValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(int.MinValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.UserRequested, cancelledOrder.CancelReason);
            Assert.Equal(Quantity.MinValue, cancelledOrder.Cost);
            Assert.Equal(Quantity.MinValue, cancelledOrder.Fee);
        }
Exemple #12
0
        public void Deserialize_Doesnotthrowexception()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = 12345678, RemainingQuantity = 56789, Timestamp = 404, CancelReason = CancelReason.ValidityExpired, Cost = 12.13m, Fee = 92.005m
            }, bytes);
            var messageLength = BitConverter.ToInt32(bytes.Slice(0));

            Assert.Equal(68, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal((OrderId)12345678, cancelledOrder.OrderId);
            Assert.Equal(56789, cancelledOrder.RemainingQuantity);
            Assert.Equal(404, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.ValidityExpired, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)12.13m, cancelledOrder.Cost);
            Assert.Equal((Quantity)92.005m, cancelledOrder.Fee);
        }
        public void Deserialize_ThrowsExecption_IfNullPassed()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => CancelledOrderSerializer.Deserialize(null));

            Assert.Equal("bytes", ex.ParamName);
        }
 public void cancelBinaryDeserialize()
 {
     var cancel = CancelledOrderSerializer.Deserialize(cancelBinary);
 }
Exemple #15
0
 public void CancelBinaryDeserialize()
 {
     CancelledOrderSerializer.Deserialize(cancelBinary);
 }