public void TestGetJabberIdForUser() { var user = new User { Id = 1234 }; var response = new FakeHttpResponse(File.ReadAllText("../../Examples/RoomList.xml")); var credentials = new Credentials { ApiToken = "ABC123" }; Mock<ICredentialService>() .Setup(call => call.GetCredentials()) .Returns(credentials); Mock<IHttpService>() .Setup(call => call.Get("https://api.hipchat.com/v1/rooms/list?format=xml&auth_token=ABC123")) .Returns(response); var jabberId = service.GetJabberIdForUser(user); Assert.AreEqual("7_1234", jabberId); }
/// <summary> /// Gets the jabber id for user with the given id. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> public string GetJabberIdForUser(User user) { var jabberId = string.Empty; // Get all the rooms in the account var credentials = CredentialService.GetCredentials(); var url = "https://api.hipchat.com/v1/rooms/list?format=xml&auth_token=" + credentials.ApiToken; var response = HttpService.Get(url); if (response.Success) { // Set the Jabber Id to the account id from the room name jabberId = response.ToXml().GetInnerXml("//xmpp_jid").SubstringBeforeChar("_"); } return jabberId + "_" + user.Id; }