public async void Add_ValidObjectPassed_ReturnsCreatedAtActionResult() { // Arrange var newId = 3; var newName = "Hello world"; // Act var actionResult = await _controller.PostBooking( new Booking { Id = newId, Name = newName } ); // Assert Assert.IsType <CreatedAtActionResult>(actionResult.Result); }
public void TestPostBooking() { Booking a = new Booking() { BookingId = 1, User = "******", Service = "Service1", BookedFrom = DateTime.Now, BookedTo = DateTime.Now.AddDays(1), Deleted = false }; var mockBookingValidator = new Mock <IBookingValidator>(); mockBookingValidator.Setup(x => x.PostBooking(a)).Verifiable(); mockBookingValidator.Setup(x => x.secure(null)).Verifiable(); mockBookingValidator.Setup(x => x.AtmSecure(null)).Verifiable(); var controller = new BookingsController(mockBookingValidator.Object); var controllerContext = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add("TODO_PAGOS_TOKEN", "1"); controllerContext.Request = request; controller.ControllerContext = controllerContext; IHttpActionResult actionResult = controller.PostBooking(a); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Booking> >; Assert.IsNotNull(actionResult); }
public async System.Threading.Tasks.Task TestClosingABooking() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseSqlite(connection) .Options; var operationalStoreOptionsMock = new Mock <OperationalStoreOptions>(); operationalStoreOptionsMock.Object.ConfigureDbContext = dbContext => dbContext.UseSqlite(connection); var iOptionsMock = Options.Create <OperationalStoreOptions>(operationalStoreOptionsMock.Object); // Create the schema in the database using (var context = new ApplicationDbContext(options, iOptionsMock)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var context = new ApplicationDbContext(options, iOptionsMock)) { var bookingController = new BookingsController(context); var locationController = new LocationsController(context); var parkingLotController = new ParkingLotsController(context); Location location = new Location() { LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000 }; await locationController.PostLocation(location); ParkingLot newParkingLot = new ParkingLot() { ParkingDisplayName = "TestPL", LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000 }; await parkingLotController.PostParkingLot(newParkingLot); context.SaveChanges(); await bookingController.PostBooking(1); context.SaveChanges(); bookingController.CloseBooking(1); context.SaveChanges(); var booking = await bookingController.GetBooking(1); Assert.True(booking.Value.IsOccupied == false); } } finally { connection.Close(); } }
public void Should_PostBooking() { Booking testBooking = new Booking { CustomerId = 1, ShowingId = 1, Status = BookingStatus.PaymentPending, BookedDate = DateTime.Now, BookingItems = new List <BookingItem>() }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.Bookings.Create(testBooking)).Returns(true); BookingsController controller = new BookingsController(mock.Object, null, null); var bookings = controller.PostBooking(testBooking); Assert.IsType <CreatedAtActionResult>(bookings); }
public void ShouldNot_PostBooking_ModelStateError() { Booking testBooking = new Booking { CustomerId = 1, ShowingId = 1, Status = BookingStatus.PaymentComplete, BookedDate = DateTime.Now, BookingItems = new List <BookingItem>() }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.Bookings.Create(testBooking)).Returns(true); mock.Setup(f => f.Bookings.GetById(1)).Returns(testBooking); BookingsController controller = new BookingsController(mock.Object, null, null); controller.ModelState.AddModelError("TestError", "Error"); var bookings = controller.PostBooking(testBooking); Assert.IsType <BadRequestObjectResult>(bookings); }