示例#1
0
        public void TestBookingOrderServiceUpdate(long id, int oldStart, int oldEnd, int newStart, int newEnd, int prod1Id, int prod2Id)
        {
            UserInfo user    = new UserInfo();
            Product  product = new Product()
            {
                Id = prod1Id
            };
            Product product2 = new Product()
            {
                Id = prod2Id
            };
            DateTime cal    = DateTime.Now;
            DateTime start  = new DateTime(cal.Year + 1, cal.Month, cal.Day, 10 + oldStart, 0, 0);
            DateTime end    = new DateTime(cal.Year + 1, cal.Month, cal.Day, 10 + oldEnd, 0, 0);
            DateTime start2 = new DateTime(cal.Year + 1, cal.Month, cal.Day, 10 + newStart, 0, 0);
            DateTime end2   = new DateTime(cal.Year + 1, cal.Month, cal.Day, 10 + newEnd, 0, 0);

            BookingOrder oldBooking = new BookingOrder()
            {
                Id                 = id,
                User               = user,
                Product            = product,
                StartTimeOfBooking = start,
                EndTimeOfBooking   = end
            };

            BookingOrder updatedBooking = new BookingOrder()
            {
                Id                 = id,
                User               = user,
                Product            = product,
                StartTimeOfBooking = start2,
                EndTimeOfBooking   = end2
            };

            IEnumerable <BookingOrder> bookingOrders = new List <BookingOrder>()
            {
                new BookingOrder()
                {
                    Id                 = id + 1,
                    User               = user,
                    Product            = product2,
                    StartTimeOfBooking = start,
                    EndTimeOfBooking   = end
                },
                oldBooking
            };

            _mockRepo.Setup(repo => repo.ReadAll()).Returns(bookingOrders);
            _mockRepo.Setup(x => x.Read(id)).Returns(updatedBooking);
            _mockRepo.Setup(x => x.Update(updatedBooking)).Returns(updatedBooking);
            Assert.IsTrue(_service.Update(updatedBooking) != null);
            _mockRepo.Verify(x => x.Update(It.IsAny <BookingOrder>()), Times.Once);
        }
 public ActionResult Put([FromBody] BookingAdapterIn value)
 {
     try
     {
         _bookingService.Update(new BookingOrder
         {
             Id                 = value.Id,
             Product            = _productService.Read(value.Product.Id),
             User               = _UserInfoservice.Read(value.User.Id),
             StartTimeOfBooking = DateConverter.FromUTCEpochToDatetime(value.StartTimeOfBooking),
             EndTimeOfBooking   = DateConverter.FromUTCEpochToDatetime(value.EndTimeOfBooking)
         });
         return(NoContent());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }