public void Create() { var restClient = MockRestClient .ThatExpects("{ \"title\": \"Forward call to 31612345678\", \"record\": true, \"steps\": [ { \"options\": { \"destination\": \"31612345678\" }, \"action\": \"transfer\" } ]}") .AndReturns("{ \"data\": [ { \"id\": \"de3ed163-d5fc-45f4-b8c4-7eea7458c635\", \"title\": \"Forward call to 31612345678\", \"record\": true, \"steps\": [ { \"id\": \"2fa1383e-6f21-4e6f-8c36-0920c3d0730b\", \"action\": \"transfer\", \"options\": { \"destination\": \"31612345678\" } } ], \"createdAt\": \"2017-03-06T14:52:22Z\", \"updatedAt\": \"2017-03-06T14:52:22Z\" } ], \"_links\": { \"self\": \"/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635\" }}") .FromEndpoint("POST", "call-flows", VoiceCallFlowsResource.VoiceCallFlowsBaseUrl) .Get(); var client = Client.Create(restClient.Object); var newVoiceCallFlow = new VoiceCallFlow { Title = "Forward call to 31612345678", Record = true, Steps = new List <Step> { new Step { Action = "transfer", Options = new Options { Destination = "31612345678" } } } }; var voiceCallFlow = client.CreateVoiceCallFlow(newVoiceCallFlow); restClient.Verify(); Assert.AreEqual("Forward call to 31612345678", voiceCallFlow.Title); }
public void Update() { var restClient = MockRestClient .ThatExpects("{\"title\":\"Updated call flow\",\"steps\":[{\"options\":{\"destination\":\"31611223344\"},\"action\":\"transfer\"}]}") .AndReturns(filename: "VoiceCallFlowUpdate.json") .FromEndpoint("PUT", "call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635", VoiceCallFlowsResource.VoiceCallFlowsBaseUrl) .Get(); var client = Client.Create(restClient.Object); var voiceCallFlow = new VoiceCallFlow { Title = "Updated call flow", Steps = new List <Step> { new Step { Action = "transfer", Options = new Options { Destination = "31611223344" } } } }; var updatedVoiceCallFlow = client.UpdateVoiceCallFlow("de3ed163-d5fc-45f4-b8c4-7eea7458c635", voiceCallFlow); restClient.Verify(); Assert.IsNotNull(updatedVoiceCallFlow.Id); }
public void PostWebhook() { var restClient = MockRestClient .ThatExpects( @"{""events"":[""message.created"", ""message.updated""],""channelId"": ""853eeb5348e541a595da93b48c61a1ae"",""url"":""https://example.com/webhook""}") .AndReturns(filename: "WebhookView.json") .FromEndpoint("POST", "webhooks", Resource.ConverstationsBaseUrl) .Get(); var client = Client.Create(restClient.Object); var req = new ConversationWebhook { ChannelId = "853eeb5348e541a595da93b48c61a1ae", Url = "https://example.com/webhook", Events = new List <ConversationWebhookEvent> { ConversationWebhookEvent.MessageCreated, ConversationWebhookEvent.MessageUpdated } }; var webhook = client.CreateConversationWebhook(req); restClient.Verify(); Assert.AreEqual(req.ChannelId, webhook.ChannelId); Assert.AreEqual(req.Url, webhook.Url); Assert.AreEqual(req.Events.Count, webhook.Events.Count); Assert.IsTrue(webhook.Events.Contains(ConversationWebhookEvent.MessageCreated)); Assert.IsTrue(webhook.Events.Contains(ConversationWebhookEvent.MessageUpdated)); }
public void Start() { var restClient = MockRestClient .ThatExpects( @"{""to"":""+31612345678"",""type"":""text"",""content"":{""text"":""Hello!""},""channelId"":""619747f69cf940a98fb443140ce9aed2""}") .AndReturns(filename: "ConversationView.json") .FromEndpoint("POST", "conversations/start", Resource.ConverstationsBaseUrl) .Get(); var client = Client.Create(restClient.Object); var req = new ConversationStartRequest { ChannelId = "619747f69cf940a98fb443140ce9aed2", Content = new Content { Text = "Hello!" }, Type = ContentType.Text, To = "+31612345678" }; var conversation = client.StartConversation(req); restClient.Verify(); Assert.AreEqual(req.ChannelId, conversation.LastUsedChannelId); Assert.AreEqual("31612345678", conversation.Contact.Msisdn); Assert.AreEqual(2, conversation.Channels.Count); }
public void PostMessage() { var restClient = MockRestClient .ThatExpects(@"{""type"": ""text"",""content"":{""text"": ""Hello!""}}") .AndReturns(filename: "ConversationMessage.json") .FromEndpoint("POST", $"conversations/{ConvId}/messages", Resource.ConverstationsBaseUrl) .Get(); var client = Client.Create(restClient.Object); var req = new ConversationMessageSendRequest { Type = ContentType.Text, Content = new Content { Text = "Hello!" } }; var message = client.SendConversationMessage(ConvId, req); restClient.Verify(); Assert.AreEqual(ConvId, message.ConversationId); Assert.AreEqual(ConversationMessageStatus.Pending, message.Status); Assert.AreEqual(ConversationMessageDirection.Sent, message.Direction); }
public void Create() { var restClient = MockRestClient .ThatExpects("{\"url\":\"https://testing.com\",\"token\":\"example token\"}") .AndReturns(filename: "WebhooksCreate.json") .FromEndpoint("POST", "webhooks", baseUrl) .Get(); var client = Client.Create(restClient.Object); var newWebhook = new Webhook { url = "https://testing.com", token = "example token" }; var webhookResponse = client.CreateWebhook(newWebhook); restClient.Verify(); Assert.IsNotNull(webhookResponse.Data); Assert.IsNotNull(webhookResponse.Links); var selfLink = webhookResponse.Links["self"]; Assert.AreEqual("/webhooks/dff95aec-c11f-423c-82f3-1f391d78d716", selfLink); var webhook = webhookResponse.Data.FirstOrDefault(); Assert.AreEqual("dff95aec-c11f-423c-82f3-1f391d78d716", webhook.Id); Assert.AreEqual("https://testing.com", webhook.url); Assert.AreEqual("example token", webhook.token); Assert.IsNotNull(webhook.createdAt); Assert.IsNotNull(webhook.updatedAt); }
public void Create() { var restClient = MockRestClient .ThatExpects("{ \"title\": \"Forward call to 31612345678\", \"record\": true, \"steps\": [ { \"options\": { \"destination\": \"31612345678\" }, \"action\": \"transfer\" } ]}") .AndReturns("{ \"data\": [ { \"id\": \"de3ed163-d5fc-45f4-b8c4-7eea7458c635\", \"title\": \"Forward call to 31612345678\", \"record\": true, \"steps\": [ { \"id\": \"2fa1383e-6f21-4e6f-8c36-0920c3d0730b\", \"action\": \"transfer\", \"options\": { \"destination\": \"31612345678\" } } ], \"createdAt\": \"2017-03-06T14:52:22Z\", \"updatedAt\": \"2017-03-06T14:52:22Z\" } ], \"_links\": { \"self\": \"/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635\" }}") .FromEndpoint("POST", "call-flows", baseUrl) .Get(); var client = Client.Create(restClient.Object); var newCallFlow = new CallFlow { Title = "Forward call to 31612345678", Record = true, Steps = new List <Step> { new Step { Action = "transfer", Options = new Options { Destination = "31612345678" } } } }; var callFlowResponse = client.CreateCallFlow(newCallFlow); restClient.Verify(); Assert.IsNotNull(callFlowResponse.Data); Assert.IsNotNull(callFlowResponse.Links); var links = callFlowResponse.Links; Assert.AreEqual("/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635", links.GetValueOrDefault("self")); var callFlow = callFlowResponse.Data.FirstOrDefault(); Assert.AreEqual("de3ed163-d5fc-45f4-b8c4-7eea7458c635", callFlow.Id); Assert.AreEqual("Forward call to 31612345678", callFlow.Title); Assert.AreEqual(true, callFlow.Record); Assert.IsNotNull(callFlow.CreatedAt); Assert.IsNotNull(callFlow.UpdatedAt); Assert.IsNotNull(callFlow.Steps); var step = callFlow.Steps.FirstOrDefault(); Assert.AreEqual("2fa1383e-6f21-4e6f-8c36-0920c3d0730b", step.Id); Assert.AreEqual("transfer", step.Action); Assert.AreEqual("31612345678", step.Options.Destination); }
public void Update() { var restClient = MockRestClient .ThatExpects("{\"name\":\"family\"}") .AndReturns("{\"id\": \"group-id\",\"href\": \"https://rest.messagebird.com/groups/group-id\",\"name\": \"family\",\"contacts\": {\"totalCount\": 3,\"href\": \"https://rest.messagebird.com/groups/group-id\"},\"createdDatetime\": \"2018-07-25T12:16:10+00:00\",\"updatedDatetime\": \"2018-07-25T12:16:23+00:00\"}") .FromEndpoint("PATCH", "groups/group-id") .Get(); var client = Client.Create(restClient.Object); var group = client.UpdateGroup("group-id", "family"); restClient.Verify(); Assert.IsNotNull(group.Id); }
public void Update() { var restClient = MockRestClient .ThatExpects("{\"id\":\"de3ed163-d5fc-45f4-b8c4-7eea7458c635\",\"title\":\"Updated call flow\",\"steps\":[{\"action\":\"transfer\",\"options\":{\"destination\":\"31611223344\"}}]}") .AndReturns(filename: "CallFlowUpdate.json") .FromEndpoint("PUT", "call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635", baseUrl) .Get(); var client = Client.Create(restClient.Object); var callFlow = new CallFlow { Title = "Updated call flow", Steps = new List <Step> { new Step { Action = "transfer", Options = new Options { Destination = "31611223344" } } } }; var callFlowResponse = client.UpdateCallFlow("de3ed163-d5fc-45f4-b8c4-7eea7458c635", callFlow); restClient.Verify(); Assert.IsNotNull(callFlowResponse.Data); Assert.IsNotNull(callFlowResponse.Links); var links = callFlowResponse.Links; Assert.AreEqual("/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635", links.GetValueOrDefault("self")); var updatedCallFlow = callFlowResponse.Data.FirstOrDefault(); Assert.AreEqual("de3ed163-d5fc-45f4-b8c4-7eea7458c635", updatedCallFlow.Id); Assert.AreEqual("Updated call flow", updatedCallFlow.Title); Assert.AreEqual(false, updatedCallFlow.Record); Assert.IsNotNull(updatedCallFlow.CreatedAt); Assert.IsNotNull(updatedCallFlow.UpdatedAt); Assert.IsNotNull(updatedCallFlow.Steps); var step = updatedCallFlow.Steps.FirstOrDefault(); Assert.AreEqual("3538a6b8-5a2e-4537-8745-f72def6bd393", step.Id); Assert.AreEqual("transfer", step.Action); Assert.AreEqual("31611223344", step.Options.Destination); }
public void Create() { var restClient = MockRestClient .ThatExpects("{\"name\":\"Friends\"}") .AndReturns("{\"id\": \"group-id\",\"href\": \"https://rest.messagebird.com/groups/group-id\",\"name\": \"Friends\",\"contacts\": {\"totalCount\": 3,\"href\": \"https://rest.messagebird.com/groups/group-id\"},\"createdDatetime\": \"2018-07-25T12:16:10+00:00\",\"updatedDatetime\": \"2018-07-25T12:16:23+00:00\"}") .FromEndpoint("POST", "groups") .Get(); var client = Client.Create(restClient.Object); var group = client.CreateGroup("Friends"); restClient.Verify(); Assert.AreEqual("group-id", group.Id); Assert.AreEqual(3, group.Contacts.TotalCount); }
public void Update() { var restClient = MockRestClient .ThatExpects(@"{""id"":""2e15efafec384e1c82e9842075e87beb"",""status"": ""archived""}") .AndReturns(filename: "ConversationView.json") .FromEndpoint("PATCH", $"conversations/{ConvId}", Resource.ConverstationsBaseUrl) .Get(); var client = Client.Create(restClient.Object); var conversation = client.UpdateConversation(ConvId, new Conversation { Status = ConversationStatus.Archived }); restClient.Verify(); Assert.AreEqual(ConvId, conversation.Id); Assert.AreEqual(ConversationStatus.Archived, conversation.Status); }
public void Create() { var restClient = MockRestClient .ThatExpects("{\"Language\":\"en-EN\"}") .AndReturns(filename: "TranscriptionCreate.json") .FromEndpoint("POST", "calls/373395cc-382b-4a33-b372-cc31f0fdf242/legs/8dd347a4-11ee-44f2-bee3-7fbda300b2cd/recordings/cfa9ae96-e034-4db7-91cb-e58a8392c7bd/transcriptions/", baseUrl) .Get(); var client = Client.Create(restClient.Object); var transcriptionResponse = client.CreateTranscription("373395cc-382b-4a33-b372-cc31f0fdf242", "8dd347a4-11ee-44f2-bee3-7fbda300b2cd", "cfa9ae96-e034-4db7-91cb-e58a8392c7bd", "en-EN"); restClient.Verify(); Assert.IsNotNull(transcriptionResponse.Data); var transcription = transcriptionResponse.Data.FirstOrDefault(); Assert.AreEqual("2ce04c83-ca4f-4d94-8310-02968da41318", transcription.Id); Assert.AreEqual("cfa9ae96-e034-4db7-91cb-e58a8392c7bd", transcription.RecordingId); Assert.AreEqual("transcribing", transcription.Status); }
public void Update() { var restClient = MockRestClient .ThatExpects("{\"lastName\":\"SomeName\",\"custom4\":\"Fourth\"}") .AndReturns("{\"id\": \"id\",\"href\": \"https://rest.messagebird.com/contacts/id\",\"msisdn\": 31687654321,\"firstName\": \"Foo\",\"lastName\": \"SomeName\",\"customDetails\": {\"custom1\": \"First\",\"custom2\": \"Second\",\"custom3\": null,\"custom4\": \"Fourth\"},\"groups\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/groups\"},\"messages\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/messages\"},\"createdDatetime\": \"2018-08-10T13:58:00+00:00\",\"updatedDatetime\": \"2018-08-10T13:58:00+00:00\"}") .FromEndpoint("PATCH", "contacts/some-id") .Get(); var client = Client.Create(restClient.Object); var optionalArguments = new ContactOptionalArguments { LastName = "SomeName", Custom4 = "Fourth", }; var contact = client.UpdateContact("some-id", optionalArguments); restClient.Verify(); Assert.AreEqual(31687654321L, contact.Msisdn); Assert.AreEqual("SomeName", contact.LastName); Assert.AreEqual("Fourth", contact.CustomDetails.Custom4); }
public void Create() { var restClient = MockRestClient .ThatExpects("{\"source\":\"31644556677\",\"destination\":\"33766723144\",\"callFlow\":{\"title\":\"Forward call to 31612345678\",\"record\":true,\"steps\":[{\"action\":\"transfer\",\"options\":{\"destination\":\"31612345678\"}}]},\"duration\":0}") .AndReturns(filename: "CallCreate.json") .FromEndpoint("POST", "calls", baseUrl) .Get(); var client = Client.Create(restClient.Object); var newCallFlow = new CallFlow { Title = "Forward call to 31612345678", Record = true, Steps = new List <Step> { new Step { Action = "transfer", Options = new Options { Destination = "31612345678" } } } }; var newCall = new Call { Source = "31644556677", Destination = "33766723144", CallFlow = newCallFlow }; var callResponse = client.CreateCall(newCall); restClient.Verify(); Assert.IsNotNull(callResponse.Data); var call = callResponse.Data.FirstOrDefault(); Assert.AreEqual("cac63a43-ff05-4cc3-b8e3-fca82e97975c", call.Id); }
public void Create() { var restClient = MockRestClient .ThatExpects("{\"msisdn\":31612345678,\"firstName\":\"Foo\",\"lastName\":\"Bar\",\"custom1\":\"First\",\"custom2\":\"Second\"}") .AndReturns("{\"id\": \"id\",\"href\": \"https://rest.messagebird.com/contacts/id\",\"msisdn\": 31612345678,\"firstName\": \"Foo\",\"lastName\": \"Bar\",\"customDetails\": {\"custom1\": \"First\",\"custom2\": \"Second\",\"custom3\": null,\"custom4\": null},\"groups\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/groups\"},\"messages\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/messages\"},\"createdDatetime\": \"2018-08-10T13:58:00+00:00\",\"updatedDatetime\": \"2018-08-10T13:58:00+00:00\"}") .FromEndpoint("POST", "contacts") .Get(); var client = Client.Create(restClient.Object); var optionalArguments = new ContactOptionalArguments { FirstName = "Foo", LastName = "Bar", Custom1 = "First", Custom2 = "Second", }; var contact = client.CreateContact(31612345678L, optionalArguments); restClient.Verify(); Assert.AreEqual(31612345678L, contact.Msisdn); Assert.AreEqual("Second", contact.CustomDetails.Custom2); }