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 async Task User_Should_Follow_Another_User() { User followerUser = new User((Nickname)"user1", (FullName)"test1 user1", Password.Create("password").Value, (Email)"*****@*****.**", "bio1"); User followedUser = new User((Nickname)"user2", (FullName)"test2 user2", Password.Create("password").Value, (Email)"*****@*****.**", "bio2"); Result followResult; using (var session = _testFixture.OpenSession(_output)) { await session.SaveAsync(followerUser); await session.SaveAsync(followedUser); } var followCommand = new FollowCommand(followerUser.ID, followedUser.Nickname); using (var session = _testFixture.OpenSession(_output)) { var handler = new FollowCommandHandler(session, Log.Logger); followResult = await handler.Handle(followCommand, default); } using (new AssertionScope()) { followResult.IsSuccess.Should().BeTrue(); using (var session = _testFixture.OpenSession(_output)) { (await session.GetAsync <User>(followerUser.ID)).Followed.Count().Should().Be(1); (await session.GetAsync <User>(followedUser.ID)).Followers.Count().Should().Be(1); } } }
public static void Main(string[] args) { var simpleCommand = new SimpleCommand("Vasya"); var simpleKiller = new WatchingKiller("Chikatilo"); PerformKill <ICommand>(simpleKiller, simpleCommand); Console.WriteLine(new string('-', 30)); var followCommand = new FollowCommand("Kolya", "Park"); var followingKiller = new FollowerKiller("Walking Chikatilo"); PerformKill <IFollowCommand>(simpleKiller, followCommand); Console.WriteLine(new string('-', 30)); var murderCommand = new MurderCommand("Kolya", "Park", "Knife"); var murderKiller = new MurderKiller("Potroshitel"); PerformKill <IMurderCommand>(murderKiller, murderCommand); Console.WriteLine(new string('-', 30)); PerformKill <IMurderCommand>(followingKiller, murderCommand); // Console.WriteLine(new string('-', 30)); // PerformKill<IFollowCommand>(murderKiller, followCommand); - error }
public void GivenAFollowCommandWhenExecuteMethodIsCalledThenItCallsFollowInTheCommandReceiver() { var command = new FollowCommand(this.receiver, AliceUserHandle, BobUserHandle); command.Execute(); this.receiver.Received().Follow(AliceUserHandle, BobUserHandle); }
public async Task <IActionResult> Post([FromBody] FollowCommand command) //[FromHeader(Name = "x-requestid")] string requestId)? { bool commandResult = false; commandResult = await _mediator.Send(command); return(commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest()); }
// Start is called before the first frame update public override void Start() { base.Start(); nav = GetComponent <Navigator>(); follow = new FollowCommand(nav.GetController(), 5f, player, 5f); explosion = GetComponent <EnemyExplosion>(); damagableBehaviour.damagable = new SuicideBoxDamagable(this, 10, 0, 0); nav.SetMoveCommand(follow); }
public void FollowCommand_Ctor_ParamValidation() { // ARRANGE var user = "******"; var arg = "pippo"; var storage = new Mock <IStorageProvider>(); var interaction = new Mock <IInteractionProvider>(); // ACT // missing "arg" IDictionary <string, string> arguments = new Dictionary <string, string> { { nameof(user), user } }; ArgumentException ex1 = Assert.Throws <ArgumentException>(() => { var command = new FollowCommand(storage.Object, interaction.Object, arguments); }); // missing "user" arguments = new Dictionary <string, string> { { nameof(arg), arg } }; ArgumentException ex2 = Assert.Throws <ArgumentException>(() => { var command = new FollowCommand(storage.Object, interaction.Object, arguments); }); // missing "storage" ArgumentNullException ex3 = Assert.Throws <ArgumentNullException>(() => { var command = new FollowCommand(null, interaction.Object, arguments); }); // missing "interaction" ArgumentNullException ex4 = Assert.Throws <ArgumentNullException>(() => { var command = new FollowCommand(storage.Object, null, arguments); }); // missing "arguments" ArgumentNullException ex5 = Assert.Throws <ArgumentNullException>(() => { var command = new FollowCommand(storage.Object, interaction.Object, null); }); // ASSERT Assert.Equal("userToFollow", ex1.ParamName); Assert.Equal("user", ex2.ParamName); Assert.Equal("storage", ex3.ParamName); Assert.Equal("interaction", ex4.ParamName); Assert.Equal("arguments", ex5.ParamName); }
public void GivenTargetIsCurrentUser_ThrowsUnprocessableEntityException() { var command = new FollowCommand { Username = Seed.Persons().First().Username, }; async Task Handler() => await SendAsync(command); Assert.ThrowsAsync(typeof(UnprocessableEntityException), Handler); }
public CommandsController( ApplicationDbContext context, HashtagFinder hashtagFinder, IHostingEnvironment appEnvironment, UserManager <ApplicationUser> userManager) { _userManager = userManager; _putLikeCommand = new PutLikeCommand(context); _followCommand = new FollowCommand(context); _createPostCommand = new CreatePostCommand(context, hashtagFinder, appEnvironment); _deletePostCommand = new DeletePostCommand(context, appEnvironment); }
public async Task <IActionResult> Follow(string username) { var command = new FollowCommand { Username = username, }; var response = await Mediator.Send(command); return(CreatedAtAction(nameof(Follow), response)); }
public void GivenTargetDoesNotExist_ThrowsNotFoundException() { var command = new FollowCommand { Username = "******", }; async Task Handler() => await SendAsync(command); Assert.ThrowsAsync(typeof(NotFoundException), Handler); }
public async Task Handle(UserFollowedEvent message, IMessageHandlerContext context) { using (LogContext.PushProperty("IntegrationEventContext", $"{message.Id}-{Program.AppName}")) { _logger.LogInformation("----- Handling UserFollowedEvent: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", message.Id, Program.AppName, message); var command = new FollowCommand { FollowerId = message.FollowerId, FollowedUserId = message.FollowedUserId }; await _mediator.Send(command); } }
public void CreateFrom_GivenAFollowCommand_RecognizesItCorrectly() { // arrange var user = Charlie; var whoToFollow = Alice; var followCommand = $"{user} follows {whoToFollow}"; // act var command = CommandFactory.CreateFrom(followCommand); // assert var expectedCommand = new FollowCommand(user, whoToFollow); command.Should().Be(expectedCommand); }
public async Task <IActionResult> Follow(string id) { var command = new FollowCommand(User.GetIdentifier(), id); var processCommandResult = await _dispatcher.Send(command); if (processCommandResult.IsSuccess) { var newFollowerNotification = new FollowedUserEvent( User.Identity.Name, Url.Action("Profile", "Account", new { id = User.Identity.Name }), id); await _dispatcher.Publish(newFollowerNotification); return(RedirectToAction(nameof(Profile), new { id })); } return(RedirectToAction("Error", "Home")); }
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 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 Task Should_Not_Follow_User_Twice() { User followerUser = new User((Nickname)"user5", (FullName)"test5 user5", Password.Create("password").Value, (Email)"*****@*****.**", "bio5"); User followedUser = new User((Nickname)"user6", (FullName)"test6 user6", Password.Create("password").Value, (Email)"*****@*****.**", "bio6"); Result followResult; using (var session = _testFixture.OpenSession(_output)) { await session.SaveAsync(followerUser); await session.SaveAsync(followedUser); } var followCommand = new FollowCommand(followerUser.ID, followedUser.Nickname); using (var session = _testFixture.OpenSession(_output)) { var handler = new FollowCommandHandler(session, Log.Logger); followResult = await handler.Handle(followCommand, default); } using (var session = _testFixture.OpenSession(_output)) { var handler = new FollowCommandHandler(session, Log.Logger); followResult = await handler.Handle(followCommand, default); } using (new AssertionScope()) { followResult.IsSuccess.Should() .BeFalse($"User [{followedUser.Nickname}] is already followed by user [{followerUser.Nickname}]."); using (var session = _testFixture.OpenSession(_output)) { (await session.GetAsync <User>(followerUser.ID)).Followed.Count().Should().Be(1); (await session.GetAsync <User>(followedUser.ID)).Followers.Count().Should().Be(1); } } }
public async Task Handle(UserFollowedEvent message, IMessageHandlerContext context) { using (LogContext.PushProperty("IntegrationEventContext", $"{message.Id}-{Program.AppName}")) { _logger.LogInformation("----- Handling UserFollowedEvent: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", message.Id, Program.AppName, message); var followCommand = new FollowCommand { FollowerId = message.FollowerId, FollowedUserId = message.FollowedUserId }; await _mediator.Send(followCommand); var fromUser = await _userRepository.GetByIdAsync(message.FollowerId); var eventCommand = new CreateEventCommand { FromUserId = message.FollowerId, ToUserId = message.FollowedUserId, EventType = EventType.Follow, PushMessage = $"{fromUser.Nickname}开始关注你" }; await _mediator.Send(eventCommand); } }
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)); }
private void Follow(FollowCommand followCommand) { _followStore.StoreFollow(followCommand.User, followCommand.WhoToFollow); }