コード例 #1
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);
        }
コード例 #2
0
        public async void Service_CanUpdateContact()
        {
            // Arrange
            AddressBook addressBook = new AddressBookBuilder()
                                      .AddContact1()
                                      .Build();
            Contact contactWithUpdateDetails = AddressBookBuilder.BuildContact1(addressBook.Id);
            IAddressBookRepository repo      = Substitute.For <IAddressBookRepository>();

            repo.GetContactAsync(contactWithUpdateDetails.Id).Returns(addressBook);
            AddressBookService target = new AddressBookService(repo);

            // Act
            await target.UpdateContactAsync(contactWithUpdateDetails);

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

            Assert.Equal(TrackingState.Modified, addressBook.Contacts.First().Tracking);
        }