Skip to content
This repository was archived by the owner on Apr 27, 2024. It is now read-only.
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
20 changes: 20 additions & 0 deletions src/LineBot/GroupSummary/GroupSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Dirk Lemstra (https://github.com/dlemstra/line-bot-sdk-dotnet).
// Licensed under the Apache License, Version 2.0.

using System;
using Newtonsoft.Json;

namespace Line
{
internal sealed class GroupSummary : IGroupSummary
{
[JsonProperty("groupId")]
public string GroupId { get; set; } = default!;

[JsonProperty("groupName")]
public string GroupName { get; set; } = default!;

[JsonProperty("pictureUrl")]
public Uri PictureUrl { get; set; } = default!;
}
}
28 changes: 28 additions & 0 deletions src/LineBot/GroupSummary/IGroupSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Dirk Lemstra (https://github.com/dlemstra/line-bot-sdk-dotnet).
// Licensed under the Apache License, Version 2.0.

using System;

namespace Line
{
/// <summary>
/// Encapsulates the interface for the summary of a group.
/// </summary>
public interface IGroupSummary
{
/// <summary>
/// Gets the Group ID.
/// </summary>
string GroupId { get; }

/// <summary>
/// Gets the Group name.
/// </summary>
string GroupName { get; }

/// <summary>
/// Gets the Group icon URL.
/// </summary>
Uri PictureUrl { get; }
}
}
14 changes: 14 additions & 0 deletions src/LineBot/ILineBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ public interface ILineBot
/// <returns>The events from the specified request.</returns>
Task<ILineEvents> GetEvents(HttpRequest request);

/// <summary>
/// Returns the summary of the specified group.
/// </summary>
/// <param name="group">The group.</param>
/// <returns>The summary of the specified group.</returns>
Task<IGroupSummary?> GetGroupSummmary(IGroup group);

/// <summary>
/// Returns the summary of the specified group.
/// </summary>
/// <param name="groupId">The id of the group.</param>
/// <returns>The summary of the specified group.</returns>
Task<IGroupSummary?> GetGroupSummmary(string groupId);

/// <summary>
/// Returns the profile of the specified user.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions src/LineBot/LineBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,33 @@ public async Task<ILineEvents> GetEvents(HttpRequest request)
return eventCollection;
}

/// <summary>
/// Returns the summary of the specified group.
/// </summary>
/// <param name="groupId">The id of the group.</param>
/// <returns>The summary of the specified group.</returns>
public async Task<IGroupSummary?> GetGroupSummmary(string groupId)
{
Guard.NotNullOrEmpty(nameof(groupId), groupId);

var response = await _client.GetAsync($"group/{groupId}/summary").ConfigureAwait(false);
await response.CheckResult().ConfigureAwait(false);

return await response.Content.DeserializeObject<GroupSummary>().ConfigureAwait(false);
}

/// <summary>
/// Returns the summary of the specified group.
/// </summary>
/// <param name="group">The group.</param>
/// <returns>The summary of the specified group.</returns>
public async Task<IGroupSummary?> GetGroupSummmary(IGroup group)
{
Guard.NotNull(nameof(group), group);

return await GetGroupSummmary(group.Id);
}

/// <summary>
/// Returns the profile of the specified user.
/// </summary>
Expand Down
88 changes: 88 additions & 0 deletions tests/LineBot.Tests/GroupProfile/GroupSummaryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright Dirk Lemstra (https://github.com/dlemstra/line-bot-sdk-dotnet).
// Licensed under the Apache License, Version 2.0.

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Line.Tests
{
[TestClass]
public class GroupSummaryTests
{
[TestMethod]
public async Task GetGroupSummmary_GroupIsNulll_ThrowsException()
{
ILineBot bot = TestConfiguration.CreateBot();
await ExceptionAssert.ThrowsArgumentNullExceptionAsync("group", async () =>
{
IGroupSummary summary = await bot.GetGroupSummmary((IGroup)null);
});
}

[TestMethod]
public async Task GetGroupSummmary_GroupIdIsNull_ThrowsException()
{
ILineBot bot = TestConfiguration.CreateBot();
await ExceptionAssert.ThrowsArgumentNullExceptionAsync("groupId", async () =>
{
IGroupSummary summary = await bot.GetGroupSummmary((string)null);
});
}

[TestMethod]
public async Task GetGroupSummmary_GroupIdIsEmpty_ThrowsException()
{
ILineBot bot = TestConfiguration.CreateBot();
await ExceptionAssert.ThrowsArgumentEmptyExceptionAsync("groupId", async () =>
{
IGroupSummary summary = await bot.GetGroupSummmary(string.Empty);
});
}

[TestMethod]
public async Task GetGroupSummmary_ErrorResponse_ThrowsException()
{
TestHttpClient httpClient = TestHttpClient.ThatReturnsAnError();

ILineBot bot = TestConfiguration.CreateBot(httpClient);

await ExceptionAssert.ThrowsUnknownError(async () =>
{
await bot.GetGroupSummmary("test");
});
}

[TestMethod]
[DeploymentItem(JsonDocuments.GroupSummary)]
public async Task GetGroupSummary_CorrectResponse_ReturnsGroupSummary()
{
TestHttpClient httpClient = TestHttpClient.Create(JsonDocuments.GroupSummary);

ILineBot bot = TestConfiguration.CreateBot(httpClient);
IGroupSummary summary = await bot.GetGroupSummmary("test");

Assert.AreEqual(HttpMethod.Get, httpClient.RequestMethod);
Assert.AreEqual("/group/test/summary", httpClient.RequestPath);

Assert.IsNotNull(summary);
Assert.AreEqual("Ca56f94637c...", summary.GroupId);
Assert.AreEqual("Group name", summary.GroupName);
Assert.AreEqual(new Uri("https://profile.line-scdn.net/abcdefghijklmn"), summary.PictureUrl);
}

[TestMethod]
[DeploymentItem(JsonDocuments.GroupSummary)]
public async Task GetGroupSummary_WithGroup_ReturnsGroupSummary()
{
TestHttpClient httpClient = TestHttpClient.Create(JsonDocuments.GroupSummary);

ILineBot bot = TestConfiguration.CreateBot(httpClient);
IGroupSummary summary = await bot.GetGroupSummmary(new TestGroup());

Assert.AreEqual("/group/testGroup/summary", httpClient.RequestPath);
Assert.IsNotNull(summary);
}
}
}
5 changes: 5 additions & 0 deletions tests/LineBot.Tests/JsonDocuments/GroupSummary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"groupId": "Ca56f94637c...",
"groupName": "Group name",
"pictureUrl": "https://profile.line-scdn.net/abcdefghijklmn"
}
1 change: 1 addition & 0 deletions tests/LineBot.Tests/JsonDocuments/JsonDocuments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public static partial class JsonDocuments
public const string Error = "JsonDocuments/Error.json";
public const string UserProfile = "JsonDocuments/UserProfile.json";
public const string Whitespace = "JsonDocuments/Whitespace.json";
public const string GroupSummary = "JsonDocuments/GroupSummary.json";
}
}