예제 #1
0
        public void ParseErrorMessageWithoutCode()
        {
            const string message = "::No clientID";
            BayeuxError  error   = new BayeuxError(message);

            Assert.IsTrue(false, "Exception should be thrown already!");
        }
예제 #2
0
        public void ParseErrorWithoutMessage()
        {
            const string message = "";
            BayeuxError  error   = new BayeuxError("101::" + message);

            Assert.AreEqual(error.Message, message, "Invalid message");
            Assert.IsNotNull(error.Arguments, "Argumets should not be null");
            Assert.AreEqual(error.Arguments.Count, 0, "Invalid number or message arguments");
            Assert.AreEqual(error.Code, 101, "Invalid error code");
        }
예제 #3
0
        public void ParseErrorMessageOnly()
        {
            const string message = "This is message only";
            BayeuxError  error   = new BayeuxError(message);

            Assert.AreEqual(error.Message, message, "Invalid message");
            Assert.IsNotNull(error.Arguments, "Argumets should not be null");
            Assert.AreEqual(error.Arguments.Count, 0, "Invalid number or message arguments");
            Assert.AreEqual(error.Code, 0, "Invalid error code");
        }
예제 #4
0
        public void ParseErrorWithArgs()
        {
            const string message  = "No Message";
            const string argument = "/foo/bar";
            BayeuxError  error    = new BayeuxError("101:" + argument + ":" + message);

            Assert.AreEqual(error.Message, message, "Invalid message");
            Assert.IsNotNull(error.Arguments, "Argumets should not be null");
            Assert.AreEqual(error.Arguments.Count, 1, "Invalid number or message arguments");
            Assert.AreEqual(error.Arguments[0], argument, "Invalid argument");
            Assert.AreEqual(error.Code, 101, "Invalid error code");
        }
예제 #5
0
        /// <summary>
        /// Reads the response from given JSON object.
        /// </summary>
        public void Read(IJSonObject input)
        {
            _jsonResponse = input;

            // reset all fields to their default values:
            Channel    = null;
            ClientID   = null;
            Successful = false;
            Timestamp  = DateTime.MinValue;
            ID         = null;
            Data       = null;
            Error      = null;
            Advice     = null;
            Ext        = null;

            // stop processing, if there is no input data given:
            if (input == null)
            {
                return;
            }

            // now read the Bayeux mandatory fields:
            Channel = input["channel"].StringValue;
            if (!BayeuxChannel.IsValid(Channel))
            {
                throw new FormatException("Invalid channel format");
            }


            if (input.Contains("clientId"))
            {
                ClientID = input["clientId"].StringValue;
            }

            // for meta channels, this field is required,
            // however it's optional for others (like events)
            if (Channel.StartsWith("/meta"))
            {
                Successful = input["successful"].BooleanValue;
            }
            else
            {
                if (input.Contains("successful"))
                {
                    Successful = input["successful"].BooleanValue;
                }
            }

            // parse optional fields:
            if (input.Contains("timestamp"))
            {
                Timestamp = input["timestamp"].DateTimeValue;
            }
            if (input.Contains("id"))
            {
                ID = input["id"].StringValue;
            }
            if (input.Contains("data"))
            {
                Data = input["data"];
            }
            if (input.Contains("error"))
            {
                Error = new BayeuxError(input["error"].StringValue);
            }
            if (input.Contains("advice"))
            {
                Advice = new BayeuxAdvice(input["advice"]);
            }
            if (input.Contains("ext"))
            {
                Ext = input["ext"];
            }

            ReadOptionalFields(input);
        }
예제 #6
0
        /// <summary>
        /// Reads the response from given JSON object.
        /// </summary>
        public void Read(IJSonObject input)
        {
            _jsonResponse = input;

            // reset all fields to their default values:
            Channel = null;
            ClientID = null;
            Successful = false;
            Timestamp = DateTime.MinValue;
            ID = null;
            Data = null;
            Error = null;
            Advice = null;
            Ext = null;

            // stop processing, if there is no input data given:
            if (input == null)
                return;

            // now read the Bayeux mandatory fields:
            Channel = input["channel"].StringValue;
            if (!BayeuxChannel.IsValid(Channel))
                throw new FormatException("Invalid channel format");


            if (input.Contains("clientId"))
                ClientID = input["clientId"].StringValue;

            // for meta channels, this field is required,
            // however it's optional for others (like events)
            if (Channel.StartsWith("/meta"))
                Successful = input["successful"].BooleanValue;
            else
            {
                if (input.Contains("successful"))
                    Successful = input["successful"].BooleanValue;
            }

            // parse optional fields:
            if (input.Contains("timestamp"))
                Timestamp = input["timestamp"].DateTimeValue;
            if (input.Contains("id"))
                ID = input["id"].StringValue;
            if (input.Contains("data"))
                Data = input["data"];
            if (input.Contains("error"))
                Error = new BayeuxError(input["error"].StringValue);
            if (input.Contains("advice"))
                Advice = new BayeuxAdvice(input["advice"]);
            if (input.Contains("ext"))
                Ext = input["ext"];

            ReadOptionalFields(input);
        }