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 #63 from noobot/return-message-sub-type
Return message sub type
- Loading branch information
Showing
8 changed files
with
146 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using SlackConnector.Connections.Sockets.Messages.Inbound; | ||
using SlackConnector.Models; | ||
|
||
namespace SlackConnector.Extensions | ||
{ | ||
internal static class MessageSubTypeExtensions | ||
{ | ||
public static SlackMessageSubType ToSlackMessageSubType(this MessageSubType subType) | ||
{ | ||
return (SlackMessageSubType)subType; | ||
} | ||
} | ||
} |
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,30 @@ | ||
namespace SlackConnector.Models | ||
{ | ||
public enum SlackMessageSubType | ||
{ | ||
Unknown = 0, | ||
BotMessage, | ||
MeMessage, | ||
MessageChanged, | ||
MessageDeleted, | ||
ChannelJoin, | ||
ChannelLeave, | ||
ChannelTopic, | ||
ChannelPurpose, | ||
ChannelName, | ||
ChannelArchive, | ||
ChannelUnarchive, | ||
GroupJoin, | ||
GroupLeave, | ||
GroupTopic, | ||
GroupPurpose, | ||
GroupName, | ||
GroupArchive, | ||
GroupUnarchive, | ||
FileShare, | ||
FileComment, | ||
FileMention, | ||
PinnedItem, | ||
UnpinnedItem | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
tests/SlackConnector.Tests.Unit/Extensions/MessageSubTypeExtensionsTests.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,23 @@ | ||
using Shouldly; | ||
using SlackConnector.Connections.Sockets.Messages.Inbound; | ||
using SlackConnector.Extensions; | ||
using SlackConnector.Models; | ||
using Xunit; | ||
|
||
namespace SlackConnector.Tests.Unit.Extensions | ||
{ | ||
public class MessageSubTypeExtensionsTests | ||
{ | ||
[Theory] | ||
[InlineData(MessageSubType.bot_message, SlackMessageSubType.BotMessage)] | ||
[InlineData(MessageSubType.channel_name, SlackMessageSubType.ChannelName)] | ||
[InlineData(MessageSubType.channel_topic, SlackMessageSubType.ChannelTopic)] | ||
[InlineData(MessageSubType.group_join, SlackMessageSubType.GroupJoin)] | ||
private void should_convert_to_expected_enum(MessageSubType inbound, SlackMessageSubType expected) | ||
{ | ||
inbound | ||
.ToSlackMessageSubType() | ||
.ShouldBe(expected); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/SlackConnector.Tests.Unit/Models/MessageSubTypeEnumTests.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,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Shouldly; | ||
using SlackConnector.Connections.Sockets.Messages.Inbound; | ||
using SlackConnector.Models; | ||
using Xunit; | ||
|
||
namespace SlackConnector.Tests.Unit.Models | ||
{ | ||
public class MessageSubTypeEnumTests | ||
{ | ||
[Fact] | ||
public void should_have_same_number_of_enum_values_as_internal_enum_type() | ||
{ | ||
// given | ||
int numberOfInternalEnumNames = Enum.GetNames(typeof(MessageSubType)).Length; | ||
int numberOfPublicEnumNames = Enum.GetNames(typeof(SlackMessageSubType)).Length; | ||
|
||
// then | ||
numberOfPublicEnumNames.ShouldBe(numberOfInternalEnumNames); | ||
} | ||
|
||
[Fact] | ||
public void should_have_same_message_types_as_internal_models() | ||
{ | ||
// given | ||
var internalEnumNames = Enum.GetNames(typeof(MessageSubType)) | ||
.Select(x => x.Replace("_", string.Empty)) | ||
.Select(x => x.ToLower()); | ||
var publicEnumNames = Enum.GetNames(typeof(SlackMessageSubType)) | ||
.Select(x => x.ToLower()); | ||
|
||
// then | ||
publicEnumNames.All(x => internalEnumNames.Contains(x)).ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_have_same_message_type_values_as_internal_models() | ||
{ | ||
// given | ||
var internalEnumValues = GetEnumValues<MessageSubType>(); | ||
var publicEnumValues = GetEnumValues<SlackMessageSubType>(); | ||
|
||
// then | ||
foreach (var publicEnumName in publicEnumValues.Keys) | ||
{ | ||
publicEnumValues[publicEnumName].ShouldBe(internalEnumValues[publicEnumName]); | ||
} | ||
} | ||
|
||
private static Dictionary<string, int> GetEnumValues<T>() where T : struct, IConvertible | ||
{ | ||
var internalEnumNames = Enum.GetNames(typeof(T)); | ||
|
||
var vals = new Dictionary<string, int>(); | ||
foreach (var enumName in internalEnumNames) | ||
{ | ||
T thingy; | ||
Enum.TryParse(enumName, out thingy); | ||
|
||
var name = enumName | ||
.Replace("_", string.Empty) | ||
.ToLower(); | ||
|
||
vals.Add(name, thingy.ToInt32(new NumberFormatInfo())); | ||
} | ||
return vals; | ||
} | ||
} | ||
} |
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