public async void GetById_UnknownIdPassed_ReturnsNotFoundResult() { // Arange int nonExistingId = -1; // Act ActionResult <Booking> actionResult = await _controller.GetBooking(nonExistingId); // Assert Assert.IsType <NotFoundResult>(actionResult.Result); }
//[ExpectedException(typeof(Exception))] public void TestGetBooking() { new Booking() { BookingId = 1, User = "******", Service = "Service1", BookedFrom = DateTime.Now, BookedTo = DateTime.Now.AddDays(1), Deleted = false }; var mockBookingValidator = new Mock <IBookingValidator>(); 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.GetBooking("1"); 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 GetBooking_ReturnNotNullList() { var mock = new Mock <bookingrepo>(db); BookingsController obj = new BookingsController(mock.Object); var data = obj.GetBooking(); var res = data as ObjectResult; Assert.IsNotNull(data); }
public void GetBooking_ValidInput_OkRequest() { var mock = new Mock <bookingrepo>(db); BookingsController obj = new BookingsController(mock.Object); var data = obj.GetBooking(); var res = data as ObjectResult; Assert.AreEqual(200, res.StatusCode); }
public void GetBooking_InvalidInput_ReturnsBadRequest() { try { var mock = new Mock <bookingrepo>(db); BookingsController obj = new BookingsController(mock.Object); var data = obj.GetBooking(); var res = data as BadRequestResult; Assert.AreEqual(400, res.StatusCode); } catch (Exception e) { Assert.AreEqual("Object reference not set to an instance of an object.", e.Message); } }
public void Should_GetBooking() { Mock <IUnitOfWork> mockUOW = new Mock <IUnitOfWork>(); mockUOW.Setup(f => f.Bookings.Get()).Returns(new List <Booking> { new Booking { Id = 1, CustomerId = 1, ShowingId = 1, Status = BookingStatus.PaymentPending, BookedDate = DateTime.Parse("01-01-2020 12:00"), BookingItems = new List <BookingItem>() } } .AsQueryable()); mockUOW.Setup(f => f.Customers.Get()).Returns(new List <Customer> { new Customer { Id = 1, UserId = "test" } }.AsQueryable()); // mock UserManager var userStore = new Mock <IUserStore <User> >(); Mock <UserManager <User> > mockUserManager = new Mock <UserManager <User> >(userStore.Object, null, null, null, null, null, null, null, null); mockUserManager.Setup(f => f.IsInRoleAsync(It.IsAny <User>(), "admin")).Returns(Task.FromResult(true)); mockUserManager.Setup(f => f.FindByNameAsync(It.IsAny <string>())).Returns(Task.FromResult(new User { Id = "test" })); BookingsController controller = new BookingsController(mockUOW.Object, mockUserManager.Object, null); var userClaimsIdentity = new ClaimsPrincipal(); userClaimsIdentity.AddIdentity(new ClaimsIdentity(new[] { new Claim("sub", "*****@*****.**") })); controller.ControllerContext.HttpContext = new DefaultHttpContext() { User = userClaimsIdentity }; var booking = controller.GetBooking(1); Assert.IsType <OkObjectResult>(booking); }