예제 #1
0
        public void Quit_WhenError_ShouldRollback()
        {
            var trip     = ModelTestHelper.CreateTrip(-1, "QuitError");
            var services = new TripServices();
            var userTrip = ModelTestHelper.CreateUserTrip(2, trip.TripName);

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

            Assert.IsNotNull(reloadedTrip);
            Assert.AreEqual(1, reloadedTrip.Participants.Count());
            services.Participate(reloadedTrip, 2, "aSecondUser");
            Assert.IsFalse(services.HasErrors, string.Join(",", services.Errors));
            var mockUserTripRepo = new Mock <IUserTripRepository>();

            mockUserTripRepo.Setup(s => s.GetUserTrip(2, reloadedTrip.TripName)).Returns(userTrip);
            mockUserTripRepo.Setup(s => s.HasErrors).Returns(true);
            mockUserTripRepo.Setup(s => s.Errors).Returns(new List <string>());
            var secondServices = new TripServices(new TripRepository(), new PotRepository(), new TripParticipantRepository(),
                                                  mockUserTripRepo.Object, new PotUserRepository());

            secondServices.Quit(reloadedTrip, 2, "aSecondUser");
            Assert.IsTrue(secondServices.HasErrors);
            Assert.AreEqual(2, services.GetParticipants(reloadedTrip.Id).Count());
        }
예제 #2
0
        public void Quit_WhenValid_ShouldCommit()
        {
            var trip     = ModelTestHelper.CreateTrip(-1, "QuitCommit", 1000);
            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.Participate(reloadedTrip, 2, "aSecondUser");
            Assert.IsFalse(services.HasErrors, string.Join(",", services.Errors));
            Assert.IsNotNull(reloadedTrip.TripPot);
            var pot = reloadedTrip.TripPot;

            pot.CurrentAmount = 200;
            var potRepo = new PotRepository();

            potRepo.UpdatePot(pot);
            Assert.IsFalse(potRepo.HasErrors);
            var potUserRepo = new PotUserRepository();
            var potUser     = potUserRepo.GetPotUser(pot.Id, 2);

            Assert.IsFalse(potUserRepo.HasErrors);
            Assert.IsNotNull(potUser);
            potUser.Amount = 200;
            potUserRepo.UpdatePotUser(potUser);
            Assert.IsFalse(potUserRepo.HasErrors);
            services.Quit(reloadedTrip, 2, "aSecondUser");
            Assert.IsFalse(services.HasErrors, string.Join(",", services.Errors));
            reloadedTrip = services.GetTrip(reloadedTrip.Id);
            Assert.IsFalse(services.HasErrors, string.Join(",", services.Errors));
            Assert.IsNotNull(reloadedTrip);
            Assert.AreEqual(1, reloadedTrip.Participants.Count());
            pot = reloadedTrip.TripPot;
            Assert.IsNotNull(pot);
            Assert.AreEqual(0, pot.CurrentAmount);
            Assert.AreEqual(1, pot.Participants.Count());
            Assert.AreEqual(1, new UserTripRepository().GetUserTripsByTrip(reloadedTrip.TripName).Count());
        }