This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from noobot/channel-created
Add Channel created event
- Loading branch information
Showing
11 changed files
with
202 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/SlackConnector/Connections/Sockets/Messages/Inbound/ChannelCreatedMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using SlackConnector.Connections.Models; | ||
|
||
namespace SlackConnector.Connections.Sockets.Messages.Inbound | ||
{ | ||
internal class ChannelCreatedMessage : InboundMessage | ||
{ | ||
public ChannelCreatedMessage() | ||
{ | ||
MessageType = MessageType.Channel_Created; | ||
} | ||
|
||
public Channel Channel { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ internal enum MessageType | |
Im_Created, | ||
Team_Join, | ||
Pong, | ||
Reaction_Added | ||
Reaction_Added, | ||
Channel_Created | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System.Threading.Tasks; | ||
using SlackConnector.Models; | ||
|
||
namespace SlackConnector.EventHandlers | ||
{ | ||
public delegate Task ChannelCreatedHandler(SlackChannelCreated chatHub); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SlackConnector.Models | ||
{ | ||
public class SlackChannelCreated | ||
{ | ||
public string Id { get; internal set; } | ||
public string Name { get; internal set; } | ||
public SlackUser Creator { get; internal set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...SlackConnector.Tests.Unit/SlackConnectionTests/InboundMessageTests/ChannelCreatedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using Ploeh.AutoFixture; | ||
using SlackConnector.Connections.Models; | ||
using SlackConnector.Connections.Sockets; | ||
using SlackConnector.Connections.Sockets.Messages.Inbound; | ||
using SlackConnector.Models; | ||
using Xunit; | ||
using Shouldly; | ||
|
||
namespace SlackConnector.Tests.Unit.SlackConnectionTests.InboundMessageTests | ||
{ | ||
public class ChannelCreatedTests | ||
{ | ||
[Theory, AutoMoqData] | ||
private async Task should_raise_event( | ||
Mock<IWebSocketClient> webSocket, | ||
SlackConnection slackConnection, | ||
SlackUser slackUser, | ||
Fixture fixture) | ||
{ | ||
// given | ||
var connectionInfo = new ConnectionInformation | ||
{ | ||
WebSocket = webSocket.Object, | ||
Users = new Dictionary<string, SlackUser> | ||
{ | ||
{slackUser.Id , slackUser} | ||
} | ||
}; | ||
await slackConnection.Initialise(connectionInfo); | ||
|
||
SlackChannelCreated channelCreated = null; | ||
slackConnection.OnChannelCreated += channel => | ||
{ | ||
channelCreated = channel; | ||
return Task.CompletedTask; | ||
}; | ||
|
||
var inboundMessage = new ChannelCreatedMessage | ||
{ | ||
Channel = new Channel | ||
{ | ||
Creator = slackUser.Id, | ||
Id = fixture.Create<string>(), | ||
Name = fixture.Create<string>() | ||
} | ||
}; | ||
|
||
// when | ||
webSocket.Raise(x => x.OnMessage += null, null, inboundMessage); | ||
|
||
// then | ||
channelCreated.Id.ShouldBe(inboundMessage.Channel.Id); | ||
channelCreated.Name.ShouldBe(inboundMessage.Channel.Name); | ||
channelCreated.Creator.ShouldBe(slackUser); | ||
slackConnection.ConnectedHubs.ContainsKey(inboundMessage.Channel.Id).ShouldBeTrue(); | ||
} | ||
|
||
[Theory, AutoMoqData] | ||
private async Task should_not_raise_event_given_missing_data( | ||
Mock<IWebSocketClient> webSocket, | ||
SlackConnection slackConnection) | ||
{ | ||
// given | ||
var connectionInfo = new ConnectionInformation { WebSocket = webSocket.Object }; | ||
await slackConnection.Initialise(connectionInfo); | ||
|
||
SlackChannelCreated channelCreated = null; | ||
slackConnection.OnChannelCreated += channel => | ||
{ | ||
channelCreated = channel; | ||
return Task.CompletedTask; | ||
}; | ||
|
||
var inboundMessage = new ChannelCreatedMessage { Channel = null }; | ||
|
||
// when | ||
webSocket.Raise(x => x.OnMessage += null, null, inboundMessage); | ||
|
||
// then | ||
channelCreated.ShouldBeNull(); | ||
slackConnection.ConnectedHubs.ShouldBeEmpty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters