public void Build_WithAValidCommand_ReturnsBooking() { //arrange var validCommand = new CreateBookingCommand { BookingDate = DateTime.Now, ContactNumber = "0123456789", EmailAddress = "*****@*****.**", Flexibility = Flexibility.PlusMinusOneDay, Name = "Name", VehicleSize = VehicleSize.Large, }; var builder = new BookingBuilder(); //act var booking = builder.Build(validCommand); //assert Assert.Equal(validCommand.BookingDate, booking.BookingDate); Assert.Equal(validCommand.ContactNumber, booking.ContactNumber); Assert.Equal(validCommand.EmailAddress, booking.EmailAddress); Assert.Equal(validCommand.Flexibility, booking.Flexibility); Assert.Equal(validCommand.Name, booking.Name); Assert.Equal(validCommand.VehicleSize, booking.VehicleSize); }
public async Task UpdateBookingCommand_ShouldThrowNotFoundException_MissingExtraClass() { var userId = await RunAsDefaultUserAsync(); var subjectId = await SendAsync(new CreateSubjectCommand { Name = "Wizardry" }); var extraClassId = await SendAsync(new CreateExtraClassCommand { Name = "Gandalf's class", SubjectId = subjectId, Size = 1, Price = 500, Duration = TimeSpan.FromMinutes(60), Date = DateTime.Now, }); var command = new CreateBookingCommand { ExtraClassId = extraClassId }; var bookingId = await SendAsync(command); var updateCommand = new UpdateBookingCommand { Id = bookingId, ExtraClassId = 9999999999, Paid = true, Price = 100 }; //Assert FluentActions.Invoking(() => SendAsync(updateCommand)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> Create([FromBody] CreateBookingCommand command) { try { _logger.LogInformation("Log message in the Create() method"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bookingId = await _bookingAPI.CreatedBooking(command); return(StatusCode(StatusCodes.Status201Created, bookingId)); } catch (BrokenCircuitException ex) { _logger.LogInformation("Exception in Booking-> Create: " + ex); telemetry.TrackException(ex); // Catches error when bookingapi is in circuit-opened mode return(StatusCode(StatusCodes.Status500InternalServerError, "Sorry Booking Service Is Not Available. Please try again later.")); } catch (Exception ex) { _logger.LogInformation("Exception in Booking-> Create: " + ex); telemetry.TrackException(ex); return(StatusCode(StatusCodes.Status500InternalServerError, "Sorry Some problem Occured In booking Service")); } }
public async Task CreateBookingCommand_ShouldExecuteSuccessfully() { // Arrange var userId = await RunAsDefaultUserAsync(); var subjectId = await SendAsync(new CreateSubjectCommand { Name = "Wizardry" }); var extraClassId = await SendAsync(new CreateExtraClassCommand { Name = "Gandalf's class", SubjectId = subjectId, Size = 1, Price = 500, Duration = TimeSpan.FromMinutes(60), Date = DateTime.Now, }); var command = new CreateBookingCommand { ExtraClassId = extraClassId }; var bookingId = await SendAsync(command); var booking = await FindAsync <Booking>(bookingId); booking.UserId.Should().Be(userId); booking.ExtraClassId.Should().Be(extraClassId); booking.CreatedBy.Should().Be(userId); booking.Created.Should().BeCloseTo(DateTime.Now, 10000); }
public async Task CreateBookingCommandHandler_ShouldThrowDoubleBookingException() { // Arrange var userId = await RunAsDefaultUserAsync(); var subjectId = await SendAsync(new CreateSubjectCommand { Name = "Wizardry" }); var extraClassId = await SendAsync(new CreateExtraClassCommand { Name = "Gandalf's class", SubjectId = subjectId, Size = 5, Price = 500, Duration = TimeSpan.FromMinutes(60), Date = DateTime.Now, }); var command = new CreateBookingCommand { ExtraClassId = extraClassId }; var bookingId = await SendAsync(command); //Assert FluentActions.Invoking(() => SendAsync(command)).Should().Throw <DoubleBookingException>(); }
public BookingsController( UserBookingQuery userBookingQuery, CreateBookingCommand createBookingCommand ) { _userBookingQuery = userBookingQuery; _createBookingCommand = createBookingCommand; }
public async Task <BookingProductDTO> CreateBookingAsync([Body] CreateBookingCommand command) { await Task.CompletedTask; return(new BookingProductDTO { Id = 1 }); }
public void Build_WithAnInvalidCommand_Throws() { //arrange var builder = new BookingBuilder(); var command = new CreateBookingCommand(); //act + assert Assert.ThrowsAny <Exception>(() => builder.Build(command)); }
public async Task CreateBooking(CreateBookingInput input) { var request = new CreateBookingCommand { ArriveDate = input.ArriveDate, CustomerName = input.CustomerName, RoomName = input.RoomName }; await _mediator.Send <ResponseBase>(request); }
public void CreateBookingCommandHandler_ExtraClassDoesNotExist_ShouldThrowNotFoundException() { // Arrange var command = new CreateBookingCommand { ExtraClassId = 99 }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> CreateBooking() { var timeslotId = new Guid("fc7dbac5-fba5-4ae6-9bbb-08d7d0b1a950"); var from = new DateTime(2020, 3, 25, 20, 00, 00); var to = new DateTime(2020, 3, 25, 22, 00, 00); var bookingCommand = new CreateBookingCommand(timeslotId, from, to); await _mediator.Send(bookingCommand); return(Ok()); }
public async Task <IActionResult> CreateBookingAsync([FromBody] CreateBookingCommand command) { try { await createBookingCommandHandler.HandleAsync(command); return(Ok()); } catch { return(BadRequest()); } }
public async Task GivenCreateBookingCommand_ReturnsSuccessStatusCode() { var command = new CreateBookingCommand(string.Empty, string.Empty); command.CustomerId = string.Empty; command.Destination = "45 Terrian st"; command.Origin = "67 bloom blvd"; var content = Utilities.GetRequestContent(command); var response = await _client.PostAsync($"/api/booking", content); response.EnsureSuccessStatusCode(); }
public async Task <IActionResult> Create(CreateBookingCommand command) { if (!ModelState.IsValid) { return(View(command)); } _ = await _mediator .Send(command) .ConfigureAwait(false); return(RedirectToAction("Index")); }
public async Task <IActionResult> Index(BookViewModel bookViewModel) { if (ModelState.IsValid) { string paxId = HttpContext.Session.GetString(SessionDataKeys.PaxId); //Calculate Product Price ProductPriceDTO productPrice = await getProductPricing(bookViewModel.ProductId, bookViewModel.CheckInDate, bookViewModel.CheckInTime); bookViewModel.CalculateFinalPrice(productPrice); //Create Booking CreateBookingCommand createBookingCommand = new CreateBookingCommand { Name = bookViewModel.ProductName }; CreateBookingCommandItem bookingItem = new CreateBookingCommandItem() { ProductId = bookViewModel.ProductId, DateCheckIn = bookViewModel.CheckInDate.ToJsonDateTime(bookViewModel.CheckInTime), }; bookingItem.PaxId.Add(paxId); createBookingCommand.BookingProducts.Add(bookingItem); BookingProductDTO bookingProductDTO = await _heroService.BookingApi.CreateBookingAsync(createBookingCommand); //Validate Booking BookingValidationResultDTO bookResult = await _heroService.BookingApi.ValidateBookingAsync(bookingProductDTO.Id); if (bookResult.IsValid) { //Create the payment CreatePaymentCommand createPaymentCommand = new CreatePaymentCommand() { Amount = bookViewModel.FinalPrice, BookingId = bookingProductDTO.Id, IsFinal = true, Method = PaymentMethod.Cash, PaxId = paxId }; await _heroService.PaymentApi.CreatePaymentAsync(createPaymentCommand); return(RedirectToAction("Index", "Voucher", new { bookingId = bookingProductDTO.Id, paxId })); } else { this.ModelState.AddModelError("BookValidation", "Book validation failed please retry"); } } return(View(bookViewModel)); }
public async Task <Response> CreateBooking(CreateBookingCommand booking) { var response = await PostAsync <CreateBookingCommand>(baseurl, booking); if (response.IsSuccessStatusCode) { return(new Response(true)); } return(Response.Unsuccesfull()); }
public async Task CreateBooking() { //Arrange var _fakeEventBus = new Mock <IEventBus>(); var sut = new CreateBookingCommandHandler(_repo, _fakeEventBus.Object); //Act CreateBookingCommand command = new CreateBookingCommand(string.Empty, string.Empty); var result = await sut.Handle(command, CancellationToken.None); //Assert Guid bookingRef = Guid.Parse(result); result.ShouldBeOfType <string>(); bookingRef.ShouldBeOfType <Guid>(); result.Count().ShouldBe(36); }
public async Task <IActionResult> Create([FromBody] CreateBookingCommand command) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bookingOrderId = await Mediator.Send(command); //We can replace this with CreatedAtAction as well return(StatusCode(StatusCodes.Status201Created, bookingOrderId)); } catch (Exception ex) { telemetry.TrackException(ex); return(StatusCode(StatusCodes.Status500InternalServerError, "Sorry We are Unable to Create Booking.")); } }
//Booking create command with circuit breaker and retry logic public async Task <string> CreatedBooking(CreateBookingCommand command) { try { var result = await _client.PostAsync("/api/booking", new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json")); if (result.StatusCode != HttpStatusCode.Created) { throw new Exception(result.ReasonPhrase); } return(await result.Content.ReadAsStringAsync()); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> OnPost([FromBody] CreateBookingCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } command.UserId = GetUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await mediator.Send(command); return(result.Status != ActionResultCode.Success ? GetErrorResult(result) : Ok(result)); }
public Task CreateAsync(Booking booking) { var command = new CreateBookingCommand(booking, mapper); return(command.ApplyAsync(context)); }
public async Task <IActionResult> CreateBooking([FromBody] CreateBookingCommand command) { await _mediator.Send(command); return(Ok()); }
public async Task <ActionResult <int> > Create([FromBody] CreateBookingCommand command) { command.Id = IdFromClaimsResolver.Resolve(httpContextAccessor as HttpContextAccessor); return(Ok(await Mediator.Send(command))); }
public CreateBookingCommandTests() { context.Setup(c => c.Bookings).Returns(bookingSet); sut = new CreateBookingCommand(context.Object); }
public async Task Test_WithValidForm() { // Arrange var customer = Fixture.Create <Customer>(); var airport1 = new Airport(1, "IST", "TR", "IST"); var airport2 = new Airport(1, "AMS", "NL", "AMS"); var airline = new Airline(1, "TK", "THY", "Istanbul"); // var bookingForm = new NewBookingForm { BookingNumber = "BN1X3", CustomerId = customer.Id, DateBooking = DateTime.UtcNow, Flight = new NewFlightForm { FlightNumber = "TK1953", DepartureDate = DateTime.Today, DepartureAirportId = 1, ArrivalDate = DateTime.Today.AddDays(1), ArrivalAirportId = 2, Price = 99, CarrierId = 1 }, Passengers = new List <NewPassengerForm> { new NewPassengerForm { Email = "*****@*****.**", Address = "Some address", Name = "Some Name", Gender = Gender.Female, DateBirth = new DateTime(2000, 1, 1) } } }; // var mockBooking = new Mock <IBookingRepository>(); mockBooking.Setup(repo => repo.GetNextBookingId()).Returns(1); mockBooking.Setup(repo => repo.GetNextFlightId()).Returns(1); mockBooking.Setup(repo => repo.GetNextPassengerId()).Returns(1); // var mockCustomer = new Mock <ICustomerRepository>(); mockCustomer.Setup(repo => repo.GetById(customer.Id)).Returns(customer); // var mockAirports = new Mock <IAirportRepository>(); mockAirports.Setup(repo => repo.GetById(1)).Returns(airport1); mockAirports.Setup(repo => repo.GetById(2)).Returns(airport2); // var mockAirlines = new Mock <IAirlineRepository>(); mockAirlines.Setup(repo => repo.GetById(1)).Returns(airline); // var command = new CreateBookingCommand(bookingForm); var commandHandler = new CreateBookingCommandHandler(mockBooking.Object, mockAirlines.Object, mockAirports.Object, mockCustomer.Object); // Act var result = await commandHandler.Handle(command, CancellationToken.None); // Assert Assert.NotNull(result); Assert.Equal(bookingForm.BookingNumber, result.BookingNumber); Assert.Equal(bookingForm.DateBooking, result.DateBooking); Assert.Equal(bookingForm.CustomerId, result.CustomerId); Assert.NotNull(result.Flight); Assert.Equal(bookingForm.Flight.FlightNumber, result.Flight.FlightNumber); Assert.NotNull(result.Passengers); Assert.NotEmpty(result.Passengers); }
public async Task <IActionResult> Create([FromBody] CreateBookingCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task <IActionResult> CreateBooking([FromBody] CreateBookingCommand request) { return(Ok(await _mediator.Send(request))); }