public void FollowCommandShouldFollowThatUser() { var userRepo = new Mock <InMemoryRepo <User> >(); var username = "******"; var user = new User(username); userRepo.Object.Add(user); var usernameToFollow = "FollowMe"; var userToFollow = new User(usernameToFollow); userRepo.Object.Add(userToFollow); userRepo.Object.Save(user); var userService = new UserService(userRepo.Object); var followCommand = new FollowCommand(new Receiver(userService)); followCommand.Execute(username, usernameToFollow); var isFollowing = false; foreach (var following in user.Following) { if (following.Username == usernameToFollow) { isFollowing = true; break; } } Assert.True(isFollowing); }
public void GivenAFollowCommandWhenExecuteMethodIsCalledThenItCallsFollowInTheCommandReceiver() { var command = new FollowCommand(this.receiver, AliceUserHandle, BobUserHandle); command.Execute(); this.receiver.Received().Follow(AliceUserHandle, BobUserHandle); }
public void SetCommandResultStatusToErrorOnUnsuccessfulExecution() { var arguments = new List <string> { "alice", "follows" }; var userRepository = new UserRepository(); userRepository.RegisterUser("alice"); var followCommand = new FollowCommand() { Arguments = arguments, UserRepository = userRepository }; var commandResult = followCommand.Execute(); Assert.That(commandResult.Status, Is.EqualTo(CommandResponseStatus.Error)); }
public void ReturnAPayloadContainingAnErrorMessageOnUnsuccessfulExecution() { var arguments = new List <string> { "alice", "follows" }; var userRepository = new UserRepository(); userRepository.RegisterUser("alice"); var followCommand = new FollowCommand() { Arguments = arguments, UserRepository = userRepository }; var commandResult = followCommand.Execute(); Assert.That(commandResult.Payload[0].StartsWith("System.ArgumentOutOfRangeException")); }
public async Task <IActionResult> Follow(string userId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userManager.GetUserAsync(User); try { _followCommand.Execute(userId, user); return(new OkObjectResult(true)); } catch (Exception ex) { return(BadRequest(ex)); } }
public void ReturnAnEmptyPayloadOnSuccessfulExecution() { var arguments = new List <string> { "alice", "follows", "bob" }; var userRepository = new UserRepository(); userRepository.RegisterUser("alice"); var followCommand = new FollowCommand() { Arguments = arguments, UserRepository = userRepository }; var commandResult = followCommand.Execute(); Assert.That(commandResult.Payload, Is.Empty); }
public void AllowAUserToFollowAnotherUserWhenExecuted() { var arguments = new List <string> { "alice", "follows", "bob" }; var userRepository = new UserRepository(); userRepository.RegisterUser("alice"); var followCommand = new FollowCommand() { Arguments = arguments, UserRepository = userRepository }; followCommand.Execute(); Assert.That(userRepository.GetUser("alice").Friends.Count, Is.EqualTo(1)); }
public async void FollowCommand_Execute() { // ARRANGE var user = "******"; var arg = "pippo"; var arguments = new Dictionary <string, string> { { nameof(user), user }, { nameof(arg), arg } }; var storage = new Mock <IStorageProvider>(); var interaction = new Mock <IInteractionProvider>(); interaction.SetupGet(_ => _.IsDebugMode).Returns(true); var command = new FollowCommand(storage.Object, interaction.Object, arguments); // ACT await command.Execute(); // ASSERT storage.Verify(_ => _.AddFollowerToUser(user, arg)); interaction.Verify(_ => _.Warn(Resources.Message_NowFollows, user, arg)); }