public void WallCommand_ShouldReturnAllTweets() { var username = "******"; var user = new User(username) { Tweets = new List <Tweet>() }; user.Tweets.Add(new Tweet("This tweet is my first tweet.")); var username2 = "ExistingUser2"; var user2 = new User(username2) { Tweets = new List <Tweet>() }; user2.Tweets.Add(new Tweet("This is second user's tweet.")); user.Following = new List <User> { user2 }; var userRepo = new Mock <IRepository <User> >(); userRepo.SetupGet(u => u.Entities).Returns(new List <User> { user, user2 }); var userService = new UserService(userRepo.Object); var wallCommand = new WallCommand(new Receiver(userService)); var actual = wallCommand.Execute(username, string.Empty); Assert.Equal(2, actual.Count); }
public void GivenAWallCommandWhenExecuteMethodIsCalledThenItCallsWallInTheCommandReceiver() { var command = new WallCommand(this.receiver, BobUserHandle); command.Execute(); this.receiver.Received().Wall(BobUserHandle); }
public void GivenAWallCommandWhenExecuteMethodIsCalledThenItStoresTheExecutionResultInResults() { var command = new WallCommand(this.receiver, BobUserHandle); this.receiver.Wall(BobUserHandle).Returns(new[] { new Message(null, PostMessageText) }); command.Execute(); ((IQueryCommand)command).Results.Should().Contain(m => m.Body == PostMessageText); }
public void ReturnAPayloadContainingAnErrorMessageOnUnsuccessfulExecution() { var arguments = new List <string> { "alice", "wall" }; var emptyUserRepository = new UserRepository(); var wallCommand = new WallCommand() { Arguments = arguments, UserRepository = emptyUserRepository }; var commandResult = wallCommand.Execute(); Assert.That(commandResult.Payload[0].StartsWith("System.NullReferenceException")); }
public void SetCommandResultStatusToErrorOnUnsuccessfulExecution() { var arguments = new List <string> { "alice", "wall" }; var emptyUserRepository = new UserRepository(); var wallCommand = new WallCommand() { Arguments = arguments, UserRepository = emptyUserRepository }; var commandResult = wallCommand.Execute(); Assert.That(commandResult.Status, Is.EqualTo(CommandResponseStatus.Error)); }
public async void WallCommand_Execute() { // ARRANGE var user = "******"; var arguments = new Dictionary <string, string> { { nameof(user), user } }; var storage = new Mock <IStorageProvider>(); var posts = new Post[] { new Post { Author = "andrea", Message = "message1", Time = new DateTime(1970, 1, 1, 0, 0, 1) }, new Post { Author = "andrea", Message = "message2", Time = new DateTime(1970, 1, 1, 0, 0, 2) }, new Post { Author = "andrea", Message = "message3", Time = new DateTime(1970, 1, 1, 0, 0, 3) } }; storage.Setup(_ => _.GetWallByUser(user)).Returns( Task.FromResult <IEnumerable <Post> >(posts)); var interaction = new Mock <IInteractionProvider>(); var time = new Mock <ITimeProvider>(); var command = new WallCommand(storage.Object, interaction.Object, time.Object, arguments); // ACT await command.Execute(); // ASSERT storage.Verify(_ => _.GetWallByUser(user)); interaction.Verify(_ => _.Write( Resources.Message_WallFormat, user, It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(posts.Length)); }
public void SetCommandResultStatusToOkOnSuccessfulExecution() { var arguments = new List <string> { "alice", "wall" }; var userRepository = new UserRepository(); userRepository.RegisterUser("alice"); var wallCommand = new WallCommand() { Arguments = arguments, UserRepository = userRepository }; var commandResult = wallCommand.Execute(); Assert.That(commandResult.Status, Is.EqualTo(CommandResponseStatus.Ok)); }
public void ReturnAllPostsOnAUsersWallInPayloadWhenSuccessfullyExecuted() { var userRepository = new UserRepository(); var user = userRepository.RegisterUser("alice"); user.Friends.Add(new User("bob") { Posts = new List <Post> { new Post("test1"), new Post("test2") } }); user.Friends.Add(new User("colin") { Posts = new List <Post> { new Post("test3") } }); var arguments = new List <string> { "alice", "wall" }; var wallCommand = new WallCommand() { Arguments = arguments, UserRepository = userRepository }; var commandResult = wallCommand.Execute(); Assert.That(commandResult.Payload.Count, Is.EqualTo(3)); Assert.That(commandResult.Payload[0], Is.EqualTo("bob - test1 (0 seconds ago)")); Assert.That(commandResult.Payload[1], Is.EqualTo("bob - test2 (0 seconds ago)")); Assert.That(commandResult.Payload[2], Is.EqualTo("colin - test3 (0 seconds ago)")); }