Example #1
0
        public void Service_CannotAddNonUniqueContact_WillThrow()
        {
            // Arrange
            AddressBook addressBook = new AddressBookBuilder()
                                      .AddContact3()
                                      .Build();
            Contact contact             = AddressBookBuilder.BuildContact3(addressBook.Id);
            IAddressBookRepository repo = Substitute.For <IAddressBookRepository>();

            repo.GetContactAsync(contact.Name, contact.Address).Returns(addressBook);
            AddressBookService target = new AddressBookService(repo);

            // Act, Assert
            Assert.ThrowsAsync <ArgumentException>(() => target.AddContactAsync(contact));
        }
Example #2
0
        public async void Service_CanAddUniqueContact()
        {
            // Arrange
            AddressBook addressBook = new AddressBookBuilder()
                                      .Build();
            Contact contact             = AddressBookBuilder.BuildContact4(addressBook.Id);
            IAddressBookRepository repo = Substitute.For <IAddressBookRepository>();

            repo.GetContactAsync(contact.Name, contact.Address).Returns(addressBook);
            AddressBookService target = new AddressBookService(repo);

            // Act
            await target.AddContactAsync(contact);

            // Assert - repo called.
            await repo.Received().SaveAsync(addressBook);

            Assert.Contains(contact, addressBook.Contacts);
        }