public ActionResult <BookingAdapterOut> Post([FromBody] BookingAdapterIn value) { try { BookingOrder booking = _bookingService.Create(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(Created("" + booking.Id, new BookingAdapterOut { Id = booking.Id, Product = booking.Product, User = booking.User, StartTimeOfBooking = DateConverter.FromDatetimeToUTCEpoch(booking.StartTimeOfBooking), EndTimeOfBooking = DateConverter.FromDatetimeToUTCEpoch(booking.EndTimeOfBooking) })); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void TestBookingOrderServiceCreate(long id, int addStart, int addEnd, int oldStart, int oldEnd, int prodid, int prod2id) { DateTime start = DateTime.Now.AddHours(addStart); DateTime end = DateTime.Now.AddHours(addEnd); UserInfo user = new UserInfo(); Product product = new Product() { Id = prodid }; Product product2 = new Product() { Id = prod2id }; IEnumerable <BookingOrder> bookingOrders = new List <BookingOrder>() { new BookingOrder() { Id = id + 1, User = user, Product = product2, StartTimeOfBooking = DateTime.Now.AddHours(oldStart), EndTimeOfBooking = DateTime.Now.AddHours(oldEnd) } }; BookingOrder boBeforeCreated = new BookingOrder() { User = user, Product = product, StartTimeOfBooking = start, EndTimeOfBooking = end }; BookingOrder boAfterCreated = new BookingOrder() { Id = id, User = user, Product = product, StartTimeOfBooking = start, EndTimeOfBooking = end }; _mockRepo.Setup(repo => repo.ReadAll()).Returns(bookingOrders); _mockRepo.Setup(x => x.Create(boBeforeCreated)).Returns(boAfterCreated); Assert.IsTrue(_service.Create(boBeforeCreated) != null); _mockRepo.Verify(x => x.Create(It.IsAny <BookingOrder>()), Times.Once); }