public void DeleteTrip_WhenError_ShouldRollback() { var trip = ModelTestHelper.CreateTrip(-1, "deleteTripError"); var services = new TripServices(); services.CreateTrip(trip, 1); Assert.IsFalse(services.HasErrors); var reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); var userTrip = ModelTestHelper.CreateUserTrip(1, trip.TripName); var mockUserTripRepo = new Mock <IUserTripRepository>(); mockUserTripRepo.Setup(s => s.GetUserTripsByTrip(trip.TripName)).Returns(new List <UserTrip> { userTrip }); mockUserTripRepo.SetupGet(s => s.HasErrors).Returns(true); mockUserTripRepo.SetupGet(s => s.Errors).Returns(new List <string>()); var secondServices = new TripServices(new TripRepository(), new PotRepository(), new TripParticipantRepository(), mockUserTripRepo.Object, new PotUserRepository()); secondServices.DeleteTrip(reloadedTrip); Assert.IsTrue(secondServices.HasErrors); reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); Assert.AreEqual(1, reloadedTrip.Participants.Count()); }
public void DeleteTrip_WhenValid_ShouldCommit() { var trip = ModelTestHelper.CreateTrip(-1, "deleteTripCommit"); var services = new TripServices(); services.CreateTrip(trip, 1); Assert.IsFalse(services.HasErrors); var reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); var pot = reloadedTrip.TripPot; Assert.IsNotNull(pot); var participants = reloadedTrip.Participants; Assert.AreEqual(1, participants.Count()); var potUsers = pot.Participants; Assert.AreEqual(1, potUsers.Count()); var tripRepo = new TripRepository(); var potRepo = new PotRepository(); var userTripRepo = new UserTripRepository(); var potUserRepo = new PotUserRepository(); var tripParticipantRepo = new TripParticipantRepository(); services.DeleteTrip(reloadedTrip); Assert.IsFalse(services.HasErrors); Assert.IsNull(tripRepo.GetTrip(reloadedTrip.Id)); Assert.IsNull(potRepo.GetPot(pot.Id)); Assert.AreEqual(0, userTripRepo.GetUserTripsByTrip(reloadedTrip.TripName).Count()); Assert.AreEqual(0, potUserRepo.GetPotUsers(pot.Id).Count()); Assert.AreEqual(0, tripParticipantRepo.GetTripParticipants(reloadedTrip.Id).Count()); }
public void DeleteTrip_WhenException_ShouldRollback() { var trip = ModelTestHelper.CreateTrip(-1, "deleteTripException"); var services = new TripServices(); services.CreateTrip(trip, 1); Assert.IsFalse(services.HasErrors); var reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); var mockUserTripRepo = new Mock <IUserTripRepository>(); mockUserTripRepo.Setup(s => s.GetUserTripsByTrip(trip.TripName)).Throws(new Exception("Exception")); var secondServices = new TripServices(new TripRepository(), new PotRepository(), new TripParticipantRepository(), mockUserTripRepo.Object, new PotUserRepository()); secondServices.DeleteTrip(reloadedTrip); Assert.IsTrue(secondServices.HasErrors); reloadedTrip = services.GetTrip(trip.Id); Assert.IsNotNull(reloadedTrip); Assert.AreEqual(1, reloadedTrip.Participants.Count()); }