· 7 years ago · Jun 13, 2018, 04:28 AM
1[TestMethod]
2[Timeout(5000)]
3public void Login_Success1()
4{
5 var client = new JsonServiceClient("apiurl");
6 var response = client.Login("XXXAccessKeyXXX", "XXXSecretKeyXXX");
7
8 //Assertions
9}
10
11public static class Extensions
12{
13 public static (bool Success, string Message, string Token) Login(this JsonServiceClient client, string accessKey, string secretKey)
14 {
15 try
16 {
17 var response = client.Post(new LoginRequest(accessKey, secretKey));
18 var authorization = response.Headers.GetValues("Authorization")[0];
19 return (true, string.Empty, authorization);
20 }
21 catch (Exception ex)
22 {
23 return (false, $"Authentication failed: {ex.Message}", string.Empty);
24 }
25 }
26}
27
28[Route("/sessions")]
29[DataContract]
30internal class LoginRequest
31{
32 internal LoginRequest(string accessKey, string secretKey)
33 {
34 AccessKey = accessKey ?? throw new ArgumentNullException(nameof(accessKey));
35 SecretKey = secretKey ?? throw new ArgumentNullException(nameof(secretKey));
36 }
37
38 [DataMember(Name = "accessKey")]
39 internal string AccessKey { get; set; }
40
41 [DataMember(Name = "secretKey")]
42 internal string SecretKey { get; set; }
43}