public async Task IndexSuccessWhenLogsFound()
        {
            var logs = new List <UserLog>()
            {
                new UserLog("123", "phrase", TimeSpan.FromSeconds(4), "action")
            };
            var returnList = new List <string>()
            {
                "word1", "word2"
            };

            _userLogServiceMock.GetAllSolverLogs().Returns(logs);
            _searchHistoryServiceMock.GetSearchedAnagrams(Arg.Any <string>()).Returns(returnList);

            var result = await _controller.Index() as ViewResult;

            var data = result.ViewData.Model as List <SearchHistory>;

            await _userLogServiceMock.Received().GetAllSolverLogs();

            await _searchHistoryServiceMock.Received().GetSearchedAnagrams(Arg.Any <string>());

            Assert.AreEqual(logs.Count, data.Count);
            Assert.AreEqual(logs[0].Ip, data[0].Ip);
            Assert.AreEqual(returnList.Count, data[0].Anagrams.Count);
            Assert.AreEqual(returnList[0], data[0].Anagrams[0]);
        }
        public async Task GetAllSolverLogsWhenListIsEmpty()
        {
            _logRepoMock.GetAllAnagramSolveLogs().Returns(new List <UserLogEntity>());

            var result = await _logService.GetAllSolverLogs();

            await _logRepoMock.Received().GetAllAnagramSolveLogs();

            Assert.AreEqual(0, result.Count);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var logs = await _userLogService.GetAllSolverLogs();

                var history = new List <SearchHistory>();
                foreach (var log in logs)
                {
                    var anagrams = await _searchHistoryService.GetSearchedAnagrams(log.SearchPhrase);

                    history.Add(
                        new SearchHistory
                    {
                        Anagrams     = anagrams,
                        Ip           = log.Ip,
                        SearchPhrase = log.SearchPhrase,
                        SearchTime   = log.SearchTime
                    });
                }

                return(View(history));
            }
            catch (Exception ex)
            {
                @ViewData["Error"] = ex.Message;
                return(View());
            }
        }