public void RentBike(BikeId bikeId, BikeRack bikeRack) { // 1. Load bike rack aggregate by id // 2. apply command (rent) // 3. save // 4. publish events }
public BikeRack() { BikeRack.IncrementID(); this.BikeRackID = BikeRack.RackCount; this.RackInUse = false; this.RequiresMaintenance = false; }
public void Post(RentBikeDto dto) { // translate to some other commands BikeRackId bikeRackId = dto.BikeRackId(); BikeRack bikeId = dto.BikeId(); _port.RentBike(bikeRackId, bikeId); }
public ActionResult archiveRack([Bind(Include = "bikeRackId")] BikeRack rack) { if (!authorize()) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized)); } context.BikeRack.Find(rack.bikeRackId).isArchived = !context.BikeRack.Find(rack.bikeRackId).isArchived; context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult newRack(BikeRack rack) { if (!authorize()) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized)); } rack.isArchived = false; context.BikeRack.Add(rack); context.SaveChanges(); return(RedirectToAction("bikeRackList")); }
public void CanReturnABike() { // given BikeRack bikeRack = BikeTestsObjectMother.AnyBikeRack(); // when BikeReturned bikeReturned = bikeRack.ReturnBike(); // then Check.That(bikeReturned).IsNotNull(); }
public void Given_EmptyBikeRack_When_RentABike_ThenRentFails() { // given BikeRack bikeRack = EmptyBikeRack(); Client client = ClientWithSufficientFunds(); Bike bike = NonBrokenBike(); // when BikeRentResult result = bikeRack.RentBikeBy(client, bike.Id); // then Check.That(result.BikeRent).IsNull(); }
public bool RepairRack(BikeRack rack) { if (rack.RequiresMaintenance == false) { return(false); } else { rack.RequiresMaintenance = false; return(true); } }
public void Given_RackWithAtLeastOneBike_When_RentABikeByClientWithLessThan10Pln_ThenBikeRentFails() { // given BikeRack bikeRack = BikeRackWithAtLeastSingleBike(); Client client = ClientWith(PlnOf(9.00m)); Bike bike = NonBrokenBike(); // when var result = bikeRack.RentBikeBy(client, bike.Id); // then Check.That(result.BikeRent).IsNull(); }
public void Given_RackWithSingleBike_When_RentABike_ThenBikeIsRent() { // given Bike bike = NonBrokenBike(); BikeRack rack = BikeTestsObjectMother.BikeRackWithSingleBike(bike); Client client = ClientWithSufficientFunds(); // when BikeRentResult result = rack.RentBikeBy(client, bike.Id); // then Check.That(result.BikeRent).IsNotNull(); }
public void Given_RackWithAtLeastOneBike_When_RentABikeByClientWithAtLeast10Pln_ThenBikeIsRent() { // given Bike bike = NonBrokenBike(); BikeRack bikeRack = BikeTestsObjectMother.BikeRackWithSingleBike(bike); Client client = ClientWith(PlnOf(10.00m)); // when var bikeRentResult = bikeRack.RentBikeBy(client, bike.Id); // then Check.That(bikeRentResult.BikeRent).IsNotNull(); }
public void Given_ClientWithRentedTwoBikes_TryToRentAnotherBike_Then_RentFails() { // given Bike bike = NonBrokenBike(); Client client = ClientWithActivesTwoBikes(PlnOf(10.00m)); BikeRack bikeRack = BikeTestsObjectMother.BikeRackWithSingleBike(bike); // when var result = bikeRack.RentBikeBy(client, bike.Id); // then Check.That(result.BikeRent).IsNull(); Check.That(result.RentLimitExceeded).IsNotNull(); }
public void Given_InvalidBikeId_ThenBikeRentFails() { // given var invalidId = AnyBikeId(); Bike bike = NonBrokenBike(); Client client = ClientWithSufficientFunds(); BikeRack bikeRack = BikeTestsObjectMother.BikeRackWithSingleBike(bike); // when var result = bikeRack.RentBikeBy(client, invalidId); // then Check.That(result.TriedToRentInvalidBike).IsNotNull(); }
public void Given_RackWithAtLeastOneBike_When_RentedBikeIsBroken_ThenBikeRentFails() { // given Bike brokenBike = BrokenBike(); BikeRack bikeRack = BikeWithBrokenSingleBike(brokenBike); Client client = ClientWithSufficientFunds(); // when var result = bikeRack.RentBikeBy(client, brokenBike.Id); // then Check.That(result.BikeRent).IsNull(); Check.That(result.BikeBroken).IsNotNull(); }
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"); }
public void Given_RackWithOneBike_When_TryToRentBikeTwice_Then_SecondRentFails() { // given Bike bike = NonBrokenBike(); Client client = ClientWithSufficientFunds(); BikeRack bikeRack = BikeTestsObjectMother.BikeRackWithSingleBike(bike); // when bikeRack.RentBikeBy(client, bike.Id); var result = bikeRack.RentBikeBy(client, bike.Id); // then Check.That(result.BikeRent).IsNull(); Check.That(result.TriedToRentInvalidBike).IsNotNull(); }
public ActionResult editRack([Bind] BikeRack rack) { if (!authorize()) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized)); } var dRack = context.BikeRack.Find(rack.bikeRackId); dRack.description = rack.description; dRack.GPSCoordX = rack.GPSCoordX; dRack.GPSCoordY = rack.GPSCoordY; dRack.isArchived = rack.isArchived; dRack.name = rack.name; context.SaveChanges(); return(RedirectToAction("editRack", new { rackId = rack.bikeRackId })); }
public static BikeRack BikeRackWithSingleBike(Bike bike) { return(BikeRack.WithSingleBike(bike)); }
private BikeRack BikeWithBrokenSingleBike(Bike bike) { return(BikeRack.WithBikes(bike)); }
private BikeRack BikeRackWithAtLeastSingleBike() { return(BikeRack.WithAvailableBikes(1)); }
private BikeRack EmptyBikeRack() { return(BikeRack.EmptyRack()); }
public static BikeRack BikeRackWithSingleBike() { return(BikeRack.WithSingleBike()); }