public void AddingToWishlist_Negative() { WishList wishReceived = new WishList(); wishReceived.WishListId = 1; wishReceived.RenterId = 2; wishReceived.RoomId = 4; WishListDuplicate wishListDuplicate = new WishListDuplicate(); wishListDuplicate.WishListId = 1; wishListDuplicate.RenterId = 2; wishListDuplicate.RoomId = 4; List <WishListDuplicate> returnedWishlist = new List <WishListDuplicate>(); returnedWishlist.Add(wishListDuplicate); //Arrange var _mockDataService = new Mock <BookingService>(); _mockDataService.Setup(p => p.AddingToWishList(wishReceived)).Throws <System.Exception>(); var _bookingManager = new BookingManager(_mockDataService.Object); try { var responseReturned = _bookingManager.AddingToWishList(wishReceived); Assert.IsTrue(false); } catch { Assert.IsTrue(true); } }
// public IActionResult PostWishList(WishList wishListReceived) public IActionResult PostWishList(WishListToReceive wishListReceived) { //BookingManager bookingManager = new BookingManager(); WishList wishListToBeAdded = new WishList(); wishListToBeAdded.RenterId = wishListReceived.RenterId; wishListToBeAdded.RoomId = wishListReceived.RoomId; Acknowledgement <WishListDuplicate> returnData = new Acknowledgement <WishListDuplicate>(); //to avoid nulls that r present due to foreign key in model class "wishlist" we are using generic for duplicate wishlist. if (!ModelState.IsValid) { returnData = search.WhenErrorOccurs("", type: "modelState"); //this will call a method in bookingManager return(Ok(returnData)); } try { returnData = search.AddingToWishList(wishListToBeAdded); } catch (AlreadyThereInWishList alreadyThere) { returnData = search.WhenErrorOccurs(alreadyThere.Message, type: "post"); //this will call a overloaded method in bookingManager return(Ok(returnData)); } catch (SqlException) { returnData = search.WhenErrorOccurs("", type: "post"); //this will call a overloaded method in bookingManager return(Ok(returnData)); } catch (Exception) { returnData = search.WhenErrorOccurs("", type: "post"); return(Ok(returnData)); } return(Ok(returnData)); }