public void DeleteFromWishList_Negative()
        {
            int renterId = 2;

            WishListDuplicate wishListDuplicateReceieved = new WishListDuplicate
            {
                RenterId = 2,
                RoomId   = 3
            };
            Acknowledgement <WishListDuplicate> wishlistAcknowledgement = new Acknowledgement <WishListDuplicate>();

            wishlistAcknowledgement.code    = 0;
            wishlistAcknowledgement.Set     = null;
            wishlistAcknowledgement.Message = "fail";


            //Arrange
            var _mockDataService = new Mock <BookingService>();


            _mockDataService.Setup(p => p.RemoveFromWishList(wishListDuplicateReceieved)).Throws <System.Exception>();

            var _bookingManager = new BookingManager(_mockDataService.Object);

            try
            {
                var responseReturned = _bookingManager.DeleteFromWishList(wishListDuplicateReceieved);
                Assert.IsTrue(false);
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }
예제 #2
0
        public IActionResult RemoveFromWishList(WishListToReceive wishListReceived)
        {
            //BookingManager bookingManager = new BookingManager();

            WishListDuplicate wishListToBeRemoved = new WishListDuplicate();

            wishListToBeRemoved.RoomId   = wishListReceived.RoomId;
            wishListToBeRemoved.RenterId = wishListReceived.RenterId;

            Acknowledgement <WishListDuplicate> returnData = new Acknowledgement <WishListDuplicate>();

            if (!ModelState.IsValid)
            {
                returnData = search.WhenErrorOccurs("", type: "modelState");
                return(Ok(returnData));
            }

            try
            {
                // returnData = BookingManager.(wishListReceived);
                returnData = search.DeleteFromWishList(wishListToBeRemoved);
            }
            catch (NotThereInWishList notThereInWishList)
            {
                returnData = search.WhenErrorOccurs(notThereInWishList.Message, type: "delete");  //this will call a overloaded method in bookingManager
                return(Ok(returnData));
            }
            catch (Exception)
            {
                returnData = search.WhenErrorOccurs("", type: "delete");
                return(Ok(returnData));
            }
            return(Ok(returnData));
        }
        public void DeleteFromWishList_Positive()
        {
            int renterId = 2;

            WishListDuplicate wishListDuplicateReceieved = new WishListDuplicate
            {
                RenterId = 2,
                RoomId   = 3
            };

            WishListDuplicate wishListDuplicateSent = new WishListDuplicate
            {
                WishListId = 1,
                RenterId   = 2,
                RoomId     = 3
            };


            List <WishListDuplicate> wishlistList = new List <WishListDuplicate>();

            wishlistList.Add(wishListDuplicateSent);

            Acknowledgement <WishListDuplicate> wishlistAcknowledgement = new Acknowledgement <WishListDuplicate>();

            wishlistAcknowledgement.code    = 1;
            wishlistAcknowledgement.Set     = wishlistList;
            wishlistAcknowledgement.Message = "success";


            //Arrange
            var _mockDataService = new Mock <BookingService>();


            _mockDataService.Setup(p => p.RemoveFromWishList(wishListDuplicateReceieved)).Returns(wishlistList);

            var _bookingManager = new BookingManager(_mockDataService.Object);

            try
            {
                var responseReturned = _bookingManager.DeleteFromWishList(wishListDuplicateReceieved);
                Assert.IsTrue(false);
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }