Exemple #1
0
        public void Deserialize_ThrowsExecption_IfMessageIsNothaveValidType()
        {
            var       bytes = new byte[11];
            Exception ex    = Assert.Throws <Exception>(() => BookRequestSerializer.Deserialize(bytes));

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

            switch (type)
            {
            case MessageType.NewOrderRequest:
                obj = OrderSerializer.Deserialize(body);
                break;

            case MessageType.CancelRequest:
                obj = CancelRequestSerializer.Deserialize(body);
                break;

            case MessageType.BookRequest:
                obj = BookRequestSerializer.Deserialize(body);
                break;

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

            _inboundChannelWritter.TryWrite(message);
        }
        public void Deserialize_ThrowsExecption_IfMessageIsNothaveValidType()
        {
            var       bytes = new byte[11];
            Exception ex    = Assert.Throws <Exception>(() => BookRequestSerializer.Deserialize(bytes));

            Assert.Equal("Invalid Message", ex.Message);
        }
Exemple #4
0
        public void Deserialize_ThrowsExecption_IfMessageIsGreaterThan35Bytes()
        {
            var       bytes = new byte[12];
            Exception ex    = Assert.Throws <Exception>(() => BookRequestSerializer.Deserialize(bytes));

            Assert.Equal("Book Request Message must be of Size : 11", ex.Message);
        }
Exemple #5
0
        public void Deserialize_ThrowsExecption_IfVersionIsNotSet()
        {
            var bytes = new byte[11];

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

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

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

            Assert.Equal("version mismatch", ex.Message);
        }
        public void Deserialize_Doesnotthrowexception_Max()
        {
            var bytes = BookRequestSerializer.Serialize(new BookRequest {
                LevelCount = int.MaxValue
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(11, messageLength);
            var cancelRequest = BookRequestSerializer.Deserialize(bytes);

            Assert.Equal(int.MaxValue, cancelRequest.LevelCount);
        }
Exemple #8
0
        public void Deserialize_Doesnotthrowexception()
        {
            Span <byte> bytes = stackalloc byte[BookRequestSerializer.MessageSize];

            BookRequestSerializer.Serialize(new BookRequest {
                LevelCount = 12345678
            }, bytes);
            var messageLength = BitConverter.ToInt32(bytes.Slice(0));

            Assert.Equal(11, messageLength);
            var cancelRequest = BookRequestSerializer.Deserialize(bytes);

            Assert.Equal(12345678, cancelRequest.LevelCount);
        }
 public void bookRequestBinaryDeserialize()
 {
     var bookrequest = BookRequestSerializer.Deserialize(bookRequestBinary);
 }
Exemple #10
0
        public void Deserialize_ThrowsExecption_IfNullPassed()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => BookRequestSerializer.Deserialize(null));

            Assert.Equal("bytes", ex.ParamName);
        }
Exemple #11
0
 public void BookRequestBinaryDeserialize()
 {
     BookRequestSerializer.Deserialize(bookRequestBinary);
 }