public void SimpleUpdate() { // given var client = this.fixture.UserClient; var messageId = PostedMessage(client); UpdateResponse actual = null; // when using (var sync = new InSync(nameof(SlackClient.Update))) { client.Update( response => { actual = response; sync.Proceed(); }, messageId, this.fixture.Config.TestChannel, "[changed]", attachments: SlackMother.SomeAttachments, as_user: true); } // then Assert.True(actual.ok, "Error while posting message to channel. "); Assert.Equal(actual.message.text, "[changed]"); Assert.Equal(actual.message.type, "message"); }
public void SimpleUpdate() { // given var client = ClientHelper.GetClient(_config.Slack.UserAuthToken); var messageId = PostedMessage(client); UpdateResponse actual = null; // when using (var sync = new InSync()) { client.Update( response => { actual = response; sync.Proceed(); }, messageId, _config.Slack.TestChannel, "[changed]", attachments: SlackMother.SomeAttachments, as_user: true); } // then Assert.IsTrue(actual.Ok, "Error while posting message to channel. "); Assert.AreEqual(actual.message.text, "[changed]"); Assert.AreEqual(actual.message.type, "message"); }
public void UserList() { var client = this.fixture.UserClient; UserListResponse actual = null; using (var sync = new InSync(nameof(SlackClient.UserLookup))) { client.GetUserList(response => { actual = response; sync.Proceed(); }); } Assert.True(actual.ok, "Error while fetching user list."); Assert.True(actual.members.Any()); // apparently deleted users do indeed have null values, so if the first user returned is deleted then there are failures. var someMember = actual.members.Where(x => !x.deleted).First(); Assert.NotNull(someMember.id); Assert.NotNull(someMember.color); Assert.NotNull(someMember.real_name); Assert.NotNull(someMember.name); Assert.NotNull(someMember.team_id); Assert.NotNull(someMember.tz); Assert.NotNull(someMember.tz_label); }
public void TestManualSubscribePresenceChangeAndManualPresenceChange() { // Arrange slackClient = this.fixture.CreateUserClient(); using (var sync = new InSync()) { slackClient.OnPresenceChanged += x => { if (x.user == slackClient.MySelf.id) { // Assert sync.Proceed(); } }; slackClient.SubscribePresenceChange(slackClient.MySelf.id); } using (var sync = new InSync()) { slackClient.OnPresenceChanged += x => { if (x is ManualPresenceChange && x.user == slackClient.MySelf.id) { // Assert sync.Proceed(); } }; // Act slackClient.EmitPresence(x => x.AssertOk(), Presence.away); slackClient.EmitPresence(x => x.AssertOk(), Presence.auto); } }
public void PostEphemeralMessage() { // given var client = this.fixture.UserClient; PostEphemeralResponse actual = null; string userName = this.fixture.Config.DirectMessageUser; string userId = client.Users.First(x => x.name.Equals(userName, StringComparison.OrdinalIgnoreCase)).id; // when using (var sync = new InSync(nameof(SlackClient.PostEphemeralMessage))) { client.PostEphemeralMessage( response => { actual = response; sync.Proceed(); }, this.fixture.Config.TestChannel, "Hi there!", userId); } // then Assert.True(actual.ok, "Error while posting message to channel. "); Assert.Null(actual.error); }
public void BlocksInAttachment() { // given var client = this.fixture.UserClient; PostMessageResponse actual = null; // when using (var sync = new InSync(nameof(SlackClient.PostMessage))) { client.PostMessage( response => { actual = response; sync.Proceed(); }, this.fixture.Config.TestChannel, "These blocks are in an attachment", attachments: new [] { new Attachment { blocks = SlackMother.SomeBlocks } }); } // then Assert.True(actual.ok, "Error while posting message to channel. "); }
private SlackSocketClient CreateClient(string authToken, IWebProxy proxySettings = null) { SlackSocketClient client; LoginResponse loginResponse = null; using (var syncClient = new InSync($"{nameof(SlackClient.Connect)} - Connected callback")) using (var syncClientSocket = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected callback")) using (var syncClientSocketHello = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected hello callback")) { client = new SlackSocketClient(authToken, proxySettings); client.OnHello += () => syncClientSocketHello.Proceed(); client.Connect(x => { loginResponse = x; Console.WriteLine($"Connected {x.ok}"); syncClient.Proceed(); if (!x.ok) { // If connect fails, socket connect callback is not called syncClientSocket.Proceed(); syncClientSocketHello.Proceed(); } }, () => { Console.WriteLine("Socket Connected"); syncClientSocket.Proceed(); }); } loginResponse.AssertOk(); return(client); }
public void UploadFile_Succeeds() { // Arrange const int FileSize = 500; const string FileName = "MyFile.bin"; byte[] data = new byte[FileSize]; // Act FileUploadResponse fileUploadResponse = null; using (var sync = new InSync(nameof(SlackClient.UploadFile))) { this.fixture.UserClient.UploadFile(c => { fileUploadResponse = c; Assert.True(c.ok); sync.Proceed(); }, data, FileName, new[] { this.fixture.Config.TestChannel }); } // Assert using (var sync = new InSync(nameof(SlackClient.UploadFile))) { this.fixture.UserClient.GetFileInfo(c => { Assert.True(c.ok); Assert.Equal(FileSize, c.file.size); Assert.Equal(FileName, c.file.name); Assert.Equal(new[] { this.fixture.Config.TestChannel }, c.file.channels); sync.Proceed(); }, fileUploadResponse.file.id); } }
public void UserList() { var client = this.fixture.UserClient; UserListResponse actual = null; using (var sync = new InSync(nameof(SlackClient.UserLookup))) { client.GetUserList(response => { actual = response; sync.Proceed(); }); } Assert.True(actual.ok, "Error while fetching user list."); Assert.True(actual.members.Any()); var someMember = actual.members.First(); Assert.NotNull(someMember.id); Assert.NotNull(someMember.color); Assert.NotNull(someMember.real_name); Assert.NotNull(someMember.name); Assert.NotNull(someMember.team_id); Assert.NotNull(someMember.tz); Assert.NotNull(someMember.tz_label); }
public void UpdatePresence() { var client = this.fixture.UserClient; using (var sync = new InSync(nameof(SlackClient.EmitPresence))) { client.EmitPresence((presence) => { presence.AssertOk(); sync.Proceed(); }, Presence.away); } }
public void UpdatePresence() { var client = ClientHelper.GetClient(_config.Slack.UserAuthToken); using (var sync = new InSync()) { client.EmitPresence((presence) => { presence.AssertOk(); sync.Proceed(); }, Presence.away); } }
private AccessTokenResponse GetAccessToken(SlackClientHelpers slackClientHelpers, string clientId, string clientSecret, string redirectUri, string authCode) { AccessTokenResponse accessTokenResponse = null; using (var sync = new InSync(nameof(slackClientHelpers.GetAccessToken))) { slackClientHelpers.GetAccessToken(response => { accessTokenResponse = response; sync.Proceed(); }, clientId, clientSecret, redirectUri, authCode); } return(accessTokenResponse); }
private static DeletedResponse DeleteMessage(SlackSocketClient client, string channel, DateTime messageTimestamp) { DeletedResponse deletedResponse = null; using (var sync = new InSync(nameof(SlackClient.DeleteMessage))) { client.DeleteMessage(response => { deletedResponse = response; sync.Proceed(); }, channel, messageTimestamp); } return(deletedResponse); }
private static DateTime PostMessage(SlackSocketClient client, string channel) { MessageReceived sendMessageResponse = null; using (var sync = new InSync(nameof(SlackSocketClient.SendMessage))) { client.SendMessage(response => { sendMessageResponse = response; sync.Proceed(); }, channel, TestText); } Assert.NotNull(sendMessageResponse); Assert.Equal(TestText, sendMessageResponse.text); return(sendMessageResponse.ts); }
private string PostedMessage(SlackSocketClient client) { string messageId = null; using (var sync = new InSync(nameof(SlackClient.PostMessage))) { client.PostMessage( response => { messageId = response.ts; Assert.True(response.ok, "Error while posting message to channel. "); sync.Proceed(); }, this.fixture.Config.TestChannel, "Hi there!", as_user: true); } return(messageId); }
private SlackSocketClient CreateClient(string authToken, IWebProxy proxySettings = null, bool maintainPresenceChanges = false, Action <SlackSocketClient, PresenceChange> presenceChanged = null) { SlackSocketClient client; LoginResponse loginResponse = null; using (var syncClient = new InSync($"{nameof(SlackClient.Connect)} - Connected callback")) using (var syncClientSocket = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected callback")) using (var syncClientSocketHello = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected hello callback")) { client = new SlackSocketClient(authToken, proxySettings, maintainPresenceChanges); void OnPresenceChanged(PresenceChange x) { presenceChanged?.Invoke(client, x); } client.OnPresenceChanged += OnPresenceChanged; client.OnHello += () => syncClientSocketHello.Proceed(); client.Connect(x => { loginResponse = x; Console.WriteLine($"Connected {x.ok}"); syncClient.Proceed(); if (!x.ok) { // If connect fails, socket connect callback is not called syncClientSocket.Proceed(); syncClientSocketHello.Proceed(); } }, () => { Console.WriteLine("Socket Connected"); syncClientSocket.Proceed(); }); } loginResponse.AssertOk(); return(client); }
public void PresenceSubscribe() { var client = this.fixture.UserClientWithPresence; var directMessageUser = client.Users.FirstOrDefault(x => x.name == this.fixture.Config.DirectMessageUser); Assert.NotNull(directMessageUser); //UserListResponse actual = null; using (var sync = new InSync(nameof(SlackClient.UserLookup))) { client.OnPresenceChangeReceived += (user) => { }; client.OnUserChangeReceived += (user) => { }; client.SendPresenceSub(new[] { directMessageUser.id }); sync.Proceed(); } }
public void TestConnectGetPresenceChanges() { // Arrange int presenceChangesRaisedCount = 0; using (var sync = new InSync(nameof(TestConnectGetPresenceChanges), this.fixture.ConnectionTimeout)) { void OnPresenceChanged(SlackSocketClient sender, PresenceChange e) { if (++presenceChangesRaisedCount == sender.Users.Count) { sync.Proceed(); } } // Act slackClient = this.fixture.CreateUserClient(maintainPresenceChangesStatus: true, presenceChanged: OnPresenceChanged); } // Assert Assert.True(slackClient.Users.All(x => x.presence != null)); }
public void ConversationList() { var client = this.fixture.UserClient; ConversationsListResponse actual = null; using (var sync = new InSync(nameof(SlackClient.ChannelLookup))) { client.GetConversationsList(response => { actual = response; sync.Proceed(); }); } Assert.True(actual.ok, "Error while fetching conversation list."); Assert.True(actual.channels.Any()); // check to null var someChannel = actual.channels.First(); Assert.NotNull(someChannel.id); Assert.NotNull(someChannel.name); }
public void AttachmentsWithActions() { // given var client = this.fixture.UserClient; PostMessageResponse actual = null; // when using (var sync = new InSync()) { client.PostMessage( response => { actual = response; sync.Proceed(); }, this.fixture.Config.TestChannel, string.Empty, attachments: SlackMother.SomeAttachmentsWithActions); } // then Assert.True(actual.ok, "Error while posting message to channel. "); }
public void ShouldJoinDirectMessageChannel() { // given var client = this.fixture.UserClient; JoinDirectMessageChannelResponse actual = null; string userName = this.fixture.Config.DirectMessageUser; string user = client.Users.First(x => x.name.Equals(userName, StringComparison.InvariantCultureIgnoreCase)).id; // when using (var sync = new InSync(nameof(SlackClient.JoinDirectMessageChannel))) { client.JoinDirectMessageChannel(response => { actual = response; sync.Proceed();; }, user); } // then Assert.True(actual.ok, "Error while joining user channel"); Assert.NotEmpty(actual.channel.id); }
public void Attachments() { // given var client = ClientHelper.GetClient(_config.Slack.UserAuthToken); PostMessageResponse actual = null; // when using (var sync = new InSync()) { client.PostMessage( response => { actual = response; sync.Proceed(); }, _config.Slack.TestChannel, string.Empty, attachments: SlackMother.SomeAttachments); } // then Assert.IsTrue(actual.ok, "Error while posting message to channel. "); }
private SlackSocketClient GetClient(string authToken) { SlackSocketClient client; using (var syncClient = new InSync($"{nameof(SlackClient.Connect)} - Connected callback")) using (var syncClientSocket = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected callback")) { client = new SlackSocketClient(authToken); client.Connect(x => { Console.WriteLine("Connected"); syncClient.Proceed(); }, () => { Console.WriteLine("Socket Connected"); syncClientSocket.Proceed(); }); } Assert.True(client.IsConnected, "Doh, still isn't connected"); return(client); }
public void SimpleMessageDelivery() { // given var client = this.fixture.UserClient; PostMessageResponse actual = null; // when using (var sync = new InSync(nameof(SlackClient.PostMessage))) { client.PostMessage( response => { actual = response; sync.Proceed(); }, this.fixture.Config.TestChannel, "Hi there!"); } // then Assert.True(actual.ok, "Error while posting message to channel. "); Assert.Equal("Hi there!", actual.message.text); Assert.Equal("message", actual.message.type); }
public void SimpleMessageDelivery() { // given var client = ClientHelper.GetClient(_config.Slack.UserAuthToken); PostMessageResponse actual = null; // when using (var sync = new InSync()) { client.PostMessage( response => { actual = response; sync.Proceed(); }, _config.Slack.TestChannel, "Hi there!"); } // then Assert.IsTrue(actual.ok, "Error while posting message to channel. "); Assert.AreEqual(actual.message.text, "Hi there!"); Assert.AreEqual(actual.message.type, "message"); }