public async Task IsBoxRentedAsync_saysTrueAboutIt() { // Arrange: var service = new BorrowService(Context, _mapper); // Act: var shouldBeTrue1 = await service.IsBoxRentedAsync(3); var shouldBeFalse1 = await service.IsBoxRentedAsync(1); var shouldBeTrue2 = await service.IsBoxRentedAsync(4); var shouldBeFalse2 = await service.IsBoxRentedAsync(9999); // Assert: Assert.True(shouldBeTrue1 == true); Assert.True(shouldBeTrue2 == true); Assert.True(shouldBeFalse1 == false); Assert.True(shouldBeFalse2 == false); }
public async Task <IActionResult> OnPostAsync() { var borrowToRegister = new BorrowDTO(); var doesPlayerExist = await _playerService.DoesPlayerExistAsync(Borrow.PlayerId); var doesBoxExist = await _boxService.DoesBoxExistAsync(Borrow.BoxId); var boxIsRented = await _borrowService.IsBoxRentedAsync(Borrow.BoxId); if (!doesPlayerExist && !doesBoxExist) { ToastMessage = _locService.GetLocalizedString("Both codes are unregistered!"); ToastType = "error"; return(Page()); } else if (!doesPlayerExist) { ToastMessage = _locService.GetLocalizedString("Player with that code is not registered!"); ToastType = "error"; return(Page()); } else if (!doesBoxExist) { ToastMessage = _locService.GetLocalizedString("Game (box) with that code is not registered!"); ToastType = "error"; return(Page()); } if (boxIsRented) { ToastMessage = _locService.GetLocalizedString("Game (box) already marked as rented. Check the code!"); ToastType = "error"; return(Page()); } if (await TryUpdateModelAsync <BorrowDTO>( borrowToRegister, "borrow", r => r.PlayerId, r => r.BoxId)) { borrowToRegister.BorrowTime = DateTime.UtcNow; await _borrowService.AddBorrowAsync(borrowToRegister); ToastMessage = _locService.GetLocalizedString("Record added"); ToastType = "success"; return(RedirectToPage("./Lend")); } ToastMessage = _locService.GetLocalizedString("Error! Please try again!"); ToastType = "error"; return(Page()); }