Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
SDK-8 fix search by user emails (#21)
Browse files Browse the repository at this point in the history
* fix search by user emails, add integration test
  • Loading branch information
vladokrsymphony authored Apr 7, 2020
1 parent efd9e25 commit ce0195d
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#Junk Files
*.DS_Store
[Tt]humbs.db
*/Resources/config.json
*/Resources/integration.parameters.json

#Visual Studio Files
[Oo]bj
Expand Down
3 changes: 2 additions & 1 deletion apiClientDotNet/Clients/UserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public List<UserInfo> getUsersV3(List<String> emailList, List<long> idList, Bool
else if (resp.StatusCode == HttpStatusCode.OK)
{
string body = restRequestHandler.ReadResponse(resp);
infoList = JsonConvert.DeserializeObject<List<UserInfo>>(body);
var userInfoList = JsonConvert.DeserializeObject<UserInfoList>(body);
infoList = userInfoList.users;
}
resp.Close();
return infoList;
Expand Down
18 changes: 11 additions & 7 deletions apiClientDotNetTest/MessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using apiClientDotNet.Models;
using apiClientDotNet;
using apiClientDotNet.Authentication;
using Microsoft.Extensions.Configuration;

namespace apiClientDotNetTest
{
Expand All @@ -14,13 +15,16 @@ public class MessageTest
{
private static SymBotClient botClient = null;
private static string attachmentTestPath = null;
// to be moved to some integration tests config file
private static readonly string testUserName = "vlado.kragujevski";
private static readonly string testRoomName = "NETSDK";
private static IConfigurationRoot config;

[ClassInitialize]
public static void Setup(TestContext conext)
{
{
// Load integration test settings
var integrationConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "integration.parameters.json");
config = new ConfigurationBuilder().AddJsonFile(integrationConfigPath).Build();

// Create SymBotClient
var symConfigLoader = new SymConfigLoader();
attachmentTestPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "AttachmentTest.txt");
var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "config.json");
Expand All @@ -36,7 +40,7 @@ public void SearchRoom()
var streamClient = botClient.getStreamsClient();
var roomSearchQuery = new RoomSearchQuery
{
query = testRoomName,
query = config.GetSection("test_room_name").Value,
active = true,
isPrivate = true
};
Expand All @@ -49,9 +53,9 @@ public void SearchRoom()
public void GetUserIdByUserName()
{
var userClient = botClient.getUsersClient();
var user = userClient.getUserFromUsername(testUserName);
var user = userClient.getUserFromUsername(config.GetSection("test_username").Value);
Assert.IsNotNull(user);
Assert.AreEqual("Vlado Kragujevski", user.displayName);
Assert.AreEqual(config.GetSection("test_displayname").Value, user.displayName);
}

[TestMethod]
Expand Down
14 changes: 14 additions & 0 deletions apiClientDotNetTest/Resources/template.integration.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Please use this template to create the integration parameters configuration file
// The integration tests needs a file named integration.parameters.json in the Resources folder
{
// Parameters common for all tests
"test_username": "user name",
"test_useremail": "user email",
"test_displayname": "account display name",
"test_room_name": "name of a room",
// Parameters related to a specific test
"UserClientIntegrationTest": {
"test_email_addresses": "comma separated string of email addresses",
"test_search_user_query": "search by some query like name"
}
}
69 changes: 69 additions & 0 deletions apiClientDotNetTest/UserClientIntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using apiClientDotNet;
using apiClientDotNet.Authentication;
using apiClientDotNet.Clients;
using apiClientDotNet.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;

namespace apiClientDotNetTest
{
[TestClass]
public class UserClientIntegrationTest
{
private static SymBotClient symBotClient;
private static IConfigurationRoot config;

[ClassInitialize]
public static void Init(TestContext context)
{
// Load integration test settings
var integrationConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "integration.parameters.json");
config = new ConfigurationBuilder().AddJsonFile(integrationConfigPath).Build();

// Create SymBotClient
var symConfig = new SymConfig();
var symConfigLoader = new SymConfigLoader();
var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "config.json");
symConfig = symConfigLoader.loadFromFile(configPath);
var botAuth = new SymBotRSAAuth(symConfig);
botAuth.authenticate();
symBotClient = SymBotClient.initBot(symConfig, botAuth);
}

[TestMethod]
public void GetUsersV3_forGivenListOfEmails_correctlyReturnListOfUsers()
{
var emails = config.GetSection(this.GetType().Name).GetSection("test_email_addresses").Value;
var emailList = emails.Split(",");
var sut = new UserClient(symBotClient);

List<UserInfo> listUserInfo = sut.getUsersV3(new List<string>(emailList), null, false);

Assert.IsNotNull(listUserInfo);
Assert.AreEqual(3, listUserInfo.Count);
Assert.IsFalse(String.IsNullOrEmpty(listUserInfo[0].displayName));
Assert.IsFalse(String.IsNullOrEmpty(listUserInfo[0].username));

Assert.IsFalse(String.IsNullOrEmpty(listUserInfo[1].displayName));
Assert.IsFalse(String.IsNullOrEmpty(listUserInfo[1].username));

Assert.IsFalse(String.IsNullOrEmpty(listUserInfo[2].displayName));
Assert.IsFalse(String.IsNullOrEmpty(listUserInfo[2].username));
}

[TestMethod]
public void SearchUsers_forGivenSearchQuery_correctlyReturnsListOfUsers()
{
var query = config.GetSection(this.GetType().Name).GetSection("test_search_user_query").Value;
var sut = new UserClient(symBotClient);

UserSearchResult searchUsers = sut.searchUsers(query, false, 0, 10, null);

Assert.IsNotNull(searchUsers);
Assert.IsTrue(searchUsers.users.Count >= 1);
}
}
}
11 changes: 9 additions & 2 deletions apiClientDotNetTest/apiClientDotNetTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
Expand All @@ -36,11 +38,16 @@
<HintPath>System.Xml</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="Resources\AttachmentTest.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\integration.parameters.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>

0 comments on commit ce0195d

Please sign in to comment.