public void RentBike(BikeId bikeId, BikeRack bikeRack)
 {
     // 1. Load bike rack aggregate by id
     // 2. apply command (rent)
     // 3. save
     // 4. publish events
 }
示例#2
0
 public BikeRack()
 {
     BikeRack.IncrementID();
     this.BikeRackID          = BikeRack.RackCount;
     this.RackInUse           = false;
     this.RequiresMaintenance = false;
 }
示例#3
0
        public void Post(RentBikeDto dto)
        {
            // translate to some other commands
            BikeRackId bikeRackId = dto.BikeRackId();
            BikeRack   bikeId     = dto.BikeId();

            _port.RentBike(bikeRackId, bikeId);
        }
示例#4
0
 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"));
 }
示例#5
0
 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();
        }
示例#7
0
        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();
        }
示例#8
0
 public bool RepairRack(BikeRack rack)
 {
     if (rack.RequiresMaintenance == false)
     {
         return(false);
     }
     else
     {
         rack.RequiresMaintenance = false;
         return(true);
     }
 }
示例#9
0
        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();
        }
示例#10
0
        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();
        }
示例#11
0
        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();
        }
示例#12
0
        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();
        }
示例#13
0
        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();
        }
示例#14
0
        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");
        }
示例#16
0
        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();
        }
示例#17
0
        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));
 }
示例#19
0
 private BikeRack BikeWithBrokenSingleBike(Bike bike)
 {
     return(BikeRack.WithBikes(bike));
 }
示例#20
0
 private BikeRack BikeRackWithAtLeastSingleBike()
 {
     return(BikeRack.WithAvailableBikes(1));
 }
示例#21
0
 private BikeRack EmptyBikeRack()
 {
     return(BikeRack.EmptyRack());
 }
 public static BikeRack BikeRackWithSingleBike()
 {
     return(BikeRack.WithSingleBike());
 }