Example #1
0
        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 ExecuteWallCommand_When_Users_Exists_Returns_Posts()
        {
            //arrange
            var mockRepository = new Mock <IUserRepository>();
            var currentUser    = new User(Username);
            var userToFollow   = new User(UsernameToFollow);

            currentUser.FollowingUsers.Add(UsernameToFollow);
            currentUser.Posts.Add(new Post(Username, Message, new PublishedTimer()));
            userToFollow.Posts.Add(new Post(UsernameToFollow, Message2, new PublishedTimer()));

            mockRepository.Setup(m => m.GetUser(It.IsAny <string>()))
            .Returns(() => currentUser);
            mockRepository.Setup(m => m.GetUser(It.IsAny <string>()))
            .Returns(() => userToFollow);

            //act
            var wallCommand = new WallCommand(mockRepository.Object);

            wallCommand.ExecuteCommand(CommandLine);
            var postForUser         = currentUser.Posts.Select(m => m.Message).FirstOrDefault();
            var postForFollowedUser = userToFollow.Posts.Select(m => m.Message).FirstOrDefault();

            //assert
            Assert.AreEqual(Message, postForUser);
            Assert.AreEqual(Message2, postForFollowedUser);
        }
        public void GivenAWallCommandWhenExecuteMethodIsCalledThenItCallsWallInTheCommandReceiver()
        {
            var command = new WallCommand(this.receiver, BobUserHandle);

            command.Execute();

            this.receiver.Received().Wall(BobUserHandle);
        }
        public void Matches_WallCommand_Returns_True()
        {
            var  mockRepository = new Mock <IUserRepository>();
            var  wallCommand    = new WallCommand(mockRepository.Object);
            bool result         = wallCommand.Matches(CommandLine);

            Assert.IsTrue(result);
        }
Example #5
0
        public void GivenAWallCommandWhenCreateFormaterForCommandIsInvokedOnFactoryThenItReturnsAWallMessageFromater()
        {
            var command = new WallCommand(this.brokerMock, BobUserHandle);
            var factory = new MessageFormaterFactory();

            var formater = factory.CreateFormaterForCommand(command);

            formater.Should().BeAssignableTo <WallMessageFormater>();
        }
        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);
        }
Example #7
0
 public int Post(int owner_id, string message)
 {
     NameValueCollection Params = new NameValueCollection();
     string CommandName;
     Params.Add("owner_id", owner_id.ToString());
     Params.Add("message", message);
     Params.Add("fields", "owner_id,message");
     CommandName = "wall.post";
     var command = new WallCommand(CommandName, Params);
     command.ExecuteCommand();
     return command.GetPostAnswer();
 }
Example #8
0
        public void WallCommand_Ctor_ParamValidation()
        {
            // ARRANGE
            var storage     = new Mock <IStorageProvider>();
            var interaction = new Mock <IInteractionProvider>();
            var time        = new Mock <ITimeProvider>();

            // ACT

            // missing "arg"
            IDictionary <string, string> arguments = new Dictionary <string, string> {
            };

            ArgumentException ex1 = Assert.Throws <ArgumentException>(() =>
            {
                var command = new WallCommand(storage.Object, interaction.Object, time.Object, arguments);
            });

            // missing "storage"
            ArgumentNullException ex2 = Assert.Throws <ArgumentNullException>(() =>
            {
                var command = new WallCommand(null, interaction.Object, time.Object, arguments);
            });

            // missing "interaction"
            ArgumentNullException ex3 = Assert.Throws <ArgumentNullException>(() =>
            {
                var command = new WallCommand(storage.Object, null, time.Object, arguments);
            });

            // missing "time"
            ArgumentNullException ex4 = Assert.Throws <ArgumentNullException>(() =>
            {
                var command = new WallCommand(storage.Object, interaction.Object, null, arguments);
            });

            // missing "arguments"
            ArgumentNullException ex5 = Assert.Throws <ArgumentNullException>(() =>
            {
                var command = new WallCommand(storage.Object, interaction.Object, time.Object, null);
            });

            // ASSERT
            Assert.Equal("user", ex1.ParamName);
            Assert.Equal("storage", ex2.ParamName);
            Assert.Equal("interaction", ex3.ParamName);
            Assert.Equal("time", ex4.ParamName);
            Assert.Equal("arguments", ex5.ParamName);
        }
        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));
        }
Example #11
0
        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));
        }
Example #13
0
        public int Post(int owner_id, string message, string attachment, string captcha_sid, string captcha_key)
        {
            NameValueCollection Params = new NameValueCollection();
            string CommandName;
            Params.Add("owner_id", owner_id.ToString());
            Params.Add("message", message);

            string added = string.Empty;

            CommandHelper.AddIfExict(Params, "attachment", Uri.EscapeUriString(attachment), ref added);
            if (CommandHelper.IsExist(added))
            {
                var res = CommandHelper.AddIfExict(Params, "captcha_sid", captcha_sid, ref added);
                if (res)
                    CommandHelper.AddIfExict(Params, "captcha_key", captcha_key, ref added);
            }

            Params.Add("fields", "owner_id,message"+ added);
            CommandName = "wall.post";
            var command = new WallCommand(CommandName, Params);
            command.ExecuteCommand();
            return command.GetPostAnswer();
        }
        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)"));
        }
Example #15
0
 public bool Equals(WallCommand obj)
 {
     return base.Equals(obj) &&
         this.User == obj.User;
 }