コード例 #1
0
        async public Task TestEmailMessage()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EmailMessage.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EmailMessageResource emailMessage = new EmailMessageResource();

            emailMessage.Subject = "Ahoy";
            emailMessage.Body    = "Sample body";

            await emailMessage.Create();

            EmailResource email = new EmailResource();

            email.To           = "*****@*****.**";
            email.EmailMessage = emailMessage;
            email.EmailId      = new EmailIdResource
            {
                Id = "NbXW9TCHax9zfAeDhaY2bG"
            };

            await email.Create();
        }
コード例 #2
0
        async public Task TestTextMessage()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/TextMessage.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            TextMessageResource textMessage = new TextMessageResource();

            textMessage.Body = "Sample body";

            await textMessage.Create();

            TextResource text = new TextResource();

            text.To          = "+14076413749";
            text.TextMessage = textMessage;
            text.PhoneNumber = new PhoneNumberResource
            {
                Id = "GncieHvbCKfMYXmeycoWZm"
            };

            await text.Create();
        }
コード例 #3
0
        public HttpCustomClient()
        {
            var baseDir          = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin", "").Replace("\\Debug", "").Replace("\\Release", "");
            var cassettePathFile = Path.Combine(baseDir, "recorded-requests", "http-requests-cassette.json");

            ScotchHttpClient = HttpClients.NewHttpClient(cassettePathFile, ScotchMode.Replaying);
        }
コード例 #4
0
        public async Task ReplaceMatchingInteractionInCassetteFile()
        {
            var originalInteractionsInCassette = Cassette.ReadCassette(_testCassettePath).ToList();

            originalInteractionsInCassette.Count.ShouldBe(3);
            var originalRecordedTime1 = originalInteractionsInCassette.ElementAt(0).RecordedAt;
            var originalRecordedTime2 = originalInteractionsInCassette.ElementAt(1).RecordedAt;
            var originalRecordedTime3 = originalInteractionsInCassette.ElementAt(2).RecordedAt;

            var httpClient = HttpClients.NewHttpClient(_testCassettePath, ScotchMode.Recording);

            var albumService = new AlbumService(httpClient);
            var album        = await albumService.GetAsync(2);

            album.Id.ShouldBe(2);

            var newInteractionsInCassette = Cassette.ReadCassette(_testCassettePath).ToList();

            newInteractionsInCassette.Count.ShouldBe(3);

            var newRecordedTime1 = newInteractionsInCassette.ElementAt(0).RecordedAt;
            var newRecordedTime2 = newInteractionsInCassette.ElementAt(1).RecordedAt;
            var newRecordedTime3 = newInteractionsInCassette.ElementAt(2).RecordedAt;

            originalRecordedTime1.ShouldBe(newRecordedTime1);
            originalRecordedTime2.ShouldNotBe(newRecordedTime2);
            originalRecordedTime3.ShouldBe(newRecordedTime3);
        }
コード例 #5
0
        public async Task ReplayedResponseHasCorrectContentType()
        {
            var httpClient = HttpClients.NewHttpClient(_testCassettePath, ScotchMode.Replaying);

            var url      = "http://jsonplaceholder.typicode.com/albums/2";
            var response = await httpClient.GetAsync(url);

            response.Content.Headers.ContentType.MediaType.ShouldBe("application/json");
        }
コード例 #6
0
        public async Task ReplaysMatchingHttpInteractionFromCassette()
        {
            var httpClient = HttpClients.NewHttpClient(_testCassettePath, ScotchMode.Replaying);

            var albumService = new AlbumService(httpClient);
            var album        = await albumService.GetAsync(2);

            album.Title.ShouldBe("Hunky Dory");
        }
コード例 #7
0
        public void can_get_balance()
        {
            var _testPath  = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
            var httpClient = HttpClients.NewHttpClient(_testPath + TestingConfig.scotchCassettePath, TestingConfig.scotchMode);
            var interfax   = new FaxClient(TestingConfig.username, TestingConfig.password, httpClient);

            var actual = interfax.Account.GetBalance().Result;
            //Assert.IsTrue(actual > 0); Call is still be valid if account balance is zero.
        }
コード例 #8
0
        public async Task CreatesCassetteFile()
        {
            var httpClient = HttpClients.NewHttpClient(_newCassettePath, ScotchMode.Recording);

            var albumService = new AlbumService(httpClient);
            var albums       = await albumService.GetAllAsync();

            albums.Count.ShouldBeGreaterThan(0);
            File.Exists(_newCassettePath).ShouldBeTrue();
        }
コード例 #9
0
        async public Task TestCallParent()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/CallParentTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            var call = new CallResource();

            call.To     = "+18332676094";
            call.Action = CallAction.Dial;

            await call.Create();
        }
コード例 #10
0
        async public Task TestCallChild()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/CallChildTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);
            OmnigageClient.IsTesting = true;

            CallResource parentCall = new CallResource();

            parentCall.To     = "+18332676094";
            parentCall.Action = CallAction.Dial;

            await parentCall.Create();

            while (true)
            {
                if (parentCall.Status == "in-progress")
                {
                    break;
                }
                else
                {
                    await parentCall.Reload();
                }
            }

            CallResource childCall = new CallResource();

            childCall.To         = "+14076413749";
            childCall.Action     = CallAction.Dial;
            childCall.ParentCall = parentCall;
            childCall.CallerId   = new CallerIdResource
            {
                Id = "yL9vQaWrSqg5W8EFEpE6xZ"
            };

            await childCall.Create();
        }
コード例 #11
0
        public async Task AppendsNewInteractionsToCassetteFile()
        {
            var preInteractionsInCassette = Cassette.ReadCassette(_testCassettePath);

            preInteractionsInCassette.Count().ShouldBe(3);

            var httpClient = HttpClients.NewHttpClient(_testCassettePath, ScotchMode.Recording);

            var albumService = new AlbumService(httpClient);
            var album1       = await albumService.GetAsync(4);

            var album2 = await albumService.GetAsync(5);

            album1.Id.ShouldBe(4);
            album2.Id.ShouldBe(5);

            var postInteractionsInCassette = Cassette.ReadCassette(_testCassettePath);

            postInteractionsInCassette.Count().ShouldBe(5);
        }
コード例 #12
0
        async public Task TestCallParentChild()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/CallParentChildTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);
            OmnigageClient.IsTesting = true;

            CallResource call = new CallResource();

            call.From     = "+18332676094";
            call.To       = "+14076413749";
            call.Action   = CallAction.Dial;
            call.CallerId = new CallerIdResource
            {
                Id = "yL9vQaWrSqg5W8EFEpE6xZ"
            };

            await call.Create();
        }
コード例 #13
0
        async public Task TestTextEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementTextTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Text Blast";
            engagement.Direction = "outbound";

            await engagement.Create();

            TextTemplateResource textTemplate = new TextTemplateResource();

            textTemplate.Name = "Text Template";
            textTemplate.Body = "Sample body";

            await textTemplate.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name         = "Text Blast";
            activity.Kind         = ActivityKind.Text;
            activity.Engagement   = engagement;
            activity.TextTemplate = textTemplate;
            activity.PhoneNumber  = new PhoneNumberResource
            {
                Id = "GncieHvbCKfMYXmeycoWZm"
            };

            await activity.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.PhoneNumber = "+14076413749";
            envelope.Engagement  = engagement;
            envelope.Meta        = new Dictionary <string, string>
            {
                { "first-name", "Omnigage" },
                { "last-name", "Demo" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await Client.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
コード例 #14
0
        public void Setup()
        {
            var httpClient = HttpClients.NewHttpClient(_testPath + TestingConfig.scotchCassettePath, TestingConfig.scotchMode);

            _interfax = new FaxClient(TestingConfig.username, TestingConfig.password, httpClient);
        }
コード例 #15
0
        async public Task TestEmailVoiceEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementEmailVoiceTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Email Voice Blast (Voice Link)";
            engagement.Direction = "outbound";
            await engagement.Create();

            EmailTemplateResource emailTemplate = new EmailTemplateResource();

            emailTemplate.Subject = "Email Template";
            emailTemplate.Body    = "Email template with {{message-body}}.";
            await emailTemplate.Create();

            EmailMessageResource emailMessage = new EmailMessageResource();

            emailMessage.Subject = "Email Message";
            emailMessage.Body    = "Sample body";
            emailMessage.IsDraft = true;
            await emailMessage.Create();

            UploadResource upload1 = new UploadResource
            {
                FilePath = "Media/hello.mp3"
            };
            await upload1.Create();

            VoiceTemplateResource recording = new VoiceTemplateResource();

            recording.Name   = "Voice Link Recording";
            recording.Kind   = "audio";
            recording.Upload = upload1;
            await recording.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name = "Email Voice";
            activity.Kind = ActivityKind.EmailVoice;
            activity.CallBackPhoneNumber = "+11231231234";
            activity.Engagement          = engagement;
            activity.VoiceTemplate       = recording;
            activity.EmailTemplate       = emailTemplate;
            activity.EmailMessage        = emailMessage;
            activity.EmailId             = new EmailIdResource
            {
                Id = "NbXW9TCHax9zfAeDhaY2bG"
            };
            await activity.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.EmailAddress = "*****@*****.**";
            envelope.Engagement   = engagement;
            envelope.Meta         = new Dictionary <string, string>
            {
                { "first-name", "Omnigage" },
                { "last-name", "Demo" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await OmnigageClient.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
コード例 #16
0
        async public Task TestVoiceEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Voice Blast";
            engagement.Direction = "outbound";

            await engagement.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name       = "Voice Blast";
            activity.Kind       = ActivityKind.Voice;
            activity.Engagement = engagement;
            activity.CallerId   = new CallerIdResource
            {
                Id = "yL9vQaWrSqg5W8EFEpE6xZ"
            };

            await activity.Create();

            UploadResource upload1 = new UploadResource
            {
                FilePath = "Media/hello.mp3"
            };
            await upload1.Create();

            UploadResource upload2 = new UploadResource
            {
                FilePath = "Media/you-have-new-mail-waiting.wav"
            };
            await upload2.Create();

            VoiceTemplateResource humanRecording = new VoiceTemplateResource();

            humanRecording.Name   = "Human Recording";
            humanRecording.Kind   = "audio";
            humanRecording.Upload = upload1;
            await humanRecording.Create();

            VoiceTemplateResource machineRecording = new VoiceTemplateResource();

            machineRecording.Name   = "Machine Recording";
            machineRecording.Kind   = "audio";
            machineRecording.Upload = upload2;
            await machineRecording.Create();

            // Define human trigger
            TriggerResource triggerHumanInstance = new TriggerResource();

            triggerHumanInstance.Kind          = TriggerKind.Play;
            triggerHumanInstance.OnEvent       = TriggerOnEvent.VoiceHuman;
            triggerHumanInstance.Activity      = activity;
            triggerHumanInstance.VoiceTemplate = humanRecording;
            await triggerHumanInstance.Create();

            // Define machine trigger
            TriggerResource triggerMachineInstance = new TriggerResource();

            triggerMachineInstance.Kind          = TriggerKind.Play;
            triggerMachineInstance.OnEvent       = TriggerOnEvent.VoiceMachine;
            triggerMachineInstance.Activity      = activity;
            triggerMachineInstance.VoiceTemplate = machineRecording;
            await triggerMachineInstance.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.PhoneNumber = "+18332676094";
            envelope.Engagement  = engagement;
            envelope.Meta        = new Dictionary <string, string>
            {
                { "first-name", "Spectrum" },
                { "last-name", "Support" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await OmnigageClient.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
コード例 #17
0
        async public Task TestEmailEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementEmailTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Email Blast";
            engagement.Direction = "outbound";

            await engagement.Create();

            EmailTemplateResource emailTemplate = new EmailTemplateResource();

            emailTemplate.Subject = "Ahoy";
            emailTemplate.Body    = "Sample body";

            await emailTemplate.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name          = "Email Blast";
            activity.Kind          = ActivityKind.Email;
            activity.Engagement    = engagement;
            activity.EmailTemplate = emailTemplate;
            activity.EmailId       = new EmailIdResource
            {
                Id = "NbXW9TCHax9zfAeDhaY2bG"
            };

            await activity.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.EmailAddress = "*****@*****.**";
            envelope.Engagement   = engagement;
            envelope.Meta         = new Dictionary <string, string>
            {
                { "first-name", "Omnigage" },
                { "last-name", "Demo" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await OmnigageClient.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }