public void Delete_HttpReturnsIn200Range_ReturnsRestResponse() { // Arrange DeleteRestResourceContext deleteResourceContext = new DeleteRestResourceContext(); HttpRequest httpRequest = new HttpRequest() { HttpMethod = HttpMethod.DELETE, ResourcePath = deleteResourceContext.ResourcePath, ContentType = "text/plain", }; RestResponse expectedResponse = new RestResponse() { StatusCode = HttpStatusCode.OK }; HttpResponse httpResponse = new HttpResponse() { StatusCode = HttpStatusCode.OK }; mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse); // Act RestResponse actualResponse = restClient.Delete(deleteResourceContext); // Assert Assert.IsNotNull(actualResponse); Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode); }
public void CreateSession_ReturnsSessionId() { // Arrange RestResource resource = new SessionResource(); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "serialisedResponse" }; EsendexSession expectedResult = new EsendexSession() { Id = Guid.NewGuid() }; mockRestClient .Setup(rc => rc.Post(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<EsendexSession>(response.Content)) .Returns(expectedResult); // Act Guid actualSessionId = service.CreateSession(); // Assert Assert.AreEqual(expectedResult.Id, actualSessionId); }
public void GetMessages_ReturnsInboxMessages() { // Arrange RestResource resource = new InboxMessagesResource(); var response = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "serialisedItem" }; var expectedResult = new InboxMessageCollection(); mockRestClient .Setup(rc => rc.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<InboxMessageCollection>(response.Content)) .Returns(expectedResult); // Act var actualResult = service.GetMessages(); // Assert Assert.AreEqual(expectedResult, 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); }
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 GetMessage_WithId_ReturnsSentMessage() { // Arrange var id = Guid.NewGuid(); RestResource resource = new MessageHeadersResource(id); var response = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "serialisedItem" }; var expectedResult = new SentMessage(); mockRestClient .Setup(rc => rc.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<SentMessage>(response.Content)) .Returns(expectedResult); // Act var actualResult = service.GetMessage(id); // Assert Assert.AreEqual(expectedResult, actualResult); }
public void GetMessages_WithPageNumberAndPageSizeAndAccountReference_ReturnsSentMessages() { // Arrange int pageNumber = 1; int pageSize = 15; string accountReference = "accountReference"; RestResource resource = new MessageHeadersResource(accountReference, pageNumber, pageSize); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "serialisedItem" }; SentMessageCollection expectedResult = new SentMessageCollection() { PageNumber = pageNumber, PageSize = pageSize, }; mockRestClient .Setup(rc => rc.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<SentMessageCollection>(response.Content)) .Returns(expectedResult); // Act SentMessageCollection actualResult = service.GetMessages(accountReference, pageNumber, pageSize); // Assert Assert.AreEqual(pageNumber, actualResult.PageNumber); Assert.AreEqual(pageSize, actualResult.PageSize); }
public void Get_HttpReturnsIn200Range_ReturnsRestResponse() { // Arrange string expectedContent = "content"; GetRestResourceContext getResourceContext = new GetRestResourceContext(); HttpRequest httpRequest = new HttpRequest() { HttpMethod = HttpMethod.GET, ResourcePath = getResourceContext.ResourcePath, ContentType = "text/plain" }; RestResponse expectedResponse = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = expectedContent }; HttpResponse httpResponse = new HttpResponse() { StatusCode = HttpStatusCode.OK, Content = expectedContent, ContentType = "application/xml", ContentEncoding = Encoding.UTF8.WebName }; mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse); // Act RestResponse actualResponse = restClient.Get(getResourceContext); // Assert Assert.IsNotNull(actualResponse); Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode); }
public void DeleteMessage_WithId_ReturnsTrueWhenSuccessful() { // Arrange var id = Guid.NewGuid(); RestResource resource = new InboxMessagesResource(id); var response = new RestResponse { StatusCode = HttpStatusCode.OK }; mockRestClient .Setup(rc => rc.Delete(resource)) .Returns(response); // Act var actualResult = service.DeleteMessage(id); // Assert Assert.IsTrue(actualResult); }
public void DeleteContact_WithId_ReturnsTrueWhenSuccessful() { // Arrange Guid id = Guid.NewGuid(); RestResource resource = new ContactsResource(id); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK }; mockRestClient .Setup(r => r.Delete(resource)) .Returns(response); // Act bool actualResult = service.DeleteContact(id); // Assert Assert.IsTrue(actualResult); }
public void Put_HttpReturnsNull_ReturnsNull() { // Arrange string content = "content"; PutRestResourceContext putResourceContext = new PutRestResourceContext(content); HttpRequest httpRequest = new HttpRequest() { HttpMethod = HttpMethod.PUT, ResourcePath = putResourceContext.ResourcePath, Content = putResourceContext.Content, ContentType = "application/xml", ContentEncoding = Encoding.UTF8 }; RestResponse expectedResponse = new RestResponse() { StatusCode = HttpStatusCode.NotFound }; HttpResponse httpResponse = null; mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse); // Act RestResponse actualResponse = restClient.Put(putResourceContext); // Assert Assert.IsNull(actualResponse); }
public void MarkMessageAsUnread_WithId_ReturnsTrueWhenSuccessful() { // Arrange Guid id = Guid.NewGuid(); RestResource resource = new InboxMessagesResource(id, InboxMessageStatus.Unread); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK }; mockRestClient .Setup(rc => rc.Put(resource)) .Returns(response); // Act bool actualResult = service.MarkMessageAsUnread(id); // Assert Assert.IsTrue(actualResult); }
public void GetMessages_WithPageNumberAndPageSize_ReturnsInboxMessages() { // Arrange int pageNumber = 1; int pageSize = 15; RestResource resource = new InboxMessagesResource(pageNumber, pageSize); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "serialisedItem" }; InboxMessageCollection expectedResult = new InboxMessageCollection() { PageNumber = pageNumber, PageSize = pageSize, }; mockRestClient .Setup(rc => rc.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<InboxMessageCollection>(response.Content)) .Returns(expectedResult); // Act InboxMessageCollection actualResult = service.GetMessages(pageNumber, pageSize); // Assert Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(pageNumber, actualResult.PageNumber); Assert.AreEqual(pageSize, actualResult.PageSize); }
public void GetMessages_WithAccountReference_ReturnsInboxMessages() { // Arrange string accountReference = "accountReference"; RestResource resource = new InboxMessagesResource(accountReference); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "serialisedItem" }; InboxMessageCollection expectedResult = new InboxMessageCollection(); mockRestClient .Setup(rc => rc.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<InboxMessageCollection>(response.Content)) .Returns(expectedResult); // Act InboxMessageCollection actualResult = service.GetMessages(accountReference); // Assert Assert.AreEqual(expectedResult, actualResult); }
public void SendScheduledMessages_WithVoiceMessage_ReturnsBatchIdResult() { // Arrange var timestamp = DateTime.UtcNow; var message = new VoiceMessage("recipients", "body", "accountReference"); var messages = new VoiceMessageCollection(message) {SendAt = timestamp}; var serialisedMessage = "serialisedMessage"; RestResource resource = new MessageDispatcherResource(serialisedMessage, false); var response = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "serialisedResponse" }; var expectedResult = new MessagingResult { BatchId = Guid.NewGuid(), MessageIds = new List<ResourceLink>() }; mockSerialiser .Setup(s => s.Serialise(messages)) .Returns(serialisedMessage); mockRestClient .Setup(rc => rc.Post(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<MessagingResult>(response.Content)) .Returns(expectedResult); // Act var actualResult = service.SendScheduledMessages(messages, timestamp); // Assert Assert.IsNotNull(actualResult); Assert.AreEqual(expectedResult.BatchId, actualResult.BatchId); Assert.AreEqual(0, actualResult.MessageIds.Count()); }
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 Get_HttpReturnsNull_ReturnsNull() { // Arrange GetRestResourceContext getResourceContext = new GetRestResourceContext(); HttpRequest httpRequest = new HttpRequest() { HttpMethod = HttpMethod.GET, ResourcePath = getResourceContext.ResourcePath, ContentType = "text/plain" }; RestResponse expectedResponse = new RestResponse() { StatusCode = HttpStatusCode.NotFound }; HttpResponse httpResponse = null; mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse); // Act RestResponse actualResponse = restClient.Get(getResourceContext); // Assert Assert.IsNull(actualResponse); }
public void Post_HttpReturnsIn200Range_ReturnsRestResponse() { // Arrange string content = "content"; PostRestResourceContext postResourceContext = new PostRestResourceContext(content); HttpRequest httpRequest = new HttpRequest() { HttpMethod = HttpMethod.POST, ResourcePath = postResourceContext.ResourcePath, Content = postResourceContext.Content, ContentType = "application/xml", ContentEncoding = Encoding.UTF8 }; RestResponse expectedResponse = new RestResponse() { StatusCode = HttpStatusCode.OK }; HttpResponse httpResponse = new HttpResponse() { StatusCode = HttpStatusCode.OK }; mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse); // Act RestResponse actualResponse = restClient.Post(postResourceContext); // Assert Assert.IsNotNull(actualResponse); Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode); }
public void SendMessages_WithSmsMessage_ReturnsBatchIdResult() { // Arrange SmsMessage message = new SmsMessage("recipients", "body", "accountReference"); SmsMessageCollection messages = new SmsMessageCollection(message); string serialisedMessage = "serialisedMessage"; RestResource resource = new MessageDispatcherResource(serialisedMessage, false); RestResponse response = new RestResponse() { StatusCode = HttpStatusCode.OK, Content = "serialisedResponse" }; MessagingResult expectedResult = new MessagingResult() { BatchId = Guid.NewGuid(), MessageIds = new List<ResourceLink>() }; mockSerialiser .Setup(s => s.Serialise(messages)) .Returns(serialisedMessage); mockRestClient .Setup(rc => rc.Post(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<MessagingResult>(response.Content)) .Returns(expectedResult); // Act MessagingResult actualResult = service.SendMessages(messages); // Assert Assert.IsNotNull(actualResult); Assert.AreEqual(expectedResult.BatchId, actualResult.BatchId); Assert.AreEqual(0, actualResult.MessageIds.Count()); }
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 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 GetMessages_WithPageNumberAndPageSize_ReturnsSentMessages() { // Arrange var pageNumber = 1; var pageSize = 15; RestResource resource = new MessageHeadersResource(pageNumber, pageSize); var response = new RestResponse { StatusCode = HttpStatusCode.OK, Content = "serialisedItem" }; var expectedResult = new SentMessageCollection { PageNumber = pageNumber, PageSize = pageSize }; mockRestClient .Setup(rc => rc.Get(resource)) .Returns(response); mockSerialiser .Setup(s => s.Deserialise<SentMessageCollection>(response.Content)) .Returns(expectedResult); // Act var actualResult = service.GetMessages(pageNumber, pageSize); // Assert Assert.AreEqual(pageNumber, actualResult.PageNumber); Assert.AreEqual(pageSize, actualResult.PageSize); }
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 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 Put_HttpReturnsIn200Range_ReturnsRestResponse() { // Arrange var content = "content"; var putResourceContext = new PutRestResourceContext(content); var httpRequest = new HttpRequest { HttpMethod = HttpMethod.PUT, ResourcePath = putResourceContext.ResourcePath, Content = putResourceContext.Content, ContentType = "application/xml", ContentEncoding = Encoding.UTF8 }; var expectedResponse = new RestResponse { StatusCode = HttpStatusCode.OK }; var httpResponse = new HttpResponse { StatusCode = HttpStatusCode.OK }; mockHttpClient.Setup(hc => hc.Submit(httpRequest)) .Returns(httpResponse); // Act var actualResponse = restClient.Put(putResourceContext); // Assert Assert.IsNotNull(actualResponse); Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode); }