public void UpdatePrice_WhenValid_ShouldCommit() { var trip = ModelTestHelper.CreateTrip(-1, "UpdatePriceValid", 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.UpdatePrice(reloadedTrip, 2000.26); reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); Assert.AreEqual(2000.26, reloadedTrip.Price); Assert.IsNotNull(reloadedTrip.TripPot); Assert.AreEqual(2000.26, reloadedTrip.TripPot.TargetAmount); var potUser = new PotUserRepository().GetPotUser(reloadedTrip.TripPot.Id, 1); Assert.IsNotNull(potUser); Assert.AreEqual(2000.26 / reloadedTrip.NumberMaxOfPeople, potUser.TargetAmount); var userTrip = new UserTripRepository().GetUserTrip(1, trip.TripName); Assert.IsNotNull(userTrip); Assert.AreEqual(2000.26, userTrip.TripAmount); }
public void UpdatePrice_WhenError_ShouldRollback() { var trip = ModelTestHelper.CreateTrip(-1, "UpdatePriceError", 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.UpdatePrice(trip, 2000.26); Assert.IsTrue(secondServices.HasErrors); reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); Assert.AreEqual(1000, reloadedTrip.Price); Assert.IsNotNull(reloadedTrip.TripPot); Assert.AreEqual(1000, reloadedTrip.TripPot.TargetAmount); var potUser = new PotUserRepository().GetPotUser(reloadedTrip.TripPot.Id, 1); Assert.IsNotNull(potUser); Assert.AreEqual(1000 / (double)reloadedTrip.NumberMaxOfPeople, potUser.TargetAmount); var userTrip = new UserTripRepository().GetUserTrip(1, trip.TripName); Assert.IsNotNull(userTrip); Assert.AreEqual(1000, userTrip.TripAmount); }