/// <summary>
        /// Initialises a new instance of the com.esendex.sdk.contacts.ContactCollection
        /// </summary>
        /// <param name="contact">A com.esendex.sdk.contacts.Contact instance that contains a contact.</param>
        public ContactCollection(Contact contact)
            : base()
        {
            if (contact == null) throw new ArgumentNullException("contact");

            Items.Add(contact);
        }
        public void CreateContacts_WithContactsCollection_ReturnsTrueWhenFailed()
        {
            // Arrange
            Contact contact = new Contact();

            ContactCollection collection = new ContactCollection(contact);

            string serialisedContent = "serialisedContent";

            RestResource resource = new ContactsResource(serialisedContent);

            RestResponse response = null;

            mockSerialiser
                .Setup(s => s.Serialise(collection))
                .Returns(serialisedContent);

            mockRestClient
                .Setup(r => r.Post(resource))
                .Returns(response);

            // Act
            bool actualResult = service.CreateContacts(collection);

            // Assert
            Assert.IsFalse(actualResult);
        }
        public void CreateContacts_WithContactsCollection_ReturnsTrueWhenSuccessful()
        {
            // Arrange
            Contact requestedContact = new Contact();

            ContactCollection requestedCollection = new ContactCollection(requestedContact);

            string serialisedContent = "serialisedContent";

            RestResource resource = new ContactsResource(serialisedContent);

            RestResponse response = new RestResponse()
            {
                StatusCode = HttpStatusCode.OK
            };

            mockSerialiser
                .Setup(s => s.Serialise(requestedCollection))
                .Returns(serialisedContent);

            mockRestClient
                .Setup(r => r.Post(resource))
                .Returns(response);

            // Act
            bool actualResult = service.CreateContacts(requestedCollection);

            // Assert
            Assert.IsTrue(actualResult);
        }
        public void CreateContact_WithContact_ReturnsContactWithId()
        {
            // Arrange
            var requestedContact = new Contact();

            var serialisedContent = "serialisedContent";

            RestResource resource = new ContactsResource(serialisedContent);

            var response = new RestResponse
            {
                StatusCode = HttpStatusCode.OK
            };

            var expectedContact = new Contact();

            mockSerialiser
                .Setup(s => s.Serialise(requestedContact))
                .Returns(serialisedContent);

            mockRestClient
                .Setup(r => r.Post(resource))
                .Returns(response);

            mockSerialiser
                .Setup(s => s.Deserialise<ContactResponse>(response.Content))
                .Returns(new ContactResponse {Contact = expectedContact});

            // Act
            var actualContact = service.CreateContact(requestedContact);

            // Assert
            Assert.AreEqual(expectedContact, actualContact);
        }
        /// <summary>
        /// Creates a com.esendex.sdk.contacts.Contact instance and returns the new com.esendex.sdk.contacts.Contact instance.
        /// </summary>
        /// <param name="contact">A com.esendex.sdk.contacts.Contact instance that contains the contact.</param>
        /// <returns>A com.esendex.sdk.contacts.Contact instance that contains the contact with an Id assigned.</returns>        
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Net.WebException"></exception>        
        public Contact CreateContact(Contact contact)
        {
            var requestXml = Serialiser.Serialise(contact);

            RestResource resource = new ContactsResource(requestXml);

            return MakeRequest<ContactResponse>(HttpMethod.POST, resource)
                .Contact;
        }
        /// <summary>
        /// Returns true if the contact was successfully updated; otherwise, false.
        /// </summary>
        /// <param name="contact">A com.esendex.sdk.contacts.Contact instance that contains the contact.</param>
        /// <returns>true, if the contact was successfully updated; otherwise, false.</returns>        
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Net.WebException"></exception>      
        public bool UpdateContact(Contact contact)
        {
            var requestXml = Serialiser.Serialise(contact);

            RestResource resource = new ContactsResource(contact.Id, requestXml);

            var response = MakeRequest(HttpMethod.PUT, resource);

            return (response != null);
        }
        /// <summary>
        /// Creates a com.esendex.sdk.contacts.Contact instance and returns the new com.esendex.sdk.contacts.Contact instance.
        /// </summary>
        /// <param name="contact">A com.esendex.sdk.contacts.Contact instance that contains the contact.</param>
        /// <returns>A com.esendex.sdk.contacts.Contact instance that contains the contact with an Id assigned.</returns>        
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Net.WebException"></exception>        
        public Contact CreateContact(Contact contact)
        {
            ContactCollection contacts = new ContactCollection(contact);

            string requestXml = Serialiser.Serialise<ContactCollection>(contacts);

            RestResource resource = new ContactsResource(requestXml);

            return MakeRequest<Contact>(HttpMethod.POST, resource);
        }
        public void ContactCollection_DefaultDIConstructor_WithContact()
        {
            // Arrange
            var contact = new Contact();

            // Act
            var contactCollectionInstance = new ContactCollection(contact);

            // Assert
            Assert.AreEqual(contact, contactCollectionInstance.Items.ElementAt(0));
        }
        public void ContactCollection_DefaultDIConstructor_WithContactsArray()
        {
            // Arrange
            Contact contact = new Contact();

            List<Contact> contacts = new List<Contact>();

            contacts.Add(contact);

            // Act
            ContactCollection contactCollectionInstance = new ContactCollection(contacts);

            // Assert
            Assert.AreEqual(contact, contactCollectionInstance.Items.ElementAt(0));
        }
        public void Contact_DefaultDIConstructor()
        {
            // Arrange
            const string accountReference = "account";
            const string quickname = "quickname";
            const string phonenumber = "phonenumber";

            // Act
            var contactInstance = new Contact(accountReference, quickname, phonenumber);

            // Assert
            Assert.AreEqual(accountReference, contactInstance.AccountReference);
            Assert.AreEqual(quickname, contactInstance.QuickName);
            Assert.AreEqual(phonenumber, contactInstance.PhoneNumber);
        }
        public void CreateContact_WithContact_ReturnsContactWithId()
        {
            // Arrange
            Contact requestedContact = new Contact();

            ContactCollection requestedCollection = new ContactCollection(requestedContact);

            string serialisedContent = "serialisedContent";

            RestResource resource = new ContactsResource(serialisedContent);

            RestResponse response = new RestResponse()
            {
                StatusCode = HttpStatusCode.OK
            };

            Contact expectedContact = new Contact();

            mockSerialiser
                .Setup(s => s.Serialise(requestedCollection))
                .Returns(serialisedContent);

            mockRestClient
                .Setup(r => r.Post(resource))
                .Returns(response);

            mockSerialiser
                .Setup(s => s.Deserialise<Contact>(response.Content))
                .Returns(expectedContact);

            // Act
            Contact actualContact = service.CreateContact(requestedContact);

            // Assert
            Assert.AreEqual(expectedContact, actualContact);
        }
        public void UpdateContact_WithContact_ReturnsFalseWhenFailed()
        {
            // Arrange
            var requestedContact = new Contact
            {
                Id = Guid.NewGuid()
            };

            var serialisedContent = "serialisedContent";

            RestResource resource = new ContactsResource(requestedContact.Id, serialisedContent);

            RestResponse response = null;

            mockSerialiser
                .Setup(s => s.Serialise(requestedContact))
                .Returns(serialisedContent);

            mockRestClient
                .Setup(r => r.Put(resource))
                .Returns(response);

            // Act
            var actualResult = service.UpdateContact(requestedContact);

            // Assert
            Assert.IsFalse(actualResult);
        }
        public void UpdateContact_WithContact_ReturnsTrueWhenSuccessful()
        {
            // Arrange
            var requestedContact = new Contact
            {
                Id = Guid.NewGuid()
            };

            var serialisedContent = "serialisedContent";

            RestResource resource = new ContactsResource(requestedContact.Id, serialisedContent);

            var response = new RestResponse
            {
                StatusCode = HttpStatusCode.OK
            };

            mockSerialiser
                .Setup(s => s.Serialise(requestedContact))
                .Returns(serialisedContent);

            mockRestClient
                .Setup(r => r.Put(resource))
                .Returns(response);

            // Act
            var actualResult = service.UpdateContact(requestedContact);

            // Assert
            Assert.IsTrue(actualResult);
        }
        /// <summary>
        /// Posts a com.esendex.sdk.contacts.Contact to a com.esendex.sdk.groups.Group.
        /// </summary>
        /// <param name="accountReference">The number of the page.</param>
        /// <param name="groupId">The number of items in the page.</param>
        /// <param name="contact"></param>
        /// <returns>A com.esendex.sdk.groups.PagedGroupCollection instance that contains the groups.</returns>        
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Net.WebException"></exception>
        public bool AddContactToGroup(string accountReference, string groupId, Contact contact)
        {
            var contactColletion = new ContactCollection();
            contactColletion.ItemsId.Add(contact.Id.ToString());

            RestResource resource = new GroupsResource(accountReference, groupId, Serialiser.Serialise(contactColletion));
            var response = MakeRequest(HttpMethod.POST, resource);
            return response != null;
        }
Beispiel #15
0
 protected bool Equals(Contact other)
 {
     return Id.Equals(other.Id)
            && string.Equals(FirstName, other.FirstName)
            && string.Equals(LastName, other.LastName)
            && string.Equals(QuickName, other.QuickName)
            && string.Equals(PhoneNumber, other.PhoneNumber)
            && string.Equals(AccountReference, other.AccountReference);
 }
        public void Contact_DefaultDIConstructor()
        {
            // Arrange
            string quickname = "quickname";
            string phonenumber = "phonenumber";

            // Act
            Contact contactInstance = new Contact(quickname, phonenumber);

            // Assert
            Assert.AreEqual(quickname, contactInstance.QuickName);
            Assert.AreEqual(phonenumber, contactInstance.PhoneNumber);
            Assert.That(contactInstance.Groups, Is.InstanceOf<IEnumerable<ContactGroupSummary>>());
        }
        public void GetContact_WithId_ReturnsContact()
        {
            // Arrange
            var id = Guid.NewGuid();

            RestResource resource = new ContactsResource(id);

            var response = new RestResponse
            {
                StatusCode = HttpStatusCode.OK
            };

            var expectedContact = new Contact();

            mockRestClient
                .Setup(r => r.Get(resource))
                .Returns(response);

            mockSerialiser
                .Setup(s => s.Deserialise<Contact>(response.Content))
                .Returns(expectedContact);

            // Act
            var actualContact = service.GetContact(id);

            // Assert
            Assert.AreEqual(expectedContact, actualContact);
        }
        public void Contact_DefaultDIConstructor_WithNullQuickNameAndMobileNumber_ThrowsException()
        {
            // Arrange
            string quickname = string.Empty;
            string phonenumber = null;

            // Act
            try
            {
                Contact contactInstance = new Contact(quickname, phonenumber);

                Assert.Fail();
            }
            // Assert
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("quickName", ex.ParamName);
            }
        }