public IActionResult History(History history) { var currentUser = GetCurrentUser(); history.UserId = currentUser.Id; _historyRepository.Add(history); return(CreatedAtAction(nameof(GetHistoryByUser), new { id = history.Id }, history)); }
public void Circular_Add_Test() { var options = Options.Create(new MockerOptions { HistoryLimit = 10 }); var historyRepository = new HistoryRepository(options); for (int j = 0; j < 10; j++) { historyRepository.Clear(); var emptyHistoryItems = historyRepository.Get(); Assert.AreEqual(0, emptyHistoryItems.Count()); for (var i = 0; i < 10; i++) { historyRepository.Add(new HistoryItem { RequestPath = "old" }); var historyItems = historyRepository.Get(); Assert.AreEqual(i + 1, historyItems.Count()); } for (var i = 0; i < 10; i++) { historyRepository.Add(new HistoryItem { RequestPath = "new" }); var historyItems = historyRepository.Get().ToList(); Assert.AreEqual(options.Value.HistoryLimit, historyItems.Count()); Assert.AreEqual(i + 1, historyItems.Count(hi => hi.RequestPath == "new")); Assert.AreEqual(options.Value.HistoryLimit - i - 1, historyItems.Count(hi => hi.RequestPath == "old")); } } }