public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model) { AuthenticatedUser user = null; unitOfWork.DoInTransaction(() => user = userMapper.MapUser(model.AuthenticatedClient) ); string token = tokeniser.CreateToken(user.UserName, user.Id); return(new { Token = token }); }
public void IsPOSTedTo(string url) { Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Tokeniser.CreateToken("username", Command.UserId)); Url = $"https://localhost/api/{url}"; Response = Client.PostAsJsonAsync(Url, Command).Result; Console.WriteLine("POST to {0} with body {1} returned status {2} with reason {3}", url, Serialize(new JsonMediaTypeFormatter(), Command), Response.StatusCode, Response.ReasonPhrase); if (failIfUnsuccessful && !Response.IsSuccessStatusCode) { throw new AssertionException( $"POST call to '{Url}' was not successful, response code is {Response.StatusCode}, reason {Response.ReasonPhrase}"); } }
public void Returns <TResult>(params TResult[] expected) { if (UserId.HasValue) { Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Tokeniser.CreateToken("username", UserId.Value)); } var response = Client.GetAsync($"https://localhost/api/{Url}").Result; if (!response.IsSuccessStatusCode) { throw new AssertionException( $"GET call to '{Url}' was not successful, response code is {response.StatusCode}, reason {response.ReasonPhrase}"); } string getResponseString = response.Content.ReadAsStringAsync().Result; Console.WriteLine("Response for GET {0} is {1}", Url, getResponseString); TResult[] actualResult = JsonConvert.DeserializeObject <TResult[]>(getResponseString); Assert.That(actualResult, Is.EquivalentTo(expected)); }