Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected Tests, new RPC Messages, new Events, RTM Changes for new PresenceSub #130

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local.properties
.classpath
.settings/
.loadpath
.vs/

# External tool builders
.externalToolBuilders/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# SlackAPI

This is a third party implementation of Slack's API written in C#. This supports their WebAPI aswell as their Real Time Messaging API.
This is a third party implementation of Slack's API written in C#. This supports their WebAPI as well as their Real Time Messaging API.

# Examples

Expand All @@ -24,7 +24,7 @@ Want committer access? Feel like I'm too lazy to keep up with Slack's ever chang

Create some pull requests, give me a reason to give you access.

# Howto build the solution
# How to build the solution
###### (aka where is the config.json file?)
The project **SlackAPI.Tests** requires a valid `config.json` file for tests. You have two options to build the solution:
- Unload SlackAPI.Tests project and you're able to build SlackAPI solution.
Expand Down
9 changes: 2 additions & 7 deletions SlackAPI.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using SlackAPI;
using System;
using System.Collections.Generic;
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace SlackAPI
Expand All @@ -31,7 +26,7 @@ static void Main(string[] args)

// start...
var state = Guid.NewGuid().ToString();
var uri = SlackClient.GetAuthorizeUri(clientId, SlackScope.Identify | SlackScope.Read | SlackScope.Post, redirectUri, state, "socialsaleslounge");
var uri = SlackClient.GetAuthorizeUri(clientId, SlackScope.Identify | SlackScope.Read | SlackScope.Post | SlackScope.Client, redirectUri, state, "socialsaleslounge");
Console.WriteLine("Directing to: " + uri);
Process.Start(uri.ToString());

Expand Down
8 changes: 4 additions & 4 deletions SlackAPI.Tests/Configuration/IntegrationCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace SlackAPI.Tests.Configuration
{
[CollectionDefinition("Integration tests")]
public class IntegrationCollection : ICollectionFixture<IntegrationFixture>
{
}
[CollectionDefinition("Integration tests")]
public class IntegrationCollection : ICollectionFixture<IntegrationFixture>
{
}
}
16 changes: 10 additions & 6 deletions SlackAPI.Tests/Configuration/IntegrationFixture.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Newtonsoft.Json;
using SlackAPI.Tests.Helpers;
using System;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using SlackAPI.Tests.Helpers;
using Xunit;

namespace SlackAPI.Tests.Configuration
Expand All @@ -13,18 +13,22 @@ public IntegrationFixture()
{
this.Config = this.GetConfig();
this.UserClient = this.GetClient(this.Config.UserAuthToken);
this.UserClientWithPresence = this.GetClient(this.Config.UserAuthToken, new[] { new Tuple<string, string>("batch_presence_aware", "true") });
this.BotClient = this.GetClient(this.Config.BotAuthToken);
}

public SlackConfig Config { get; }

public SlackSocketClient UserClient { get; }

public SlackSocketClient UserClientWithPresence { get; }

public SlackSocketClient BotClient { get; }

public void Dispose()
{
this.UserClient.CloseSocket();
this.UserClientWithPresence.CloseSocket();
this.BotClient.CloseSocket();
}

Expand All @@ -35,18 +39,18 @@ private SlackConfig GetConfig()
string fileName = Path.Combine(assemblyDirectory, @"configuration\config.json");
string json = System.IO.File.ReadAllText(fileName);

var jsonObject = new {slack = (SlackConfig)null };
var jsonObject = new { slack = (SlackConfig)null };
return JsonConvert.DeserializeAnonymousType(json, jsonObject).slack;
}

private SlackSocketClient GetClient(string authToken)
private SlackSocketClient GetClient(string authToken, Tuple<string, string>[] loginParameters = null)
{
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 = new SlackSocketClient(authToken, loginParameters);
client.Connect(x =>
{
Console.WriteLine("Connected");
Expand Down
2 changes: 1 addition & 1 deletion SlackAPI.Tests/Configuration/SlackConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class SlackConfig
{
public string UserAuthToken { get; set; }
public string BotAuthToken { get; set; }
public string TestChannel { get; set; }
public string TestChannelId { get; set; }
public string DirectMessageUser { get; set; }
public string AuthCode { get; set; }
public string ClientId { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions SlackAPI.Tests/Configuration/config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"slack": {
"userAuthToken": "token-tokentoken-tokentoken-tokentoken-token",
"botAuthToken": "bottoken-bottoken-bottoken-bottoken",
"testChannel": "SuperSecretChannel",
"directMessageUser": "someUserId",
"authCode": "some-super-secret-code-from-Slack-specially-created-for-you-=)",
"clientId": "your-special-id",
"clientSecret": "such-special-secret-key"
"testChannelId": "someChannelId",
"directMessageUser": "someUserId",
"authCode": "some-super-secret-code-from-Slack-specially-created-for-you-=)",
"clientId": "your-special-id",
"clientSecret": "such-special-secret-key"
}
}
11 changes: 9 additions & 2 deletions SlackAPI.Tests/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public void TestConnectAsUser()
Assert.True(client.IsConnected, "Invalid, doesn't think it's connected.");
}

[Fact]
public void TestConnectAsUserWithPresence()
{
var client = this.fixture.UserClientWithPresence;
Assert.True(client.IsConnected, "Invalid, doesn't think it's connected.");
}

[Fact(Skip = "Unable to get a working test with data we have in config.json")]
public void TestGetAccessToken()
{
Expand All @@ -34,7 +41,7 @@ public void TestGetAccessToken()

// act
var accessTokenResponse = GetAccessToken(clientId, clientSecret, "", authCode);

// assert
Assert.NotNull(accessTokenResponse);
Assert.NotNull(accessTokenResponse.bot);
Expand Down Expand Up @@ -71,7 +78,7 @@ public void TestConnectPostAndDelete()
{
// given
SlackSocketClient client = this.fixture.UserClient;
string channel = this.fixture.Config.TestChannel;
string channel = this.fixture.Config.TestChannelId;

// when
DateTime messageTimestamp = PostMessage(client, channel);
Expand Down
2 changes: 1 addition & 1 deletion SlackAPI.Tests/Helpers/InSync.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;

namespace SlackAPI.Tests.Helpers
Expand Down
2 changes: 1 addition & 1 deletion SlackAPI.Tests/JoinDirectMessageChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void ShouldJoinDirectMessageChannel()
client.JoinDirectMessageChannel(response =>
{
actual = response;
sync.Proceed();;
sync.Proceed(); ;
}, user);
}

Expand Down
6 changes: 3 additions & 3 deletions SlackAPI.Tests/PostMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void SimpleMessageDelivery()
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
this.fixture.Config.TestChannelId,
"Hi there!");
}

Expand All @@ -56,7 +56,7 @@ public void Attachments()
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
this.fixture.Config.TestChannelId,
string.Empty,
attachments: SlackMother.SomeAttachments);
}
Expand All @@ -81,7 +81,7 @@ public void AttachmentsWithActions()
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
this.fixture.Config.TestChannelId,
string.Empty,
attachments: SlackMother.SomeAttachmentsWithActions);
}
Expand Down
41 changes: 41 additions & 0 deletions SlackAPI.Tests/PresenceSub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using SlackAPI.Tests.Configuration;
using SlackAPI.Tests.Helpers;
using System.Linq;
using Xunit;

namespace SlackAPI.Tests
{
[Collection("Integration tests")]
public class PresenceSub
{
private readonly IntegrationFixture fixture;

public PresenceSub(IntegrationFixture fixture)
{
this.fixture = fixture;
}

[Fact]
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();
}
}
}
}
1 change: 1 addition & 0 deletions SlackAPI.Tests/SlackAPI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="PostMessage.cs" />
<Compile Include="JoinDirectMessageChannel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PresenceSub.cs" />
<Compile Include="Users.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions SlackAPI.Tests/Update.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using SlackAPI.Tests.Configuration;
using SlackAPI.Tests.Helpers;
using System;
using Xunit;

namespace SlackAPI.Tests
{
[Collection("Integration tests")]
public class Update
public class Update
{
private readonly IntegrationFixture fixture;

Expand All @@ -32,7 +33,7 @@ public void SimpleUpdate()
sync.Proceed();
},
messageId,
this.fixture.Config.TestChannel,
this.fixture.Config.TestChannelId,
"[changed]",
attachments: SlackMother.SomeAttachments,
as_user: true);
Expand All @@ -56,7 +57,7 @@ private string PostedMessage(SlackSocketClient client)
Assert.True(response.ok, "Error while posting message to channel. ");
sync.Proceed();
},
this.fixture.Config.TestChannel,
this.fixture.Config.TestChannelId,
"Hi there!",
as_user: true);
}
Expand Down
5 changes: 3 additions & 2 deletions SlackAPI.Tests/Users.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq;
using SlackAPI.Tests.Configuration;
using SlackAPI.Tests.Configuration;
using SlackAPI.Tests.Helpers;
using System.Linq;
using Xunit;

namespace SlackAPI.Tests
Expand All @@ -14,6 +14,7 @@ public Users(IntegrationFixture fixture)
{
this.fixture = fixture;
}

[Fact]
public void UserList()
{
Expand Down
5 changes: 3 additions & 2 deletions SlackAPI/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Attachment
public string title_link;
public string text;
public Field[] fields;

public string image_url;
public string thumb_url;
public string[] mrkdwn_in;
Expand All @@ -24,7 +24,8 @@ public class Attachment
public string footer_icon;
}

public class Field{
public class Field
{
public string title;
public string value;
public bool @short;
Expand Down
6 changes: 2 additions & 4 deletions SlackAPI/Bot.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;

namespace SlackAPI
namespace SlackAPI
{
public class Bot
{
public string emoji;
public string emoji;
public string image_24;
public string image_32;
public string image_48;
Expand Down
8 changes: 1 addition & 7 deletions SlackAPI/Channel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackAPI
namespace SlackAPI
{
public class Channel : Conversation
{
Expand Down
8 changes: 1 addition & 7 deletions SlackAPI/ContextMessage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackAPI
namespace SlackAPI
{
public class ContextMessage : Message
{
Expand Down
4 changes: 0 additions & 4 deletions SlackAPI/Conversation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackAPI
{
Expand Down
8 changes: 1 addition & 7 deletions SlackAPI/DirectMessageConversation.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackAPI
namespace SlackAPI
{
public class DirectMessageConversation : Conversation
{
Expand Down
Loading