Ejemplo n.º 1
0
        public void UpdateUserWord_UpdatesExistingWordInUserWordsRepository()
        {
            _usersRepository.GetUsers().Returns(new List <User>
            {
                new User {
                    Id = 1, Ip = "::1", SearchesLeft = 5
                },
                new User {
                    Id = 2, Ip = "::2", SearchesLeft = 4
                },
                new User {
                    Id = 3, Ip = "::3", SearchesLeft = 3
                },
                new User {
                    Id = 4, Ip = "::4", SearchesLeft = 2
                }
            });

            var testUser = _usersRepository.GetUsers().First();
            var testWord = new UserWord {
                Id = 1, UserId = 1, Text = "Unit"
            };
            var updateText = "updateText";

            _userWordsService.UpdateUserWord(testWord.Id, updateText, testUser.Ip);

            _usersRepository.ReceivedCalls().ShouldNotBeNull();
            _userWordsRepository.ReceivedCalls().ShouldNotBeNull();
            _userWordsRepository.Received(1).UpdateUserWord(Arg.Is(testWord.Id), Arg.Is(updateText));
            _usersRepository.Received(2).GetUsers();
        }
Ejemplo n.º 2
0
        public IActionResult Change(int wordId, string word)
        {
            try
            {
                var ipAddress = HttpContext.Connection.RemoteIpAddress.ToString();
                _userWordsService.UpdateUserWord(wordId, word, ipAddress);
            }
            catch
            {
                return(NoContent());
            }

            return(Redirect($"/userWords?pageSize=100"));
        }
Ejemplo n.º 3
0
        public ActionResult UpdateUserWord([FromBody] UserWord word)
        {
            if (word.Id < 0 || String.IsNullOrWhiteSpace(word.Text))
            {
                return(NotFound(new { errorMessage = $"word with id of {word.Id} could not be found" }));
            }

            try
            {
                var ipAddress = HttpContext.Connection.RemoteIpAddress.ToString();
                _userWordsService.UpdateUserWord(word.Id, word.Text, ipAddress);
            }
            catch
            {
                return(NotFound(new { errorMessage = $"word with id of {word.Id} could not be found" }));
            }

            return(Ok());
        }