/// <summary> /// Login with a user and return the token as string. /// </summary> /// <param name="user">A user to login</param> /// <returns>A token as string</returns> private async Task <string> GetToken(ApplicationUser user) { Assert.NotNull(user); Assert.NotNull(user.Email); var body = JsonStringBuilder.LoginJsonBody( user.Email, MockApplicationUsers.UniversalPassword); var content = new StringContent(body); var response = await _endSystems.Post(Routes.AccountRoute + "/login", content); Assert.NotNull(response); var token = JToken.Parse(response.Body).ToString(); Assert.NotNull(token); return(token); }
public async Task Create_NoToken_Unauthorized() { // Arrange var model = MockCreateTodoViewModel.Get(0); var body = JsonStringBuilder.CreateTodoJsonBody(model.Description, model.Due.ToString()); var content = new StringContent(body); const string path = Routes.TodoRoute; // Act var response = await _endSystems.Post(path, content); // Assert Assert.Equal(HttpStatusCode.Unauthorized, response.Code); // Tear down _endSystems.Dispose(); }
public async Task PostAccountLogin_InvalidContentType_UnsupportedMediaType() { // Arrange var content = new StringContent("Home is where I want to be Pick me up and turn me around I feel numb, born with a weak heart I guess I must be having fun"); var path = $"{Routes.AccountRoute}/login"; // Act var response = await _endSystems.Post(path, content, "application/text"); // Assert Assert.Equal(HttpStatusCode.UnsupportedMediaType, response.Code); // Tear down _endSystems.Dispose(); }