public void ParseErrorMessageWithoutCode() { const string message = "::No clientID"; BayeuxError error = new BayeuxError(message); Assert.IsTrue(false, "Exception should be thrown already!"); }
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"); }
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"); }
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"); }
/// <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); }
/// <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); }