-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Rest Client Factory * Added tests and version bump * Made backwards compatible * Version change * Made factory thread safe * Version bump and doc update
- Loading branch information
1 parent
f84a9a5
commit d0e6eba
Showing
30 changed files
with
300 additions
and
57 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
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
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
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
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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Net; | ||
using Intercom.Core; | ||
using Intercom.Data; | ||
using Intercom.Clients; | ||
using Intercom.Exceptions; | ||
using Intercom.Factories; | ||
using RestSharp; | ||
using RestSharp.Authenticators; | ||
using System.Collections.Generic; | ||
|
@@ -17,39 +19,71 @@ public class UserClientTest : TestBase | |
{ | ||
private UsersClient usersClient; | ||
|
||
public UserClientTest() | ||
public UserClientTest() { } | ||
|
||
private void SetupMock(RestClient restClient = null) | ||
{ | ||
this.usersClient = new UsersClient(new Authentication(AppId, AppKey)); | ||
var auth = new Authentication(AppId, AppKey); | ||
if (restClient == null) | ||
{ | ||
var restClientMock = new Mock<RestClient>(); | ||
restClient = restClientMock.Object; | ||
} | ||
var restClientFactoryMock = new Mock<RestClientFactory>(new object[] { auth }); | ||
restClientFactoryMock.Setup(x => x.RestClient).Returns(restClient); | ||
var restClientFactory = restClientFactoryMock.Object; | ||
usersClient = new UsersClient(restClientFactory); | ||
} | ||
|
||
[Test()] | ||
public void Create_WithNull_ThrowException() | ||
{ | ||
SetupMock(); | ||
Assert.Throws<ArgumentNullException>(() => usersClient.Create(null)); | ||
} | ||
|
||
[Test()] | ||
public void Create_NoUserIdOrEmail_ThrowException() | ||
{ | ||
SetupMock(); | ||
Assert.Throws<ArgumentException>(() => usersClient.Create(new User())); | ||
} | ||
|
||
[Test()] | ||
public void Archive_NoIdOrUserIdOrEmail_ThrowException() | ||
{ | ||
SetupMock(); | ||
Assert.Throws<ArgumentException>(() => usersClient.Archive(new User())); | ||
} | ||
|
||
[Test()] | ||
public void PermanentlyDeleteUser_NoId_ThrowException() | ||
{ | ||
SetupMock(); | ||
Assert.Throws<ArgumentNullException>(() => usersClient.PermanentlyDeleteUser(null)); | ||
} | ||
|
||
[Test()] | ||
public void Update_NoIdOrUserIdOrEmail_ThrowException() | ||
{ | ||
SetupMock(); | ||
Assert.Throws<ArgumentException>(() => usersClient.Update(new User())); | ||
} | ||
|
||
[Test()] | ||
public void View_ByStringId_ReturnsObjectAsExpected() | ||
{ | ||
var userId = "id"; | ||
var restClientMock = new Mock<RestClient>(); | ||
var restResponse = new RestResponse() | ||
{ | ||
StatusCode = HttpStatusCode.OK, | ||
Content = $"{{ \"type\": \"user\", \"id\": \"530370b477ad7120001d\", \"user_id\": \"{userId}\", \"email\": \"[email protected]\" }}", | ||
}; | ||
restClientMock.Setup(x => x.Execute(It.IsAny<IRestRequest>())).Returns(restResponse); | ||
var restClient = restClientMock.Object; | ||
SetupMock(restClient); | ||
Assert.AreEqual(userId, usersClient.View(userId).user_id); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.