public void GenerateUserLogReport_ShouldGenerateCorrectUserLogReport() { userLogRepository.GetUserLogReport().Returns(new List <UserLogReport> { new UserLogReport { UserIp = "107.0.0.1", SearchTime = new DateTime(2019, 7, 19), Word = "dangus", Anagrams = new List <string> { "dugnas" } }, new UserLogReport { UserIp = "107.0.0.1", SearchTime = new DateTime(2019, 7, 19), Word = "dangus", Anagrams = new List <string> { "gandus" } } }); List <string> expected = new List <string> { "dugnas", "gandus" }; var result = userLogService.GenerateUserLogReport(); Assert.IsNotNull(result); Assert.AreEqual(expected, result.First().Anagrams); userLogRepository.Received().GetUserLogReport(); }
public List <UserLogReport> GenerateUserLogReport() { bool added = false; List <UserLogReport> userLogReports = new List <UserLogReport>(); var tempUserLogReport = userLogRepository.GetUserLogReport(); foreach (var tempUserLog in tempUserLogReport) { added = false; UserLogReport reportToAdd = new UserLogReport(); reportToAdd.UserIp = tempUserLog.UserIp; reportToAdd.SearchTime = tempUserLog.SearchTime; reportToAdd.Word = tempUserLog.Word; foreach (var logReport in userLogReports) { if (logReport.UserIp == reportToAdd.UserIp && logReport.SearchTime == reportToAdd.SearchTime) { logReport.Anagrams.Add(tempUserLog.Anagrams[0]); added = true; break; } } if (!added) { reportToAdd.Anagrams = tempUserLog.Anagrams; userLogReports.Add(reportToAdd); } } return(userLogReports); }