Esempio n. 1
0
        public void GivenAnInvalidComment_AddComment_Returns400BadRequest()
        {
            //Arrange
            var comment = new Comment();

            mockMovieService.Setup(service =>
                                   service.AddComment(It.IsAny <Comment>())).Returns(comment);
            controller = new MovieController(mockMovieService.Object, mockUserService.Object);
            controller.ModelState.AddModelError("", "");

            //Act
            var result = (BadRequestResult)controller.AddComment(comment);

            //Assert
            Assert.Equal(400, result.StatusCode);
        }
Esempio n. 2
0
        public void GivenAValidComment_AddComment_Returns201Created()
        {
            //Arrange
            var comment = new Comment();

            mockMovieService.Setup(service =>
                                   service.AddComment(It.IsAny <Comment>())).Returns(comment);
            controller = new MovieController(mockMovieService.Object, mockUserService.Object);

            //Act
            var result        = (CreatedResult)controller.AddComment(comment);
            var resultComment = (Comment)result.Value;

            //Assert
            Assert.Equal(201, result.StatusCode);
            Assert.Equal(comment, resultComment);
        }
Esempio n. 3
0
        private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            var         message  = messageEventArgs.Message;
            string      username = message.From.Username;
            UserSession session;

            if (!_userSessions.TryGetValue(username, out session))
            {
                session = new UserSession(username);
                _userSessions.Add(username, session);
            }
            session.Message = message;
            if (message == null || message.Type != MessageType.Text)
            {
                return;
            }
            var arguments = message.Text.Split(' ').ToList();

            switch (arguments.First())
            {
            case "/author":
                Bot.SendTextMessageAsync(message.Chat.Id, "Frédéric Korradi, Simon Flückiger, Simon Jobin");
                break;

            case "/repo":
                Bot.SendTextMessageAsync(message.Chat.Id, "https://github.com/korradif/heigmac");
                break;

            case "/addFriend":
                if (arguments.Count == 2)
                {
                    Bot.SendTextMessageAsync(message.Chat.Id, "Adding " + arguments[1].Substring(1) + " as a friend to " + message.From.Username);
                    _movieController.AddFriend(message.From.Username, arguments[1].Substring(1));
                }
                break;

            case "/getFriends":
                List <string> friends = _movieController.GetFriends(username);
                DisplayFriends(friends, session);
                break;

            case "/getMovie":
                await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);

                session.Step = Step.ChooseFilter;
                var inlineKeyboard = new InlineKeyboardMarkup(new[]
                {
                    new []     // first row
                    {
                        InlineKeyboardButton.WithCallbackData("Name"),
                        InlineKeyboardButton.WithCallbackData("Cast"),
                        InlineKeyboardButton.WithCallbackData("Crew"),
                    },
                    new []     // second row
                    {
                        InlineKeyboardButton.WithCallbackData("Genres"),
                        InlineKeyboardButton.WithCallbackData("Year"),
                        InlineKeyboardButton.WithCallbackData("Language"),
                    }
                });

                await Bot.SendTextMessageAsync(
                    message.Chat.Id,
                    "Choose",
                    replyMarkup : inlineKeyboard);

                break;

            default:
                switch (session.Step)
                {
                case Step.InputFilterValue:
                    session.FilterValue = arguments[0].Substring(1);
                    displayFilteredMovies(session);
                    break;

                case Step.CommentMovie:
                    string comment2 = arguments[0].Substring(1);
                    for (int i = 1; i < arguments.Count; ++i)
                    {
                        comment2 += " " + arguments[i];
                    }
                    Bot.SendTextMessageAsync(message.Chat.Id, "Adding " + comment2 + " as a comment to " + session.SelectedMovie + " from user " + message.From.Username);
                    _movieController.AddComment(message.From.Username, session.SelectedMovie, comment2);
                    session.Step = Step.Default;
                    break;

                case Step.RateMovie:
                    bool parsedSucessfully = Double.TryParse(arguments[0].Substring(1).Replace('.', ','), out double rate);
                    if (parsedSucessfully)
                    {
                        _movieController.AddRate(username, session.SelectedMovie, rate);
                        Bot.SendTextMessageAsync(message.Chat.Id, "Adding " + rate + " as a mark to " + session.SelectedMovie + " from user " + message.From.Username);
                        session.Step = Step.Default;
                    }
                    else
                    {
                        Bot.SendTextMessageAsync(message.Chat.Id, "Please enter a valid rate");
                    }
                    break;

                default:
                    const string usage = @"
Usage:
/author   - display authors name
/getMovie - get the Movie (various filters)
/addFriend [username] - add an user as a friend
/getFriends - display friends list
";

                    await Bot.SendTextMessageAsync(
                        message.Chat.Id,
                        usage,
                        replyMarkup : new ReplyKeyboardRemove());

                    break;
                }
                break;
            }
        }