public void RentBike(BikeId bikeId, BikeRack bikeRack) { // 1. Load bike rack aggregate by id // 2. apply command (rent) // 3. save // 4. publish events }
public void Given_BikeRackWithoutASingleBike_When_RentABike_ThenRentFails() { // given var bikeRack = emptyBikeRack(); BikeId bikeId = anyBikeId(); Client client = clientWithSomeFunds(); // when Check.ThatCode(() => bikeRack.Rent(bikeId, client)) // then .Throws <BikeRentFailedException>(); }
public void CanRentABike() { // given var bikeRack = nonEmptyBikeRack(); var bikeId = new BikeId(); Client client = clientWithSomeFunds(); // when var bikeRent = bikeRack.Rent(bikeId, client); // then Check.That(bikeRent).IsNotNull(); }
/// <summary> /// Rents a bike from this rack. /// </summary> /// <param name="bikeId">id of the bike to rent</param> /// <param name="client">a client who wants to rent a bike</param> /// <returns>emitted event</returns> /// <exception cref="BikeRentFailedException">thrown when rent fails</exception> public BikeRent Rent(BikeId bikeId, Client client) { if (client.HasNoFunds()) { throw new BikeRentFailedException("Client has no funds"); } if (AvailableBikes == 0) { throw new BikeRentFailedException("Bike rent failed"); } AvailableBikes--; return(new BikeRent()); }
public void When_RentBikeByClientWithoutFunds_ThenRentFails() { // given BikeRack bikeRack = nonEmptyBikeRack(); BikeId bikeId = anyBikeId(); Client client = clientWithoutFunds(); // when Check.ThatCode(() => bikeRack.Rent(bikeId, client)) // then .Throws <BikeRentFailedException>() .WithMessage("Client has no funds"); }
/// <summary> /// Model must be validated! /// </summary> public BusinessEntities.Bikes.Bike ToEntity() { return(new BusinessEntities.Bikes.Bike( BikeId.GetValueOrDefault(), BikeState.Value, BikeModel.ToEntityPartial(), Color, CurrentLocation, CurrentLocationName, AvailableFromUtc.GetValueOrDefault(), RateAverage.GetValueOrDefault(), Created.Value, CreatedBy.ToEntityPartial(), null, ImageSeq, true )); }