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]);
        }
Exemplo n.º 2
0
        public async Task IndexFailedWhenNoSolvesLeftForIp()
        {
            _userLogServiceMock.CountAnagramsLeftForIpToSolve().Returns(0);

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

            var data = result.ViewData.Values;

            await _userLogServiceMock.Received().CountAnagramsLeftForIpToSolve();

            Assert.AreEqual(1, data.Count);
        }
        public async Task CreateSuccessWhenAllMandatoryFieldsFilled()
        {
            _cookiesHandlerServiceMock.ClearAllCookies();
            await _wordServiceMock.InsertWord(Arg.Any <Anagram>());

            await _userLogServiceMock.AddLog(Arg.Any <TimeSpan>(), Arg.Any <UserActionTypes>());

            await _contextMock.SaveChangesAsync();

            var result = await _controller.Create(_anagram) as RedirectToActionResult;

            _cookiesHandlerServiceMock.Received().ClearAllCookies();
            await _wordServiceMock.Received().InsertWord(Arg.Any <Anagram>());

            await _userLogServiceMock.Received().AddLog(Arg.Any <TimeSpan>(), Arg.Any <UserActionTypes>());

            await _contextMock.Received().SaveChangesAsync();

            Assert.AreEqual("Index", result.ActionName);
        }
        public void UserLogs_ShouldReturnAView()
        {
            userLogService.GenerateUserLogReport().Returns(new List <UserLogReport> {
                new UserLogReport
                {
                    UserIp     = "107.0.0.1",
                    SearchTime = new DateTime(2019, 7, 19),
                    Word       = "dangus",
                    Anagrams   = new List <string> {
                        "dugnas"
                    }
                }
            });

            var result = homeController.UserLogs();

            Assert.IsInstanceOf <ViewResult>(result);

            userLogService.Received().GenerateUserLogReport();
        }