Ejemplo n.º 1
0
        public void UpdateAllowedNumberOfPeople_WhenError_ShouldRollback()
        {
            var trip     = ModelTestHelper.CreateTrip(-1, "UpdateNbPeopleError", 1000, maxNbPeople: 30);
            var services = new TripServices();

            services.CreateTrip(trip, 1);
            Assert.IsFalse(services.HasErrors);
            var reloadedTrip = services.GetTrip(trip.Id);

            Assert.IsNotNull(reloadedTrip);
            Assert.AreEqual(1, reloadedTrip.Participants.Count());
            var mockTripRepo = new Mock <ITripRepository>();

            mockTripRepo.Setup(s => s.UpdateTrip(reloadedTrip)).Callback(() => new TripRepository().UpdateTrip(reloadedTrip));
            mockTripRepo.SetupGet(s => s.HasErrors).Returns(true);
            mockTripRepo.SetupGet(s => s.Errors).Returns(new List <string>());
            var secondServices = new TripServices(mockTripRepo.Object, new PotRepository(), new TripParticipantRepository(),
                                                  new UserTripRepository(), new PotUserRepository());

            secondServices.UpdateAllowedNumberOfPeople(trip, 50);
            Assert.IsTrue(secondServices.HasErrors);
            reloadedTrip = services.GetTrip(trip.Id);
            Assert.IsNotNull(reloadedTrip);
            Assert.AreEqual(30, reloadedTrip.NumberMaxOfPeople);
            var potUser = new PotUserRepository().GetPotUser(reloadedTrip.TripPot.Id, 1);

            Assert.IsNotNull(potUser);
            Assert.AreEqual(reloadedTrip.Price / 30, potUser.TargetAmount);
        }
Ejemplo n.º 2
0
        public void UpdateAllowedNumberOfPeople_WhenValid_ShouldCommit()
        {
            var trip     = ModelTestHelper.CreateTrip(-1, "UpdateNbPeopleValid", 1000, maxNbPeople: 30);
            var services = new TripServices();

            services.CreateTrip(trip, 1);
            Assert.IsFalse(services.HasErrors);
            var reloadedTrip = services.GetTrip(trip.Id);

            Assert.IsNotNull(reloadedTrip);
            Assert.AreEqual(1, reloadedTrip.Participants.Count());
            services.UpdateAllowedNumberOfPeople(reloadedTrip, 50);
            reloadedTrip = services.GetTrip(trip.Id);
            Assert.IsNotNull(reloadedTrip);
            Assert.AreEqual(50, reloadedTrip.NumberMaxOfPeople);
            var potUser = new PotUserRepository().GetPotUser(reloadedTrip.TripPot.Id, 1);

            Assert.IsNotNull(potUser);
            Assert.AreEqual(reloadedTrip.Price / 50, potUser.TargetAmount);
        }