public async Task ZeroAnagramSolvesLeftForIp() { Settings.MaxAnagramsForIp = 2; _logRepoMock.GetTimesIpMadeAction(Arg.Any <string>(), Arg.Any <UserActionTypes>()).Returns(1, 0, 1, 0); var result = await _logService.CountAnagramsLeftForIpToSolve(); await _logRepoMock.Received(4).GetTimesIpMadeAction(Arg.Any <string>(), Arg.Any <UserActionTypes>()); Assert.AreEqual(0, result); }
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 <IActionResult> Index([Required] string id) { try { if (string.IsNullOrEmpty(id)) { return(View()); } IList <string> anagrams = new List <string>(); var solvesLeft = await _userLogService.CountAnagramsLeftForIpToSolve(); if (solvesLeft <= 0) { throw new Exception("You reached your solve limit. Add new word to increase your limit"); } anagrams = await _searchHistoryService.GetSearchedAnagrams(id); if (anagrams != null && anagrams.Count > 0) { return(View(anagrams)); } Stopwatch sw = new Stopwatch(); sw.Start(); anagrams = await _anagramSolver.GetAnagrams(id); sw.Stop(); await _userLogService.AddLog(sw.Elapsed, UserActionTypes.GetAnagrams, id); //removing input element anagrams.Remove(id); _cookiesHandler.AddCookie(id, string.Join(";", anagrams.ToArray())); await _context.SaveChangesAsync(); return(View(anagrams)); } catch (Exception ex) { @ViewData["Error"] = ex.Message; return(View()); } }