Ejemplo n.º 1
0
        public void CanGetOAuthUrl()
        {
            var expectedUrl = "http://test.com";

            http.Stub(
                HttpPost
                .Url("https://api.cronofy.com/v1/add_to_calendar")
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat(
                    "{{\"client_id\":\"{0}\",\"client_secret\":\"{1}\",\"oauth\":{{\"redirect_uri\":\"{2}\",\"scope\":\"{3}\",\"state\":\"{4}\"}},\"event\":{{\"event_id\":\"{5}\",\"summary\":\"{6}\",\"start\":{{\"time\":\"{7}\",\"tzid\":\"Etc/UTC\"}},\"end\":{{\"time\":\"{8}\",\"tzid\":\"Etc/UTC\"}}}}}}",
                    clientId, clientSecret, redirectUrl, scope, state, eventId, summary, startString, endString)
                .ResponseCode(200)
                .ResponseBodyFormat(
                    "{{\"url\":\"{0}\"}}", expectedUrl)
                );

            var addToCalendarRequest = new AddToCalendarRequestBuilder()
                                       .OAuthDetails(redirectUrl, scope, state)
                                       .UpsertEventRequest(upsertEventRequest)
                                       .Build();

            var actualUrl = client.AddToCalendar(addToCalendarRequest);

            Assert.Equal(expectedUrl, actualUrl);
        }
Ejemplo n.º 2
0
        public void CanRedeemToken()
        {
            const string accessToken  = "asdnakjsdnas";
            const int    expiresIn    = 3600;
            const string refreshToken = "jerwpmsdkjngvdsk";
            const string scope        = "read_events create_event delete_event";

            http.Stub(
                HttpPost
                .Url("https://app.cronofy.com/oauth/token")
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat(
                    "{{\"client_id\":\"{0}\",\"client_secret\":\"{1}\",\"grant_type\":\"authorization_code\",\"code\":\"{2}\",\"redirect_uri\":\"{3}\"}}",
                    clientId, clientSecret, oauthCode, redirectUri)
                .ResponseCode(200)
                .ResponseBodyFormat(
                    "{{\"token_type\":\"bearer\",\"access_token\":\"{0}\",\"expires_in\":{1},\"refresh_token\":\"{2}\",\"scope\":\"{3}\"}}",
                    accessToken, expiresIn, refreshToken, scope)
                );

            var actualToken   = client.GetTokenFromCode(oauthCode, redirectUri);
            var expectedToken = new OAuthToken(accessToken, refreshToken, expiresIn, scope.Split(new[] { ' ' }));

            Assert.AreEqual(expectedToken, actualToken);
        }
Ejemplo n.º 3
0
        public void CanCreateInvite()
        {
            http.Stub(
                HttpPost
                .Url("https://api.cronofy.com/v1/smart_invites")
                .RequestHeader("Authorization", string.Format("Bearer {0}", clientSecret))
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBody(
                    @"{""method"":""request"",""smart_invite_id"":""testEventId"",""callback_url"":""http://example.com/callbackUrl"",""recipient"":{""email"":""*****@*****.**""},""event"":{""summary"":""Test Summary"",""start"":{""time"":""2014-08-05 15:30:00Z"",""tzid"":""Etc/UTC""},""end"":{""time"":""2014-08-05 16:30:00Z"",""tzid"":""Etc/UTC""}},""organizer"":{""name"":""My Cool Application""}}")
                .ResponseCode(200)
                .ResponseBody(@"{
                      ""recipient"": {
                        ""email"": ""*****@*****.**"",
                        ""status"": ""pending""
                      },
                      ""method"": ""request"",
                      ""smart_invite_id"": ""your-unique-identifier-for-invite"",
                      ""callback_url"": ""https://example.yourapp.com/cronofy/smart_invite/notifications"",
                      ""event"": {
                        ""summary"": ""Board meeting"",
                        ""description"": ""Discuss plans for the next quarter."",
                        ""start"": ""2017-10-05T09:30:00Z"",
                        ""end"": ""2017-10-05T10:00:00Z"",
                        ""tzid"": ""Europe/London"",
                        ""location"": {
                          ""description"": ""Board room""
                        }
                      },
                      ""attachments"": {
                        ""icalendar"": ""BEGIN:VCALENDAR\nVERSION:2.0...""
                      }
                    }")
                );

            var smartInviteRequest = new SmartInviteRequestBuilder()
                                     .Method("request")
                                     .CallbackUrl(callbackUrl)
                                     .InviteId(inviteId)
                                     .Recipient("*****@*****.**")
                                     .Organizer("My Cool Application")
                                     .Event(upsertEventRequest)
                                     .Build();

            var actual = client.CreateInvite(smartInviteRequest);

            Assert.AreEqual("your-unique-identifier-for-invite", actual.SmartInviteId);
            Assert.AreEqual("https://example.yourapp.com/cronofy/smart_invite/notifications", actual.CallbackUrl);
            Assert.AreEqual("pending", actual.Recipient.Status);
            Assert.AreEqual("request", actual.Method);
            Assert.AreEqual("*****@*****.**", actual.Recipient.Email);
            Assert.AreEqual("BEGIN:VCALENDAR\nVERSION:2.0...", actual.Attachments.ICalendar);
        }
        public void CanCreateApplicationCalendar()
        {
            const string accessToken  = "asdnakjsdnas";
            const int    expiresIn    = 3600;
            const string refreshToken = "jerwpmsdkjngvdsk";
            const string scope        = "read_events create_event delete_event";

            http.Stub(
                HttpPost
                .Url("https://api.cronofy.com/v1/application_calendars")
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat(
                    "{{\"client_id\":\"{0}\",\"client_secret\":\"{1}\",\"application_calendar_id\":\"{2}\"}}",
                    clientId, clientSecret, applicationCalendarId)
                .ResponseCode(200)
                .ResponseBodyFormat(
                    "{{\"token_type\":\"bearer\",\"access_token\":\"{0}\",\"expires_in\":{1},\"refresh_token\":\"{2}\",\"scope\":\"{3}\"}}",
                    accessToken, expiresIn, refreshToken, scope)
                );

            var actualToken   = client.ApplicationCalendar(applicationCalendarId);
            var expectedToken = new OAuthToken(accessToken, refreshToken, expiresIn, scope.Split(new[] { ' ' }));

            Assert.Equal(expectedToken, actualToken);
        }
Ejemplo n.º 5
0
        public void CanRevokeToken()
        {
            const string refreshToken = "jerwpmsdkjngvdsk";

            http.Stub(
                HttpPost
                .Url("https://app.cronofy.com/oauth/token/revoke")
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat(
                    "{{\"client_id\":\"{0}\",\"client_secret\":\"{1}\",\"token\":\"{2}\"}}",
                    clientId, clientSecret, refreshToken)
                .ResponseCode(200)
                );

            client.RevokeToken(refreshToken);
        }
        public void CanGetOAuthUrlWithAvailabilityTargetCalendarsAndHourFormat()
        {
            var start = new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc);
            var end   = new DateTime(2014, 8, 5, 16, 30, 0, DateTimeKind.Utc);

            var client = new CronofyOAuthClient(clientId, clientSecret);
            var http   = new StubHttpClient();

            client.HttpClient = http;

            var upsertEventRequestWithoutStartAndEnd = new UpsertEventRequestBuilder()
                                                       .EventId("testEventId")
                                                       .Summary("Test Summary")
                                                       .Build();

            var sequenceBuilder = new SequenceRequestBuilder()
                                  .RequiredDuration(60)
                                  .Ordinal(1)
                                  .SequenceId("First Event")
                                  .Event(upsertEventRequestWithoutStartAndEnd)
                                  .AddRequiredParticipant("acc_567236000909002")
                                  .AddRequiredParticipant("acc_678347111010113");

            var availabilityRequest = new SequencedAvailabilityRequestBuilder()
                                      .AddSequence(sequenceBuilder)
                                      .AddAvailablePeriod(start, end)
                                      .Build();

            var expectedUrl = "http://test.com";

            http.Stub(
                HttpPost
                .Url("https://api.cronofy.com/v1/real_time_sequencing")
                .JsonRequest(@"
                    {
                      ""availablity"":{
                         ""sequence"":[
                              {
                                ""ordinal"":1,
                                ""sequence_id"":""First Event"",
                                ""event"":{
                                    ""event_id"":""testEventId"",
                                    ""summary"":""Test Summary""
                                },
                                ""participants"":[
                                  {
                                    ""members"":[
                                      { ""sub"":""acc_567236000909002"" },
                                      { ""sub"":""acc_678347111010113"" }
                                    ],
                                ""required"":""all""
                              }
                            ],
                            ""required_duration"":{
                              ""minutes"":60
                            },
                            ""available_periods"":[ ]
                          }
                        ],
                        ""available_periods"":[
                          {
                            ""start"":""2014-08-05 15:30:00Z"",
                            ""end"":""2014-08-05 16:30:00Z""
                          }
                        ]
                      },
                      ""client_id"":""abcdef123456"",
                      ""client_secret"":""s3cr3t1v3"",
                      ""oauth"":{
                        ""redirect_uri"":""http://example.com/redirectUri"",
                        ""scope"":""test_scope""
                      },
                      ""event"":{
                        ""event_id"":""testEventId"",
                        ""summary"":""Test Summary""
                      },
                      ""target_calendars"":[
                        {
                          ""sub"":""sub"",
                          ""calendar_id"":""calendarId""
                        }
                      ],
                      ""formatting"":{
                        ""hour_format"":""H""
                      },
                      ""tzid"":""Etc/UTC""
                    }")
                .ResponseCode(200)
                .ResponseBodyFormat("{{\"url\":\"{0}\"}}", expectedUrl)
                );

            var request = new RealTimeSequencingRequestBuilder()
                          .OAuthDetails("http://example.com/redirectUri", "test_scope")
                          .Timezone("Etc/UTC")
                          .UpsertEventRequest(upsertEventRequestWithoutStartAndEnd)
                          .SequencedAvailabilityRequest(availabilityRequest)
                          .AddTargetCalendar("sub", "calendarId")
                          .HourFormat("H")
                          .Build();

            var actualUrl = client.RealTimeSequencing(request);

            Assert.AreEqual(expectedUrl, actualUrl);
        }
Ejemplo n.º 7
0
        public void CanGetOAuthUrlWithAvailabilityTargetCalendarsAndHourFormat()
        {
            var expectedUrl = "http://test.com";
            var hourFormat  = "H";

            http.Stub(
                HttpPost
                .Url("https://api.cronofy.com/v1/real_time_scheduling")
                .RequestHeader("Content-Type", "application/json; charset=utf-8")
                .RequestBodyFormat(
                    "{{" +
                    "\"availability\":{{" +
                    "\"participants\":[{{" +
                    "\"members\":[{{" +
                    "\"sub\":\"{6}\"" +
                    "}}]" +
                    "}}]," +
                    "\"required_duration\":{{" +
                    "\"minutes\":60" +
                    "}}," +
                    "\"available_periods\":[{{" +
                    "\"start\":\"{7}\"," +
                    "\"end\":\"{8}\"" +
                    "}}]" +
                    "}}," +
                    "\"client_id\":\"{0}\"," +
                    "\"client_secret\":\"{1}\"," +
                    "\"oauth\":{{" +
                    "\"redirect_uri\":\"{2}\"," +
                    "\"scope\":\"{3}\"" +
                    "}}," +
                    "\"event\":{{" +
                    "\"event_id\":\"{4}\"," +
                    "\"summary\":\"{5}\"" +
                    "}}," +
                    "\"target_calendars\":[{{" +
                    "\"sub\":\"{9}\"," +
                    "\"calendar_id\":\"{10}\"" +
                    "}}]," +
                    "\"formatting\":{{" +
                    "\"hour_format\":\"{11}\"" +
                    "}}," +
                    "\"tzid\":\"Etc/UTC\"" +
                    "}}",
                    clientId, clientSecret, redirectUrl, scope, eventId, summary, sub, startString, endString, sub, calendarId, hourFormat)
                .ResponseCode(200)
                .ResponseBodyFormat(
                    "{{\"url\":\"{0}\"}}", expectedUrl)
                );

            var request = new RealTimeSchedulingRequestBuilder()
                          .OAuthDetails(redirectUrl, scope)
                          .Timezone("Etc/UTC")
                          .UpsertEventRequest(upsertEventRequestWithoutStartAndEnd)
                          .AvailabilityRequest(availabilityRequest)
                          .AddTargetCalendar(sub, calendarId)
                          .HourFormat("H")
                          .Build();

            var actualUrl = client.RealTimeScheduling(request);

            Assert.AreEqual(expectedUrl, actualUrl);
        }