-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
963297d
commit 4c0c1a2
Showing
4 changed files
with
152 additions
and
0 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,19 @@ | ||
using SMSApi.Api.Response.Subusers; | ||
|
||
namespace SMSApi.Api.Action.Subusers; | ||
|
||
public class GetSubuser : Action<SubuserDetails> | ||
{ | ||
private readonly string _userId; | ||
|
||
public GetSubuser(string userId) | ||
{ | ||
_userId = userId; | ||
} | ||
|
||
protected override RequestMethod Method => RequestMethod.GET; | ||
|
||
protected override string Uri() => $"subusers/{_userId}"; | ||
|
||
protected override ApiType ApiType() => Action.ApiType.Rest; | ||
} |
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
81 changes: 81 additions & 0 deletions
81
smsapiTests/Unit/Action/Subusers/GetSubuserResponseTest.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,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using SMSApi.Api; | ||
using SMSApi.Api.Action.Subusers; | ||
using smsapi.Api.Response.REST.Exception; | ||
using SMSApi.Api.Response.Subusers; | ||
using smsapiTests.Unit.Fixture; | ||
using smsapiTests.Unit.Helper; | ||
|
||
namespace smsapiTests.Unit.Action.Subusers; | ||
|
||
[TestClass] | ||
public class GetSubuserResponseTest | ||
{ | ||
private readonly ProxyStub _proxyStub = new(); | ||
|
||
[TestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public void get_subuser(bool active) | ||
{ | ||
var id = "655B26893332330011B0B297"; | ||
var username = "subuser_name"; | ||
var description = "any description"; | ||
var fromAccountPoints = Random.Shared.NextDouble(); | ||
var perMonthPoints = Random.Shared.NextDouble(); | ||
var response = | ||
new Dictionary<string, dynamic> | ||
{ | ||
{ "id", id }, | ||
{ "username", username }, | ||
{ "active", active }, | ||
{ "description", description }, | ||
{ | ||
"points", new Dictionary<string, double> | ||
{ | ||
{ "from_account", fromAccountPoints }, | ||
{ "per_month", perMonthPoints } | ||
} | ||
} | ||
}; | ||
_proxyStub.SyncExecutionResponse = new HttpResponseEntity( | ||
response.ToHttpEntityStreamTask(), | ||
HttpStatusCode.OK | ||
); | ||
|
||
var result = GetSubuser(); | ||
|
||
Assert.AreEqual(id, result.Id); | ||
Assert.AreEqual(username, result.Username); | ||
Assert.AreEqual(active, result.Active); | ||
Assert.AreEqual(description, result.Description); | ||
Assert.AreEqual(new UserPoints(fromAccountPoints, perMonthPoints), result.Points); | ||
} | ||
|
||
[TestMethod] | ||
public void map_http_404_to_not_found_exception() | ||
{ | ||
_proxyStub.SyncExecutionResponse = new HttpResponseEntity( | ||
DictionaryToStreamHelper.EmptyStream, | ||
HttpStatusCode.NotFound | ||
); | ||
|
||
var result = () => | ||
{ | ||
GetSubuser(); | ||
}; | ||
|
||
Assert.ThrowsException<NotFoundException>(result); | ||
} | ||
|
||
private SubuserDetails GetSubuser() | ||
{ | ||
var action = new GetSubuser("any"); | ||
action.Proxy(_proxyStub); | ||
|
||
return action.Execute(); | ||
} | ||
} |
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,43 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using SMSApi.Api; | ||
using SMSApi.Api.Action.Subusers; | ||
|
||
namespace smsapiTests.Unit.Action.Subusers; | ||
|
||
[TestClass] | ||
public class GetSubuserTest | ||
{ | ||
private readonly ProxyAssert _proxyAssert; | ||
private readonly SpyProxy _spyProxy = new(); | ||
|
||
public GetSubuserTest() | ||
{ | ||
_proxyAssert = new ProxyAssert(_spyProxy); | ||
} | ||
|
||
[TestMethod] | ||
public void use_get_request_method() | ||
{ | ||
GetSubuser().Execute(); | ||
|
||
_proxyAssert.AssertRequestMethod(RequestMethod.GET); | ||
} | ||
|
||
[TestMethod] | ||
public void request_proper_uri() | ||
{ | ||
var userId = "1238f47da26ee45dc41fb987"; | ||
|
||
GetSubuser(userId).Execute(); | ||
|
||
_proxyAssert.AssertUriEquals($"subusers/{userId}"); | ||
} | ||
|
||
private GetSubuser GetSubuser(string id = "any") | ||
{ | ||
var action = new GetSubuser(id); | ||
action.Proxy(_spyProxy); | ||
|
||
return action; | ||
} | ||
} |