public void GetSplitContact_ReturnsSplitContactDto() { var splitContactStub = new SplitContact { Id = 1, ContactId = 2, Contact = new Contact { Iban = "BE68 5390 0754 7034", Address = "Rue des longiers, 45" }, SplitId = 5, Owes = 25m, Paid = 50m, Comments = "me devait déjà 5 euros" }; _contactServiceMock.Setup(s => s.GetSplitContactById(splitContactStub.Id)).Returns(splitContactStub); var contactStub = new Contact { Id = 2, Email = "*****@*****.**" }; _contactServiceMock.Setup(s => s.GetContactById(contactStub.Id)).Returns(contactStub); var splitContactDto = _controller.GetSplitContact(splitContactStub.SplitId, splitContactStub.Id); Assert.Equal(contactStub.Email, splitContactDto.Email); Assert.Equal(splitContactStub.Owes, splitContactDto.Owes); Assert.Equal(splitContactStub.Paid, splitContactDto.Paid); Assert.Equal(splitContactStub.Contact.Iban, splitContactDto.Iban); Assert.Equal(splitContactStub.Contact.Address, splitContactDto.Address); Assert.Equal(splitContactStub.Comments, splitContactDto.Comments); }
public void PaidBalance(decimal owes, decimal paid, decimal expectedPaidBalance) { var splitContact = new SplitContact { Owes = owes, Paid = paid }; Assert.Equal(expectedPaidBalance, splitContact.PaidBalance); }
public void GetSplitContactById_ReturnsSplitContact() { var splitContactStub = new SplitContact { Id = 5, ContactId = 30, Owes = 25m, Paid = 50m, Comments = "my comment" }; _splitContactRepositoryMock.Setup(r => r.Get(It.IsAny <Expression <Func <SplitContact, bool> > >())).Returns(new List <SplitContact> { splitContactStub }); var splitContact = _contactService.GetSplitContactById(splitContactStub.Id); Assert.Equal(splitContactStub.ContactId, splitContact.ContactId); Assert.Equal(splitContactStub.Owes, splitContact.Owes); Assert.Equal(splitContactStub.Paid, splitContact.Paid); Assert.Equal(splitContactStub.Comments, splitContact.Comments); }
public void CreateIfNeededAndAddToSplit_NameIsNotProvided_EmailIsUsedAsName() { _contactRepositoryMock.Setup(r => r.Get(It.IsAny <Expression <Func <Contact, bool> > >())).Returns(new List <Contact>()); var contactStub = new Contact { Id = 5, Email = "*****@*****.**", Name = "John Smith" }; _contactRepositoryMock.Setup(r => r.Insert(It.Is <Contact>(c => c.Name == contactStub.Email))).Returns(contactStub); var splitContactStub = new SplitContact { ContactId = 5, SplitId = 1 }; _splitContactRepositoryMock.Setup(r => r.Insert(It.IsAny <SplitContact>())).Returns(splitContactStub); var contact = _contactService.CreateIfNeededAndAddToSplit(splitContactStub.SplitId, contactStub.Email, null); _contactRepositoryMock.VerifyAll(); }
public void UpdateSplitContact_CallsRepository() { var splitContactStub = new SplitContact { Id = 5, ContactId = 30, Contact = new Contact(), Owes = 25m, Paid = 50m, Comments = "my comment" }; _splitContactRepositoryMock.Setup(r => r.GetWithIncludedProperties(It.IsAny <Expression <Func <SplitContact, IEntity> > >(), It.IsAny <Expression <Func <SplitContact, bool> > >())).Returns(new List <SplitContact> { splitContactStub }); var splitContactWithNewValues = new SplitContact { Id = 5, ContactId = 30, Owes = 99m, Paid = 22m, Contact = new Contact { Iban = "BE68 5390 0754 7034", Address = "Rue des longiers, 45" }, Comments = "updated values" }; _contactService.UpdateSplitContact(splitContactStub.Id, splitContactWithNewValues.Owes, splitContactWithNewValues.Paid, splitContactWithNewValues.Contact.Iban, splitContactWithNewValues.Contact.Address, splitContactWithNewValues.Comments); _splitContactRepositoryMock.Verify(r => r.Update(It.Is <SplitContact>(sc => sc.Owes == splitContactWithNewValues.Owes && sc.Paid == splitContactWithNewValues.Paid && sc.Contact.Iban == splitContactWithNewValues.Contact.Iban && sc.Contact.Address == splitContactWithNewValues.Contact.Address && sc.Comments == splitContactWithNewValues.Comments))); }
public void CreateIfNeededAndAddToSplit_ContactDoesNotExist_CreatesAndReturnsContact() { _contactRepositoryMock.Setup(r => r.Get(It.IsAny <Expression <Func <Contact, bool> > >())).Returns(new List <Contact>()); var contactStub = new Contact { Id = 5, Email = "*****@*****.**", Name = "John Smith" }; _contactRepositoryMock.Setup(r => r.Insert(It.IsAny <Contact>())).Returns(contactStub); var splitContactStub = new SplitContact { ContactId = 5, SplitId = 1 }; _splitContactRepositoryMock.Setup(r => r.Insert(It.IsAny <SplitContact>())).Returns(splitContactStub); var contact = _contactService.CreateIfNeededAndAddToSplit(splitContactStub.SplitId, contactStub.Email, contactStub.Name); Assert.Equal(contactStub.Email, contact.Email); Assert.Equal(contactStub.Name, contact.Name); }
public void CreateIfNeededAndAddToSplit_ContactExists_LinksAndReturnsContact() { var contactStub = new Contact { Id = 5, Email = "*****@*****.**", Name = "John Smith" }; _contactRepositoryMock.Setup(r => r.Get(It.IsAny <Expression <Func <Contact, bool> > >())).Returns(new List <Contact> { contactStub }); _contactRepositoryMock.Setup(r => r.Insert(It.IsAny <Contact>())).Throws(new Exception("Should not have been called")); var splitContactStub = new SplitContact { ContactId = 5, SplitId = 1 }; _splitContactRepositoryMock.Setup(r => r.Insert(It.IsAny <SplitContact>())).Returns(splitContactStub); var contact = _contactService.CreateIfNeededAndAddToSplit(splitContactStub.SplitId, contactStub.Email, contactStub.Name); Assert.Equal(contactStub.Email, contact.Email); Assert.Equal(contactStub.Name, contact.Name); }