Пример #1
0
        public void Credit_WhenUnableToUpdatePotUser_ShouldLogError()
        {
            var          pot     = ModelTestHelper.CreatePot(2, 1);
            var          potUser = ModelTestHelper.CreatePotUser(1, pot.Id);
            const string error   = "Unable to update pot user";
            var          errors  = new List <string> {
                error
            };

            _mockPotUserRepo.Setup(s => s.GetPotUser(pot.Id, 1)).Returns(potUser);
            _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(false);
            _mockPotUserRepo.Setup(s => s.UpdatePotUser(potUser)).Callback
            (

                () =>
            {
                _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(true);
                _mockPotUserRepo.SetupGet(s => s.Errors).Returns(errors);
            }
            );
            CreateServices();
            _potServices.Credit(pot, 1, 100);
            Assert.IsTrue(_potServices.HasErrors);
            Assert.IsTrue(_potServices.Errors.Contains(error));
        }
Пример #2
0
        public void Credit_WhenException_ShouldRollback()
        {
            var pot     = ModelTestHelper.CreatePot(-1, 1, amount: 200);
            var potRepo = new PotRepository();

            potRepo.SavePot(pot);
            Assert.IsFalse(potRepo.HasErrors);
            var potUser     = ModelTestHelper.CreatePotUser(1, pot.Id, amount: 0, targetAmount: 200);
            var potUserRepo = new PotUserRepository();

            potUserRepo.SavePotUser(potUser);
            Assert.IsFalse(potUserRepo.HasErrors);
            var mockPotRepo = new Mock <IPotRepository>();

            mockPotRepo.Setup(s => s.UpdatePot(It.IsAny <Pot>())).Throws(new Exception("Exception"));
            var services = new PotServices(mockPotRepo.Object, new PotUserRepository());

            services.Credit(pot, 1, 200);
            Assert.IsTrue(services.HasErrors);
            services = new PotServices();
            var dbPot = services.GetPot(pot.Id);

            Assert.IsNotNull(dbPot);
            Assert.AreEqual(200, dbPot.CurrentAmount);
            Assert.AreEqual(1, dbPot.Participants.Count());
            var member = dbPot.Participants.First();

            Assert.IsNotNull(member);
            Assert.AreEqual(0, member.Amount);
        }
Пример #3
0
        public void Equals_ShouldReturnCorrectValue(int firstUserId, int firstPotId, int secondUserId, int secondPotId, bool expected)
        {
            var firstPotUser  = ModelTestHelper.CreatePotUser(firstUserId, firstPotId);
            var secondPotUser = ModelTestHelper.CreatePotUser(secondUserId, secondPotId);

            Assert.AreEqual(expected, firstPotUser.Equals(secondPotUser));
        }
Пример #4
0
        public void Credit_WhenErrorDuringUpdate_ShouldRollback()
        {
            var pot     = ModelTestHelper.CreatePot(-1, 1, amount: 200);
            var potRepo = new PotRepository();

            potRepo.SavePot(pot);
            Assert.IsFalse(potRepo.HasErrors);
            var potUser     = ModelTestHelper.CreatePotUser(1, pot.Id, amount: 0, targetAmount: 200);
            var potUserRepo = new PotUserRepository();

            potUserRepo.SavePotUser(potUser);
            Assert.IsFalse(potUserRepo.HasErrors);
            var mockPotRepo = new Mock <IPotRepository>();

            mockPotRepo.SetupGet(s => s.HasErrors).Returns(true);
            mockPotRepo.SetupGet(s => s.Errors).Returns(new List <string> {
                "an error"
            });
            var services = new PotServices(mockPotRepo.Object, new PotUserRepository());

            services.Credit(pot, 1, 200);
            Assert.IsTrue(services.HasErrors);
            services = new PotServices();
            var dbPot = services.GetPot(pot.Id);

            Assert.IsNotNull(dbPot);
            Assert.AreEqual(200, dbPot.CurrentAmount);
            Assert.AreEqual(1, dbPot.Participants.Count());
            var member = dbPot.Participants.First();

            Assert.IsNotNull(member);
            Assert.AreEqual(0, member.Amount);
        }
Пример #5
0
        public void Credit_WhenValid_ShouldCommit()
        {
            var pot     = ModelTestHelper.CreatePot(-1, 1, amount: 200);
            var potRepo = new PotRepository();

            potRepo.SavePot(pot);
            Assert.IsFalse(potRepo.HasErrors);
            var potUser     = ModelTestHelper.CreatePotUser(1, pot.Id, amount: 0, targetAmount: 200);
            var potUserRepo = new PotUserRepository();

            potUserRepo.SavePotUser(potUser);
            Assert.IsFalse(potUserRepo.HasErrors);
            var services = new PotServices();

            services.Credit(pot, 1, 200);
            Assert.IsFalse(services.HasErrors);
            var dbPot = services.GetPot(pot.Id);

            Assert.IsNotNull(dbPot);
            Assert.AreEqual(400, dbPot.CurrentAmount);
            Assert.AreEqual(1, dbPot.Participants.Count());
            var member = dbPot.Participants.FirstOrDefault();

            Assert.IsNotNull(member);
            Assert.AreEqual(200, member.Amount);
            Assert.IsTrue(member.HasPayed);
        }
Пример #6
0
        public void Clone_ShoulDuplicateValues()
        {
            var pot = ModelTestHelper.CreatePot(1, 1, "cloneOrga", name: "ClonePot");

            pot.AddParticipant(ModelTestHelper.CreatePotUser(1, 1));
            pot.AddParticipant(ModelTestHelper.CreatePotUser(2, 1));
            TestClone(pot);
        }
Пример #7
0
        public void Clone_ShoulDuplicateValues()
        {
            var pot = ModelTestHelper.CreatePot(1, 1, "cloneOrga", name: "ClonePot");

            pot.AddParticipant(ModelTestHelper.CreatePotUser(1, 1));
            pot.AddParticipant(ModelTestHelper.CreatePotUser(2, 1));
            var trip = ModelTestHelper.CreateTrip(1, "MyTrip", maxNbPeople: 20, note: 6.4);

            trip.TripPot = pot;
            trip.AddParticipant(ModelTestHelper.CreateTripParticipant(1, "toto"));
            trip.AddParticipant(ModelTestHelper.CreateTripParticipant(1, "tutu"));
            TestClone(trip);
        }
Пример #8
0
        public void GetPotUser_ShouldReturnPotUser()
        {
            var mock    = CreateMock();
            var potUser = ModelTestHelper.CreatePotUser(1, 1);

            mock.Setup(s => s.GetEntity(It.IsAny <PotUserKey>())).Returns(potUser);
            var repo      = CreateRepository(mock.Object);
            var dbPotUser = repo.GetPotUser(1, 1);

            Assert.IsFalse(repo.HasErrors);
            Assert.IsNotNull(dbPotUser);
            Assert.AreEqual(1, dbPotUser.UserId);
            Assert.AreEqual(1, dbPotUser.PotId);
        }
Пример #9
0
        public void Debit_WhenValidAndUserHasNotTotallyPaid_ShouldNotLogError()
        {
            var pot     = ModelTestHelper.CreatePot(2, 1, amount: 600, targetAmount: 700);
            var potUser = ModelTestHelper.CreatePotUser(1, pot.Id, amount: 300, targetAmount: 300);

            _mockPotUserRepo.Setup(s => s.GetPotUser(pot.Id, 1)).Returns(potUser);
            _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(false);
            _mockPotRepo.SetupGet(s => s.HasErrors).Returns(false);
            CreateServices();
            _potServices.Debit(pot, 1, 200);
            Assert.IsFalse(_potServices.HasErrors);
            Assert.AreEqual(400, pot.CurrentAmount);
            Assert.AreEqual(100, potUser.Amount);
            Assert.IsFalse(potUser.HasPayed);
        }
Пример #10
0
        public void GetPotMembers_WhenValid_ShouldReturnMembersList()
        {
            var firstMember  = ModelTestHelper.CreatePotUser(1, 1);
            var secondMember = ModelTestHelper.CreatePotUser(2, 1);

            _mockPotUserRepo.Setup(s => s.GetPotUsers(1)).Returns(new List <PotUser> {
                firstMember, secondMember
            });
            _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(false);
            CreateServices();
            var list = _potServices.GetPotMembers(1);

            Assert.IsFalse(_potServices.HasErrors);
            Assert.AreEqual(2, list.Count());
        }
Пример #11
0
        public void GetUserPots_ShouldReturnRightNumberOfRecords()
        {
            var firstPotUser  = ModelTestHelper.CreatePotUser(2, 1);
            var secondPotUser = ModelTestHelper.CreatePotUser(3, 1);
            var thirdPotUser  = ModelTestHelper.CreatePotUser(3, 2);

            Assert.IsTrue(_importExport.Save(firstPotUser));
            Assert.IsTrue(_importExport.Save(secondPotUser));
            Assert.IsTrue(_importExport.Save(thirdPotUser));

            var list = _importExport.GetUserPots(3);

            Assert.AreEqual(2, list.Count());
            Assert.IsFalse(list.Any(p => p.UserId == 2));
            Assert.IsTrue(list.Any(p => p.PotId == 2));
            Assert.IsTrue(list.Any(p => p.PotId == 1));
        }
Пример #12
0
        public void Credit_WhenErrorWhileSearchingForPotUser_ShouldLogError()
        {
            var          pot     = ModelTestHelper.CreatePot(2, 1);
            var          potUser = ModelTestHelper.CreatePotUser(1, pot.Id);
            const string error   = "Error while searching for pot";
            var          errors  = new List <string> {
                error
            };

            _mockPotUserRepo.Setup(s => s.GetPotUser(pot.Id, 1)).Returns(potUser);
            _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(true);
            _mockPotUserRepo.SetupGet(s => s.Errors).Returns(errors);
            CreateServices();
            _potServices.Credit(pot, 1, 100);
            Assert.IsTrue(_potServices.HasErrors);
            Assert.IsTrue(_potServices.Errors.Contains(error));
        }
Пример #13
0
        public void GetPot_WhenValid_ShouldReturnPot()
        {
            var pot     = ModelTestHelper.CreatePot(1, 1);
            var potUser = ModelTestHelper.CreatePotUser(1, 1);

            _mockPotRepo.Setup(s => s.GetPot(1)).Returns(pot);
            _mockPotRepo.SetupGet(s => s.HasErrors).Returns(false);
            _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(false);
            _mockPotUserRepo.Setup(s => s.GetPotUsers(1)).Returns(new List <PotUser> {
                potUser
            });
            CreateServices();
            var dbPot = _potServices.GetPot(1);

            Assert.IsFalse(_potServices.HasErrors);
            Assert.IsNotNull(dbPot);
            Assert.AreEqual(1, dbPot.Participants.Count());
        }
Пример #14
0
        public void GetUserPots_ShouldReturnValidList()
        {
            var list = new List <PotUser>
            {
                ModelTestHelper.CreatePotUser(1, 1),
                ModelTestHelper.CreatePotUser(1, 2)
            };
            var mock = CreateMock();

            mock.Setup(s => s.GetUserPots(It.IsAny <int>())).Returns(list);
            var repo   = CreateRepository(mock.Object);
            var dbList = repo.GetUserPots(1);

            Assert.IsFalse(repo.HasErrors);
            Assert.AreEqual(2, dbList.Count());
            Assert.IsTrue(dbList.Any(p => p.PotId == 1));
            Assert.IsTrue(dbList.Any(p => p.PotId == 1));
        }
Пример #15
0
        public void Debit_WhenUnableToUpdatePot_ShouldLogError()
        {
            var          pot     = ModelTestHelper.CreatePot(2, 1, amount: 400);
            var          potUser = ModelTestHelper.CreatePotUser(1, pot.Id);
            const string error   = "Unable to update pot";
            var          errors  = new List <string> {
                error
            };

            _mockPotUserRepo.Setup(s => s.GetPotUser(pot.Id, 1)).Returns(potUser);
            _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(false);
            _mockPotRepo.SetupGet(s => s.HasErrors).Returns(true);
            _mockPotRepo.SetupGet(s => s.Errors).Returns(errors);
            CreateServices();
            _potServices.Debit(pot, 1, 100);
            Assert.IsTrue(_potServices.HasErrors);
            Assert.IsTrue(_potServices.Errors.Contains(error));
            Assert.AreEqual(400, pot.CurrentAmount);
        }
Пример #16
0
        public void Clone_ShoulDuplicateValue()
        {
            var potUser = ModelTestHelper.CreatePotUser(1, 3, true, 300, 1200, true, "because", false);

            TestClone(potUser);
        }
Пример #17
0
 protected override PotUser CreateModel()
 {
     return(ModelTestHelper.CreatePotUser(1, 2));
 }
Пример #18
0
 public override PotUser CreateModel()
 {
     return(ModelTestHelper.CreatePotUser(2, 3));
 }
Пример #19
0
 public override PotUser CreateSubModelWithId(int id, int secondId)
 {
     return(ModelTestHelper.CreatePotUser(secondId, id));
 }