public ResponseMessage Get(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }
            var messageType = _messageParser.GetTypeOfMessage(message);

            if (messageType != ResponseMessageType.RefreshSession)
            {
                throw new InvalidOperationException($"{this.GetType()} cannot proccess message of type {messageType}");
            }
            var messageSuccesful = _messageParser.IsSuccessfulMessage(message);

            if (messageSuccesful)
            {
                var sessionId = _messageParser.GetFieldFromMessage(message, "SessionId");
                if (string.IsNullOrWhiteSpace(sessionId))
                {
                    throw new InvalidOperationException("SessionId is missing from message");
                }
                return(new RefreshSessionResponse(sessionId));
            }
            else
            {
                throw new InvalidOperationException("Unexpected unsuccesful refresh message");
            }
        }
        public ResponseMessage Get(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }
            var messageType = _messageParser.GetTypeOfMessage(message);

            if (messageType != ResponseMessageType.JoinSessionResponse)
            {
                throw new InvalidOperationException($"{this.GetType()} cannot proccess message of type {messageType}");
            }

            var sessionId = _messageParser.GetFieldFromMessage(message, "SessionId");

            if (string.IsNullOrWhiteSpace(sessionId))
            {
                throw new InvalidOperationException("SessionId is missing from message");
            }

            var messageSuccesful = _messageParser.IsSuccessfulMessage(message);

            if (messageSuccesful)
            {
                var userId = _messageParser.GetFieldFromMessage(message, "UserId");
                if (string.IsNullOrWhiteSpace(userId))
                {
                    throw new InvalidOperationException("UserId is missing from message");
                }
                var userToken = _messageParser.GetFieldFromMessage(message, "Token");
                if (string.IsNullOrWhiteSpace(userToken))
                {
                    throw new InvalidOperationException("UserToken is missing from message");
                }
                return(new JoinSessionResponse(sessionId, userId, userToken));
            }
            else
            {
                var errorMessage = _messageParser.GetFieldFromMessage(message, "ErrorMessage");
                return(new JoinSessionResponse(sessionId, errorMessage));
            }
        }
        public ResponseMessage Get(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }
            var messageType      = _messageParser.GetTypeOfMessage(message);
            var messageSuccesful = _messageParser.IsSuccessfulMessage(message);

            var sessionId = _messageParser.GetFieldFromMessage(message, "SessionId");

            if (string.IsNullOrWhiteSpace(sessionId))
            {
                throw new InvalidOperationException("SessionId is missing from message");
            }
            string errorMessage = null;

            if (!messageSuccesful)
            {
                errorMessage = _messageParser.GetFieldFromMessage(message, "ErrorMessage");
            }
            return(new SubscribeSessionResponse(messageSuccesful, sessionId, errorMessage));
        }
예제 #4
0
        public ResponseMessage Get(string message)
        {
            if (String.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }
            var messageType = _messageParser.GetTypeOfMessage(message);

            if (messageType != ResponseMessageType.SessionEndedMessage)
            {
                throw new InvalidOperationException($"{this.GetType()} cannot proccess message of type {messageType}");
            }
            var sessionId = _messageParser.GetFieldFromMessage(message, "SessionId");

            if (string.IsNullOrWhiteSpace(sessionId))
            {
                throw new InvalidOperationException("SessionId is missing from message");
            }
            return(new EndSessionClientMessage(sessionId));
        }
예제 #5
0
 public void GivenGetFieldFromMessageIsCalled_WhenMessagePassedIsNull_ThenExceptionIsThrown()
 {
     Assert.Throws <ArgumentNullException>(() => {
         _messageParser.GetFieldFromMessage(null, "AField");
     });
 }