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); }
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)); }
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); }
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); }
public void Equals_ShouldReturnCorrectValue(int firstId, int secondId, bool expected) { var firstPot = ModelTestHelper.CreatePot(firstId, 1); var secondPot = ModelTestHelper.CreatePot(secondId, 2); Assert.AreEqual(expected, firstPot.Equals(secondPot)); }
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); }
public void Clone_WhenParticipantsIsNull_ShouldCreateNewList() { var pot = ModelTestHelper.CreatePot(1, 1, participants: null); Assert.IsNull(pot.Participants); var clone = pot.Clone() as Pot; Assert.IsNotNull(clone); Assert.IsNotNull(clone.Participants); }
public void Credit_WhenException_ShouldLogError() { var pot = ModelTestHelper.CreatePot(2, 1); _mockPotUserRepo.Setup(s => s.GetPotUser(pot.Id, 1)).Throws(new Exception("ExceptionForTest")); CreateServices(); _potServices.Credit(pot, 1, 100); Assert.IsTrue(_potServices.HasErrors); Assert.IsTrue(_potServices.Errors.Contains("ExceptionForTest")); }
public void SavePot_WhenPotNameIsUsed_ShouldLogError() { var mock = CreateMock(); mock.Setup(s => s.IsPotNameUsed(It.IsAny <string>())).Returns(true); var repo = CreateRepository(mock.Object); var pot = ModelTestHelper.CreatePot(1, 2); repo.SavePot(pot); CheckErrors(repo, string.Format("Pot name {0} is already use, please choose another one", pot.Name)); }
public void Credit_WhenPotUserIsNull_ShouldLogError() { var pot = ModelTestHelper.CreatePot(2, 1); const string error = "Unable to find user in the pot"; _mockPotUserRepo.Setup(s => s.GetPotUser(pot.Id, 1)).Returns(() => null); _mockPotUserRepo.SetupGet(s => s.HasErrors).Returns(false); _mockPotUserRepo.SetupGet(s => s.Errors).Returns(new List <string>()); CreateServices(); _potServices.Credit(pot, 1, 100); Assert.IsTrue(_potServices.HasErrors); Assert.IsTrue(_potServices.Errors.Contains(error)); }
public void GetPotByName_ShouldReturnPot() { var mock = CreateMock(); var pot = ModelTestHelper.CreatePot(1, 2); mock.Setup(s => s.GetPotByName(It.IsAny <string>())).Returns(pot); var repo = CreateRepository(mock.Object); var dbPot = repo.GetPot(pot.Name); Assert.IsFalse(repo.HasErrors); Assert.IsNotNull(dbPot); Assert.AreEqual(pot.Id, dbPot.Id); }
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); }
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); }
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)); }
public void GetPot_WhenErrorWhileLoadingPot_ShouldLogError() { var pot = ModelTestHelper.CreatePot(1, 1); const string error = "Unable to retrieve pot"; var errors = new List <string> { error }; _mockPotRepo.Setup(s => s.GetPot(1)).Returns(pot); _mockPotRepo.SetupGet(s => s.HasErrors).Returns(true); _mockPotRepo.SetupGet(s => s.Errors).Returns(errors); CreateServices(); var dbPot = _potServices.GetPot(1); Assert.IsTrue(_potServices.HasErrors); Assert.IsTrue(_potServices.Errors.Contains(error)); Assert.IsNull(dbPot); }
public void GetAllPots_ShouldReturnValidList() { var list = new List <Pot> { ModelTestHelper.CreatePot(1, 2), ModelTestHelper.CreatePot(2, 1), }; var mock = CreateMock(); mock.Setup(s => s.GetAllEntities()).Returns(list); var repo = CreateRepository(mock.Object); var dbList = repo.GetAllPots(); Assert.IsFalse(repo.HasErrors); Assert.AreEqual(2, dbList.Count()); Assert.IsTrue(dbList.Any(p => p.TripId == 2)); Assert.IsTrue(dbList.Any(p => p.Id == 1)); }
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()); }
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); }
public override Pot CreateModelWithId(int id) { return(ModelTestHelper.CreatePot(id, id + 1)); }
public override Pot CreateModel() { return(ModelTestHelper.CreatePot(1, 2)); }
protected override Pot CreateModel() { return(ModelTestHelper.CreatePot(1, 2)); }