Example #1
0
        public async Task CreateUpdateAndDeleteContact()
        {
            var rand      = new Random();
            var randValue = rand.Next(100);
            var contact   = new YouMailContact
            {
                FirstName    = "Test",
                LastName     = $"Contact {randValue}",
                MobileNumber = $"(123) 456-78{randValue}"
            };

            var id = await service.CreateContactAsync(contact);

            Assert.IsTrue(id != 0, "Contact id returned was 0, contact wasn't properly created");

            // Wait for the contact to be created
            await Task.Delay(1000);

            var newContact = await service.GetContactAsync(id);

            Assert.IsNotNull(newContact, "Should have found the updated contact");
            newContact.Organization = "Test Org";

            await service.UpdateContactAsync(newContact, newContact.Id);

            await Task.Delay(1000);

            var updatedContact = await service.GetContactAsync(id);

            await service.DeleteContactAsync(id);

            // Try to get the contact again, it should be deleted
            var contactLookup = await service.GetContactAsync(id);

            Assert.IsNull(contactLookup, "Contact should not have been found");

            // Now that we have completed the test, verify that everything is proper
            Assert.IsTrue(newContact.Id == id, "Contact Id doesn't match");
            Assert.AreEqual(newContact.Organization, updatedContact.Organization, "Organization doesn't match");
            Assert.AreEqual(newContact.FirstName, contact.FirstName, "Contact first name doesn't match");
            Assert.AreEqual(newContact.LastName, contact.LastName, "Contact last name doesn't match");
            Assert.AreEqual(updatedContact.Organization, newContact.Organization, "The contact was not updated as expected");
        }