public void TestListUsers() { var response = new FakeHttpResponse(File.ReadAllText("../../Examples/UserList.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/users/list?format=xml&auth_token=ABC123")) .Returns(response); var users = service.List(); Assert.AreEqual(3, users.Count); Assert.AreEqual(1, users[0].Id); Assert.AreEqual("Chris Rivers", users[0].Name); Assert.AreEqual("*****@*****.**", users[0].Email); Assert.AreEqual("Developer", users[0].Title); Assert.AreEqual("https://www.hipchat.com/chris.png", users[0].PhotoUrl); Assert.AreEqual("away", users[0].Status); Assert.AreEqual("gym, bbl", users[0].StatusMessage); Assert.AreEqual(true, users[0].IsGroupAdmin); }
public void TestListUsers() { 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 rooms = service.List(); Assert.AreEqual(2, rooms.Count); Assert.AreEqual(7, rooms[0].Id); Assert.AreEqual("Development", rooms[0].Name); Assert.AreEqual("Make sure to document your API functions well!", rooms[0].Topic); Assert.AreEqual(new DateTime(1970, 1, 1), rooms[0].LastActive); Assert.AreEqual(new DateTime(2010, 3, 19, 14, 51, 51), rooms[0].Created); Assert.AreEqual(1, rooms[0].OwnerUserId); Assert.AreEqual(false, rooms[0].IsArchived); Assert.AreEqual(false, rooms[0].IsPrivate); Assert.AreEqual("7_development", rooms[0].JabberId); }
/// <summary> /// Sets the credentials. /// </summary> /// <param name="credentials">The credentials.</param> public void SetCredentials(Credentials credentials) { // Get Configuration var config = ConfigService.GetConfig(); // Set values config.SetValue("Credentials", "Name", credentials.Name); config.SetValue("Credentials", "JabberId", credentials.JabberId); config.SetValue("Credentials", "Password", credentials.Password); config.SetValue("Credentials", "ApiToken", credentials.ApiToken); // Save to disk ConfigService.SetConfig(config); }
/// <summary> /// Gets the default credentials. /// </summary> /// <returns></returns> public Credentials GetCredentials() { // Get Configuration var config = ConfigService.GetConfig(); var credentials = new Credentials { Name = config.GetValue("Credentials", "Name", string.Empty), JabberId = config.GetValue("Credentials", "JabberID", string.Empty), Password = config.GetValue("Credentials", "Password", string.Empty), ApiToken = config.GetValue("Credentials", "ApiToken", string.Empty) }; return credentials; }
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); }
public void TestStoreCredentials() { var config = new Config(); var credentials = new Credentials { Name = "Bob", JabberId = "123", Password = "******", ApiToken = "123456" }; Mock<IConfigService>() .Setup(call => call.GetConfig()) .Returns(config); service.SetCredentials(credentials); Assert.AreEqual("123456", config.GetValue("Credentials", "ApiToken", string.Empty)); Assert.AreEqual("123", config.GetValue("Credentials", "JabberID", string.Empty)); Assert.AreEqual("Bob", config.GetValue("Credentials", "Name", string.Empty)); Assert.AreEqual("Password", config.GetValue("Credentials", "Password", string.Empty)); }
public void TestGetUser() { var response = new FakeHttpResponse(File.ReadAllText("../../Examples/UserShow.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/users/show?user_id=5&format=xml&auth_token=ABC123")) .Returns(response); var user = service.GetUser(5); Assert.AreEqual(5, user.Id); Assert.AreEqual("Garret Heaton", user.Name); Assert.AreEqual("*****@*****.**", user.Email); Assert.AreEqual("Co-founder", user.Title); Assert.AreEqual("https://www.hipchat.com/img/silhouette_125.png", user.PhotoUrl); Assert.AreEqual("available", user.Status); Assert.AreEqual("Come see what I'm working on!", user.StatusMessage); Assert.AreEqual(true, user.IsGroupAdmin); }
/// <summary> /// Logs in with the specified credentials. /// </summary> /// <param name="credentials">The credentials.</param> public void Login(Credentials credentials) { connection = new XmppClientConnection("chat.hipchat.com"); connection.OnLogin += ConnectionOnLogin; connection.OnAuthError += ConnectionOnAuthError; connection.OnError += ConnectionOnError; connection.OnMessage += ConnectionOnMessage; connection.UseStartTLS = true; connection.Open(credentials.JabberId, credentials.Password, "bot"); current = credentials; }