public void GenerateAuthTokenTest() { var payload = new AuthPayload() { UserId = 0, Email = "*****@*****.**", FirstName = "Test", LastName = "Test", DateTime = default(DateTime) }; var token = AuthHelper.GenerateAuthToken(payload); Assert.Equal("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjAsIkVtYWlsIjoiVGVzdEB0ZXN0LmNvbSIsIkZpcnN0TmFtZSI6IlRlc3QiLCJMYXN0TmFtZSI6IlRlc3QiLCJEYXRlVGltZSI6IjAwMDEtMDEtMDFUMDA6MDA6MDAifQ.NnHFVebJTMQ7xqx4s33CMpds1mEIIkgAyuebGbK5_2g", token); }
public static AuthResponsePayload PostAuth(AuthPayload payload) { try { string requestBody = JsonConvert.SerializeObject(payload); using (HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri("https://restful-booker.herokuapp.com/auth"), Method = HttpMethod.Post }) { request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json"); var response = _httpClient.SendAsync(request).Result; var responseString = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <AuthResponsePayload>(responseString)); } } catch (Exception e) { Console.WriteLine("Exception caught: " + e); return(null); } }