public void TestDeleteHotelByHotelId_Success_True() { //Arrange int id = 1; string userName = "******"; var hotel = new Hotel() { Id = id, IsActive = true, IsDeleted = false }; var baseResult = new BaseResult <List <Hotel> >() { Result = new List <Hotel>() { hotel } }; var pred = new Func <Hotel, bool>(x => x.Id == id && x.IsDeleted == false); iHotelLibrary.Setup(a => a.GetListByPredicate(It.Is <Func <Hotel, bool> >(x => x.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)); iHotelLibrary.Setup(a => a.UpdateEntityByDapper(It.IsAny <Hotel>())).Returns(Task.FromResult(new BaseResult <bool> { Result = true })); //Act var result = hotelRepository.DeleteHotelByHotelId(id, userName); //Assert Assert.IsTrue(result.Result is BaseResult <bool>); Assert.IsTrue(result.Result.Result == true); }
public async Task <IActionResult> DeleteHotelByHotelId([FromBody] int hotelId) { BaseResult <bool> hotelResult = new BaseResult <bool>(); if (hotelId <= default(int)) { hotelResult.IsError = true; hotelResult.Message = string.Format(coreHelper.Constants.ErrorMessage.InvalidId); return(BadRequest(hotelResult)); } string userName = base.LoggedInUserName; hotelResult = await iHotel.DeleteHotelByHotelId(hotelId, userName).ConfigureAwait(false); if (hotelResult.Message != null) { return(BadRequest(hotelResult)); } if (hotelResult.IsError || hotelResult.ExceptionMessage != null || hotelResult.Result == default(bool)) { return(StatusCode(500, hotelResult)); } return(Ok(hotelResult)); }