コード例 #1
0
        public void GetBookingById_(int bookingId, int expectedStatusCode)
        {
            _mockService.Setup(s => s.GetBookingById(1)).Returns(Task.FromResult(_bookingsList.ToList()[0]));
            var response = _controller.GetBookingById(bookingId).GetAwaiter().GetResult();

            Assert.That(response, Is.InstanceOf(typeof(ActionResult <ServiceResponse <BookingEvent> >)));
            var result = response.Result as ObjectResult;

            Assert.That(result.StatusCode == expectedStatusCode);
            var resultValue = result.Value as ServiceResponse <BookingEvent>;

            Utilities.PrintOut(result);
        }
コード例 #2
0
        public void Booking_Should_Be_Return_By_Id()
        {
            const int    Id             = 1;
            const string Name           = "2";
            const int    NumberOfAdults = 3;
            const int    NumberOfBabies = 4;

            mockBookingRepository.Setup(m => m.GetBookingById(Id)).Returns(new Booking {
                Id = Id, Name = Name, NumberOfAdults = NumberOfAdults, NumberOfBabies = NumberOfBabies
            });
            var bookingController          = new BookingsController(mockBookingRepository.Object);
            IHttpActionResult actionResult = bookingController.GetBookingById(Id);
            var contentResult = actionResult as OkNegotiatedContentResult <Booking>;

            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(Id, contentResult.Content.Id);
        }