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); }
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); }
/// <summary> /// Returns true if the contact was successfully deleted; otherwise, false. /// </summary> /// <param name="id">A System.Guid instance that contains the Id of a contact.</param> /// <returns>true, if the contact was successfully deleted; otherwise, false.</returns> /// <exception cref="System.Net.WebException"></exception> public bool DeleteContact(Guid id) { RestResource resource = new ContactsResource(id); var response = MakeRequest(HttpMethod.DELETE, 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) { 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> /// 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); }
public void DefaultConstructor_WithId() { // Arrange Guid id = Guid.NewGuid(); string expectedResourcePath = string.Format("contacts/{0}", id); // Act RestResource resource = new ContactsResource(id); // Assert Assert.AreEqual(expectedResourcePath, resource.ResourcePath); }
public void DefaultConstructor_WithContent() { // Arrange string expectedResourcePath = "contacts"; string expectedContent = "content"; // Act RestResource resource = new ContactsResource(expectedContent); // Assert Assert.AreEqual(expectedResourcePath, resource.ResourcePath); Assert.AreEqual(expectedContent, resource.Content); }
public void DefaultConstructor_WithPageNumber2AndPageSize15() { // Arrange var accountReference = "frgjbhjrehre"; var pageNumber = 2; var pageSize = 15; var expectedResourcePath = string.Format("contacts?accountReference={0}&startIndex=15&count={1}", accountReference, pageSize); // Act RestResource resource = new ContactsResource(accountReference, pageNumber, pageSize); // Assert Assert.AreEqual(expectedResourcePath, resource.ResourcePath); }
public void DefaultConstructor_WithInvalidPageNumberAndPageSize() { // Arrange int pageNumber = 0; int pageSize = 0; // Act try { RestResource resource = new ContactsResource(pageNumber, pageSize); Assert.Fail(); } // Assert catch (ArgumentException ex) { Assert.AreEqual("pageNumber", ex.ParamName); } }
public void DeleteContact_WithId_ReturnsFalseWhenUnsuccessful() { // Arrange var id = Guid.NewGuid(); RestResource resource = new ContactsResource(id); RestResponse response = null; mockRestClient .Setup(r => r.Delete(resource)) .Returns(response); // Act var actualResult = service.DeleteContact(id); // Assert Assert.IsFalse(actualResult); }
/// <summary> /// Gets a com.esendex.sdk.contact.Contact instance containing a contact. /// </summary> /// <param name="id">A System.Guid instance that contains the Id of a contact.</param> /// <returns>A com.esendex.sdk.contacts.Contact instance that contains the contact.</returns> /// <exception cref="System.Net.WebException"></exception> public Contact GetContact(Guid id) { RestResource resource = new ContactsResource(id); return MakeRequest<Contact>(HttpMethod.GET, resource); }
public void GetContacts_WithPageNumberWithPageSize_ReturnsContacts() { // Arrange int pageNumber = 1; int pageSize = 15; RestResource resource = new ContactsResource(pageNumber, pageSize); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "content" }; PagedContactCollection expectedContacts = new PagedContactCollection() { PageNumber = pageNumber, PageSize = pageSize }; mockRestClient .Setup(r => r.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<PagedContactCollection>(response.Content)) .Returns(expectedContacts); // Act PagedContactCollection actualContact = service.GetContacts(pageNumber, pageSize); // Assert Assert.AreEqual(pageNumber, actualContact.PageNumber); Assert.AreEqual(pageSize, actualContact.PageSize); }
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); }
/// <summary> /// Gets a com.esendex.sdk.contact.PagedContactCollection instance containing contacts. /// </summary> /// <param name="pageNumber">The number of the page.</param> /// <param name="pageSize">The number of items in the page.</param> /// <returns>A com.esendex.sdk.contacts.PagedContactCollection instance that contains the contacts.</returns> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.Net.WebException"></exception> public PagedContactCollection GetContacts(string accountReference, int pageNumber, int pageSize) { RestResource resource = new ContactsResource(accountReference, pageNumber, pageSize); return MakeRequest<PagedContactCollection>(HttpMethod.GET, resource); }
public void DefaultConstructor_WithIdAndContent() { // Arrange var id = Guid.NewGuid(); var expectedResourcePath = string.Format("contacts/{0}", id); var expectedContent = "content"; // Act RestResource resource = new ContactsResource(id, expectedContent); // Assert Assert.AreEqual(expectedResourcePath, resource.ResourcePath); Assert.AreEqual(expectedContent, resource.Content); }
public void GetContacts_WithPageNumberWithPageSize_ReturnsContacts() { // Arrange var accountReference = "frgjbhjrehre"; var pageNumber = 1; var pageSize = 15; RestResource resource = new ContactsResource(accountReference, pageNumber, pageSize); var response = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "content" }; var expectedContacts = new PagedContactCollection { PageNumber = pageNumber, PageSize = pageSize }; mockRestClient .Setup(r => r.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<PagedContactCollection>(response.Content)) .Returns(expectedContacts); // Act var actualContact = service.GetContacts(accountReference, pageNumber, pageSize); // Assert Assert.AreEqual(pageNumber, actualContact.PageNumber); Assert.AreEqual(pageSize, actualContact.PageSize); }
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); }
public void DeleteContact_WithId_ReturnsTrueWhenSuccessful() { // Arrange var id = Guid.NewGuid(); RestResource resource = new ContactsResource(id); var response = new RestResponse { StatusCode = HttpStatusCode.OK }; mockRestClient .Setup(r => r.Delete(resource)) .Returns(response); // Act var actualResult = service.DeleteContact(id); // Assert Assert.IsTrue(actualResult); }
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 DefaultConstructor_WithPageNumber1AndPageSize15() { // Arrange Guid id = Guid.NewGuid(); int pageNumber = 1; int pageSize = 15; string expectedResourcePath = string.Format("contacts?startIndex=0&count={0}", pageSize); // Act RestResource resource = new ContactsResource(pageNumber, pageSize); // Assert Assert.AreEqual(expectedResourcePath, resource.ResourcePath); }
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); }