File tree Expand file tree Collapse file tree
smsapiTests/Unit/Action/Sendernames Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using SMSApi . Api ;
2+ using smsapi . Api . Response . REST . Exception ;
3+
4+ var client = new ClientOAuth ( "token" ) ;
5+ var features = new Features ( client ) ;
6+
7+ const string newDefaultSender = "new sender2" ;
8+
9+ try
10+ {
11+ features . Sendernames ( )
12+ . ChangeDefault ( newDefaultSender )
13+ . Execute ( ) ;
14+
15+ //default sendername is changed at this point
16+ }
17+ catch ( NotFoundException )
18+ {
19+ Console . WriteLine ( "Sender not found" ) ;
20+ }
21+ catch ( ValidationException ex )
22+ {
23+ foreach ( var validationErrorsError in ex . ValidationErrors . Errors )
24+ Console . WriteLine ( validationErrorsError . Message ) ;
25+ }
Original file line number Diff line number Diff line change 1+ using SMSApi . Api . Response . Sendernames ;
2+
3+ namespace SMSApi . Api . Action . Sendernames ;
4+
5+ public sealed class ChangeDefaultSendername : Action < ChangeDefaultSendernameResult >
6+ {
7+ private string _sender ;
8+
9+ public ChangeDefaultSendername ( string sender )
10+ {
11+ _sender = sender ;
12+ }
13+
14+ protected override RequestMethod Method => RequestMethod . POST ;
15+
16+ protected override ApiType ApiType ( ) => Action . ApiType . Rest ;
17+
18+ protected override ActionContentType ContentType => ActionContentType . Json ;
19+
20+ protected override string Uri ( )
21+ {
22+ return $ "sms/sendernames/{ _sender } /commands/make_default";
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ using SMSApi . Api . Response . ResponseResolver ;
2+
3+ namespace SMSApi . Api . Response . Sendernames ;
4+
5+ public sealed class ChangeDefaultSendernameResult : IResponseCodeAwareResolver
6+ {
7+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,38 @@ public ListSendernames List()
2626
2727 return action ;
2828 }
29+
30+ public CreateSendername Create ( string sender )
31+ {
32+ var action = new CreateSendername ( sender ) ;
33+ action . Proxy ( proxy ) ;
34+
35+ return action ;
36+ }
37+
38+ public GetSendername Get ( string sender )
39+ {
40+ var action = new GetSendername ( sender ) ;
41+ action . Proxy ( proxy ) ;
42+
43+ return action ;
44+ }
45+
46+ public DeleteSendername Delete ( string sender )
47+ {
48+ var action = new DeleteSendername ( sender ) ;
49+ action . Proxy ( proxy ) ;
50+
51+ return action ;
52+ }
53+
54+ public ChangeDefaultSendername ChangeDefault ( string sender )
55+ {
56+ var action = new ChangeDefaultSendername ( sender ) ;
57+ action . Proxy ( proxy ) ;
58+
59+ return action ;
60+ }
2961}
3062
3163public static class SendernamesFeatureRegister
Original file line number Diff line number Diff line change 1+ using System ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
3+ using SMSApi . Api ;
4+ using SMSApi . Api . Action . Sendernames ;
5+
6+ namespace smsapiTests . Unit . Action . Sendernames ;
7+
8+ [ TestClass ]
9+ public class ChangeDefaultSendernameRequestTest
10+ {
11+ private readonly SpyProxy _spyProxy = new ( ) ;
12+ private readonly ProxyAssert _proxyAssert ;
13+
14+ public ChangeDefaultSendernameRequestTest ( )
15+ {
16+ _proxyAssert = new ProxyAssert ( _spyProxy ) ;
17+ }
18+
19+ [ TestMethod ]
20+ public void uri_is_valid ( )
21+ {
22+ var sender = "any sender" ;
23+
24+ Change ( sender ) ;
25+
26+ var encodedSender = Uri . EscapeDataString ( sender ) ;
27+ _proxyAssert . AssertUriEquals ( $ "sms/sendernames/{ encodedSender } /commands/make_default") ;
28+ }
29+
30+ [ TestMethod ]
31+ public void request_method_is_post ( )
32+ {
33+ Change ( ) ;
34+
35+ _proxyAssert . AssertRequestMethod ( RequestMethod . POST ) ;
36+ }
37+
38+ private void Change ( string ? sender = null )
39+ {
40+ var action = new ChangeDefaultSendername ( sender ?? "any" ) ;
41+ action . Proxy ( _spyProxy ) ;
42+ action . Execute ( ) ;
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ using System . Net ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
3+ using SMSApi . Api ;
4+ using SMSApi . Api . Action . Sendernames ;
5+ using smsapiTests . Unit . Fixture ;
6+ using smsapiTests . Unit . Helper ;
7+
8+ namespace smsapiTests . Unit . Action . Sendernames ;
9+
10+ [ TestClass ]
11+ public class ChangeDefaultSendernameResponseTest
12+ {
13+ private readonly ProxyStub _proxyStub = new ( ) ;
14+
15+ [ TestMethod ]
16+ public void successfully_change_default_sendername ( )
17+ {
18+ var sender = "any sender" ;
19+ _proxyStub . SyncExecutionResponse = new HttpResponseEntity (
20+ "" . ToHttpEntityStreamTask ( ) ,
21+ HttpStatusCode . NoContent
22+ ) ;
23+
24+ Change ( sender ) ;
25+
26+ Assert . IsTrue ( true ) ;
27+ }
28+
29+ private void Change ( string ? sender = null )
30+ {
31+ var action = new ChangeDefaultSendername ( sender ?? "any" ) ;
32+ action . Proxy ( _proxyStub ) ;
33+ action . Execute ( ) ;
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments