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 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);
        }
Ejemplo n.º 3
0
        public void ContactCollection_DefaultConstructor()
        {
            // Arrange

            // Act
            var contactCollectionInstance = new ContactCollection();

            // Assert
            Assert.That(contactCollectionInstance.Items, Is.InstanceOf<List<Contact>>());
        }
        /// <summary>
        /// Adds a com.esendex.sdk.contacts.ContactCollection instance and returns true if the contacts were added successfully; otherwise, false.
        /// </summary>
        /// <param name="contacts">A com.esendex.sdk.contacts.ContactCollection instance.</param>
        /// <returns>true, if the contacts were added successfully; otherwise, false.</returns>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Net.WebException"></exception>
        public bool CreateContacts(ContactCollection contacts)
        {
            string requestXml = Serialiser.Serialise <ContactCollection>(contacts);

            RestResource resource = new ContactsResource(requestXml);

            RestResponse response = MakeRequest(HttpMethod.POST, 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));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a com.esendex.sdk.contacts.ContactCollection instance and returns true if the contacts were added successfully; otherwise, false.
        /// </summary>
        /// <param name="contacts">A com.esendex.sdk.contacts.ContactCollection instance.</param>
        /// <returns>true, if the contacts were added successfully; otherwise, false.</returns>        
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Net.WebException"></exception>
        public bool CreateContacts(ContactCollection contacts)
        {
            string requestXml = Serialiser.Serialise<ContactCollection>(contacts);

            RestResource resource = new ContactsResource(requestXml);

            RestResponse response = MakeRequest(HttpMethod.POST, resource);

            return (response != null);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        public void ContactCollection_DefaultDIConstructor_WithContact()
        {
            // Arrange
            var contact = new Contact();

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

            // Assert
            Assert.AreEqual(contact, contactCollectionInstance.Items.ElementAt(0));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        public void ContactCollection_DefaultDIConstructor_WithNullContact_ThrowsArgumentNullException()
        {
            // Arrange
            Contact contact = null;

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

                Assert.Fail();
            }
                // Assert
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("contact", ex.ParamName);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Determines whether the specified System.Object are considered equal.
        /// </summary>
        /// <param name="obj">The System.Object to compare with the current System.Object</param>
        /// <returns>true if the specified System.Object is equal to the current System.Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            ContactCollection other = obj as ContactCollection;

            if (other == null)
            {
                return(false);
            }

            if (Items.Count != other.Items.Count)
            {
                return(false);
            }

            for (int i = 0; i < Items.Count; i++)
            {
                if (Items.ElementAt(i) != other.Items.ElementAt(i))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <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;
        }
        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);
        }