public async Task IndexSuccessWhenSearchingDBForResult() { var returnList = new List <string>() { "word1", "word2" }; _userLogServiceMock.CountAnagramsLeftForIpToSolve().Returns(5); _searchHistoryServiceMock.GetSearchedAnagrams(Arg.Any <string>()).Returns((List <string>)null); _anagramSolverMock.GetAnagrams(Arg.Any <string>()).Returns(returnList); await _userLogServiceMock.AddLog(Arg.Any <TimeSpan>(), Arg.Any <UserActionTypes>(), Arg.Any <string>()); _cookiesHandlerServiceMock.AddCookie(Arg.Any <string>(), Arg.Any <string>()); await _contextMock.SaveChangesAsync(); var result = await _controller.Index("labas") as ViewResult; var data = result.ViewData.Model as List <string>; await _userLogServiceMock.Received().CountAnagramsLeftForIpToSolve(); await _searchHistoryServiceMock.Received().GetSearchedAnagrams(Arg.Any <string>()); await _anagramSolverMock.Received().GetAnagrams(Arg.Any <string>()); await _userLogServiceMock.Received().AddLog(Arg.Any <TimeSpan>(), Arg.Any <UserActionTypes>(), Arg.Any <string>()); _cookiesHandlerServiceMock.Received().AddCookie(Arg.Any <string>(), Arg.Any <string>()); await _contextMock.Received().SaveChangesAsync(); Assert.AreEqual(returnList.Count, data.Count); Assert.AreEqual(returnList[0], data[0]); Assert.AreEqual(returnList[1], data[1]); }
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); }