public async Task GetUnreturnedBorrowsAsync_getsOnlyOneCorrectBorrow() { // Arrange: var service = new BorrowService(Context, _mapper); // Act: var unreturnedBoxId1 = await service.GetUnreturnedBorrowsAsync(3); var unreturnedBoxId2 = await service.GetUnreturnedBorrowsAsync(1); // Assert: Assert.True(unreturnedBoxId1.Count() == 1); Assert.True(unreturnedBoxId1.Any() == true); Assert.True(unreturnedBoxId1.First().Box.Game.Title == "TestGame3"); Assert.True(unreturnedBoxId2.Count() == 0); Assert.True(unreturnedBoxId2.Any() == false); }
public async Task <IActionResult> OnPostAsync() { var borrowsToReturn = await _borrowService.GetUnreturnedBorrowsAsync(BoxId); // there should be only one entity if (!borrowsToReturn.Any()) { ToastMessage = _locService.GetLocalizedString("Game already returned or wrong game code!"); ToastType = "warning"; return(RedirectToPage("./Return")); } if (borrowsToReturn.Count() != 1) // it should be impossible (there should be only one entity) { ToastMessage = _locService.GetLocalizedString("Impossible error! Please tell about it to Paweł in gamesroom - he will be very upset:-("); ToastType = "error"; return(Page()); } var borrowToMarkAsReturned = borrowsToReturn.First(); borrowToMarkAsReturned.Returned = true; borrowToMarkAsReturned.ReturnTime = DateTime.UtcNow; try { await _borrowService.MarkAsReturnedAsync(borrowToMarkAsReturned); ToastMessage = _locService.GetLocalizedString("Game returned"); ToastType = "success"; return(RedirectToPage("./Return")); } catch { ToastMessage = _locService.GetLocalizedString("Error! Please try again!"); ToastType = "error"; return(Page()); } }