public async Task ValidateUser(NameAndPassword nameAndPassword) { var response = await _httpClient.GetAsync($@"api/users/{nameAndPassword.UserName}/{nameAndPassword.Password}"); if (response.StatusCode == HttpStatusCode.OK) { return; } if (response.StatusCode == HttpStatusCode.Unauthorized) { throw new LogInException(await response.Content.ReadAsAsync <string>()); } throw new HttpRequestException(response.StatusCode + " " + response.ReasonPhrase); }
public async Task PublishPostCommand_TextOnly_PublishesPost() { var nameAndPasswordService = Substitute.For <INameAndPasswordService>(); var nameAndPassword = new NameAndPassword("Francisco Greco", "ElPass"); nameAndPasswordService.NameAndPassword.Returns(nameAndPassword); var newPostText = "The content of the new post"; var postRepository = Substitute.For <IPostRepository>(); var publicationPageViewModel = MakePublicationPageViewModel(postRepository, Substitute.For <INavigation>(), nameAndPasswordService); publicationPageViewModel.PostText = newPostText; await publicationPageViewModel.PublishPost(); await postRepository.Received().PublishPost(Arg.Is <CreatePostDTO>(x => x.Message == newPostText && x.NameAndPassword == nameAndPassword)); }
public async Task <User> GetUserIfValid(NameAndPassword nameAndPassword) { var user = await _missioContext.Users.FirstOrDefaultAsync(x => x.UserName == nameAndPassword.UserName); if (user == null) { throw new InvalidUserNameException(); } var credentials = await _missioContext.UsersCredentials.FirstAsync(x => x.User == user); if (_passwordService.VerifyHashedPassword(credentials.HashedPassword, nameAndPassword.Password) == PasswordVerificationResult.Failed) { throw new InvalidPasswordException(); } return(user); }
/// <inheritdoc /> public async Task <IOrderedEnumerable <IPost> > GetMostRecentPostsInOrder(NameAndPassword nameAndPassword) { var allPosts = new List <IPost>(); var response = await _httpClient.GetAsync($@"api/posts/getFriendsPosts/{nameAndPassword.UserName}/{nameAndPassword.Password}"); if (response.StatusCode == HttpStatusCode.OK) //TODO: Display error when status is not ok! { var posts = await response.Content.ReadAsAsync <List <Post> >(); allPosts.AddRange(posts.OrderByDescending(x => x.PublishedDate)); } response = await _httpClient.GetAsync($@"api/posts/getStickyPosts"); if (response.StatusCode == HttpStatusCode.OK) { allPosts.AddRange(await response.Content.ReadAsAsync <List <StickyPost> >()); } return(allPosts.OrderByDescending(x => x.GetPostPriority())); }
public CreatePostDTO([NotNull] NameAndPassword nameAndPassword, [NotNull] string message, byte[] picture) { NameAndPassword = nameAndPassword ?? throw new ArgumentNullException(nameof(nameAndPassword)); Message = message ?? throw new ArgumentNullException(nameof(message)); Picture = picture; }