public void TestInitializer() { _unitOfWork = new MockUnitOfWork(); _roomController = new RoomTypeController(ModelMapper.Create(), _unitOfWork); _roomController.ControllerContext = Substitute.For <HttpControllerContext>(); _roomController.Request = new HttpRequestMessage(); _roomController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); _roomController.Request.SetConfiguration(new HttpConfiguration()); _roomController.RequestContext.Principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "1") })); }
public async Task Prices_ReturnsEmptyResult_WithInvalidRoomTypeId() { // Arrange await using var meredithDbContext = await InitializeDb(nameof (Prices_ReturnsEmptyResult_WithInvalidRoomTypeId)); var controller = new RoomTypeController(meredithDbContext); // Act var result = await controller.Prices(-1, new DateTime(2020, 1, 2), new DateTime(2020, 1, 4)); // Assert var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <PricesResult> >(viewResult.Value); Assert.Empty(model); }
public async Task Prices_ReturnsResult_WithSpecifiedDates() { // Arrange await using var meredithDbContext = await InitializeDb(nameof (Prices_ReturnsResult_WithSpecifiedDates)); var controller = new RoomTypeController(meredithDbContext); var expected = new List <PricesResult> { new PricesResult(2, 1, new DateTime(2020, 1, 2), 200), new PricesResult(3, 1, new DateTime(2020, 1, 3), 300), new PricesResult(4, 1, new DateTime(2020, 1, 4), 400) }; // Act var result = await controller.Prices(1, new DateTime(2020, 1, 2), new DateTime(2020, 1, 4)); // Assert var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <List <PricesResult> >(viewResult.Value); AssertEqual(expected, model); }
/// <summary> /// The page_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { this.AvailableRooms = new List <Room>(); this.availableRoomsGridView.DataSource = this.AvailableRooms; this.availableRoomsGridView.DataBind(); this.Session["Booking"] = new Booking(); this.customerController = new CustomerController(); this.roomTypeController = new RoomTypeController(); var roomTypes = this.roomTypeController.RefreshEntities(); this.roomTypeComboBox.DataSource = roomTypes; this.customerComboBoxDataBind(); this.roomTypeComboBox.DataBind(); } else { this.booking = this.Session["Booking"] as Booking; } }
public RoomTypeControllerTest() { iMappingMock = new Mock <IMapping <RoomTypes> >(); loggerMock = new Mock <ILogger>(); mockRoomTypeController = new RoomTypeController(loggerMock.Object, iMappingMock.Object); }
/// <summary> /// The save booking button_ on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void saveBookingButton_OnClick(object sender, EventArgs e) { this.booking = this.Session["Booking"] as Booking; var errorlabel = this.Master?.FindControl("form1").FindControl("divErrorMessage") as Label; if (errorlabel != null) { errorlabel.Text = string.Empty; } this.roomTypeController = new RoomTypeController(); this.customerController = new CustomerController(); this.bookingController = new BookingController(); this.customerComboBoxDataBind(); var dateFrom = this.dateFromCalendar.Text; var dateTo = this.dateToCalendar.Text; var price = this.roomTypePriceTextBox.Text; if (price == string.Empty) { if (errorlabel != null) { errorlabel.Text = "Please calculate price first"; } return; } var row = this.availableRoomsGridView.FocusedRowIndex; var selectedRoom = (Room)this.availableRoomsGridView.GetRow(row); if (selectedRoom == null) { if (errorlabel != null) { errorlabel.Text = "Please select a room first"; } return; } if (this.booking.CustomerId == 0) { if (errorlabel != null) { errorlabel.Text = "Please select a customer first"; } return; } var agreedPrice = this.agreedPriceTextBox.Text; if (agreedPrice == string.Empty) { agreedPrice = price; } this.booking.RoomId = selectedRoom.Id; this.booking.AgreedPrice = Convert.ToDouble(agreedPrice); this.booking.SystemPrice = Convert.ToDouble(price); this.booking.From = Convert.ToDateTime(dateFrom); this.booking.To = Convert.ToDateTime(dateTo); this.booking.Status = Status.New; this.booking.Comments = this.commentMemoBox.Text; try { this.bookingController.CreateOrUpdateEntity(this.booking); this.Response.Redirect("BookingsListForm.aspx"); } catch (Exception ex) { errorlabel.Text = ex.Message; } }