예제 #1
0
        public void Handle(EditBookingCommand message)
        {
            var response = _repository.Update(message.BookingId, message.Hour, message.Length, message.UserName);

            if (response.Success)
            {
                var updated = new BookingUpdatedEvent(message.BookingId, message.Hour, message.UserName, message.Length);
                Bus.RaiseEvent(updated);
            }
        }
예제 #2
0
        public void EditBooking(int bookingId, int hour, string name, int length)
        {
            // Place the command to the bus
            var command = new EditBookingCommand(
                bookingId,
                hour,
                name,
                length
                );

            BookingApplication.Bus.Send(command);
        }
        public async Task Handle_WithAnInvalidEditBookingCommand_Throws()
        {
            //arrange
            var invalidCommand = new EditBookingCommand {
                Id = 0
            };

            //act + assert
            _ = await Assert
                .ThrowsAsync <BookingNotFoundException>(() => _handler.Handle(invalidCommand, default))
                .ConfigureAwait(false);
        }
예제 #4
0
        public async Task <IActionResult> Edit(EditBookingCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(View(command));
            }

            _ = await _mediator
                .Send(command)
                .ConfigureAwait(false);

            return(RedirectToAction("Index"));
        }
        public async Task Handle_WithAValidEditBookingCommand_UpdatesBooking()
        {
            //arrange
            Context.Add(new Booking
            {
                BookingDate   = DateTime.Now,
                ContactNumber = "0123456789",
                EmailAddress  = "*****@*****.**",
                Flexibility   = Flexibility.PlusMinusOneDay,
                Name          = "Name",
                VehicleSize   = VehicleSize.Large,
                Approved      = false
            });
            _ = await Context
                .SaveChangesAsync()
                .ConfigureAwait(false);

            var validCommand = new EditBookingCommand
            {
                Id            = 1,
                BookingDate   = DateTime.Now.AddMonths(1),
                ContactNumber = "9876543210",
                EmailAddress  = "*****@*****.**",
                Flexibility   = Flexibility.PlusMinusThreeDays,
                Name          = "NewName",
                VehicleSize   = VehicleSize.Medium,
                Approved      = true
            };

            //act
            _ = await _handler
                .Handle(validCommand, default)
                .ConfigureAwait(false);

            //assert
            var actual = await Context
                         .Bookings
                         .SingleAsync()
                         .ConfigureAwait(false);

            Assert.Equal(validCommand.BookingDate, actual.BookingDate);
            Assert.Equal(validCommand.ContactNumber, actual.ContactNumber);
            Assert.Equal(validCommand.EmailAddress, actual.EmailAddress);
            Assert.Equal(validCommand.Flexibility, actual.Flexibility);
            Assert.Equal(validCommand.Name, actual.Name);
            Assert.Equal(validCommand.VehicleSize, actual.VehicleSize);
            Assert.Equal(validCommand.Approved, actual.Approved);
        }