public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, TCommentObjectType obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(obj.Comment))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_COMMENT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Comment).ConfigureAwait(false);
            }

            if (obj.Spoiler.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SPOILER, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Spoiler, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Sharing != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHARING, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Sharing, cancellationToken).ConfigureAwait(false);
            }

            await WriteCommentObjectAsync(jsonWriter, obj, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, TCheckinResponseObjectType obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_ID, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteValueAsync(obj.Id, cancellationToken).ConfigureAwait(false);

            if (obj.WatchedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_WATCHED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.WatchedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Sharing != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHARING, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Sharing, cancellationToken).ConfigureAwait(false);
            }

            await WriteCheckinResponseObjectAsync(jsonWriter, obj, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #3
0
 public async Task Test_SharingObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var                   traktJsonWriter = new SharingObjectJsonWriter();
     ITraktSharing         traktSharing    = new TraktSharing();
     Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktSharing);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void Test_SharingObjectJsonWriter_WriteObject_Object_Exceptions()
        {
            var traktJsonWriter          = new SharingObjectJsonWriter();
            Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(ITraktSharing));

            action.Should().Throw <ArgumentNullException>();
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, TScrobbleResponseObjectType obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_ID, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteValueAsync(obj.Id, cancellationToken).ConfigureAwait(false);

            if (obj.Action != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_ACTION, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Action.ObjectName, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Progress.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_PROGRESS, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Progress, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Sharing != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHARING, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Sharing, cancellationToken).ConfigureAwait(false);
            }

            await WriteScrobbleResponseObjectAsync(jsonWriter, obj, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public void Test_SharingObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var           traktJsonWriter = new SharingObjectJsonWriter();
            ITraktSharing traktSharing    = new TraktSharing();
            Func <Task>   action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktSharing);

            action.Should().Throw <ArgumentNullException>();
        }
Beispiel #7
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, TCheckinObjectType obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Sharing != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CHECKIN_POST_PROPERTY_NAME_SHARING, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Sharing, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Message))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CHECKIN_POST_PROPERTY_NAME_MESSAGE, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Message, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.AppVersion))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CHECKIN_POST_PROPERTY_NAME_APP_VERSION, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.AppVersion, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.AppDate))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CHECKIN_POST_PROPERTY_NAME_APP_DATE, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.AppDate, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.FoursquareVenueId))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CHECKIN_POST_PROPERTY_NAME_VENUE_ID, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.FoursquareVenueId, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.FoursquareVenueName))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CHECKIN_POST_PROPERTY_NAME_VENUE_NAME, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.FoursquareVenueName, cancellationToken).ConfigureAwait(false);
            }

            await WriteCheckinObjectAsync(jsonWriter, obj, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #8
0
        protected override async Task WriteCommentObjectAsync(JsonTextWriter jsonWriter, ITraktCommentPostResponse obj, CancellationToken cancellationToken = default)
        {
            await base.WriteCommentObjectAsync(jsonWriter, obj, cancellationToken).ConfigureAwait(false);

            if (obj.Sharing != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_POST_RESPONSE_PROPERTY_NAME_SHARING, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Sharing, cancellationToken).ConfigureAwait(false);
            }
        }
        public async Task Test_SharingObjectJsonWriter_WriteObject_Object_Only_Slack_Property()
        {
            ITraktSharing traktSharing = new TraktSharing
            {
                Slack = true
            };

            var    traktJsonWriter = new SharingObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSharing);

            json.Should().Be(@"{""slack"":true}");
        }
Beispiel #10
0
        public async Task Test_SharingObjectJsonWriter_WriteObject_StringWriter_Only_Medium_Property()
        {
            ITraktSharing traktSharing = new TraktSharing
            {
                Medium = true
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new SharingObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktSharing);

                json.Should().Be(@"{""medium"":true}");
            }
        }
        public async Task Test_SharingObjectJsonWriter_WriteObject_JsonWriter_Only_Slack_Property()
        {
            ITraktSharing traktSharing = new TraktSharing
            {
                Slack = true
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SharingObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSharing);

                    stringWriter.ToString().Should().Be(@"{""slack"":true}");
                }
        }
        public async Task Test_SharingObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktSharing traktSharing = new TraktSharing
            {
                Facebook = true,
                Twitter  = true,
                Google   = true,
                Tumblr   = true,
                Medium   = true,
                Slack    = true
            };

            var    traktJsonWriter = new SharingObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSharing);

            json.Should().Be(@"{""facebook"":true,""twitter"":true,""google"":true," +
                             @"""tumblr"":true,""medium"":true,""slack"":true}");
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserSettings obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.User != null)
            {
                var userObjectJsonWriter = new UserObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_SETTINGS_PROPERTY_NAME_USER, cancellationToken).ConfigureAwait(false);

                await userObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.User, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Account != null)
            {
                var accountSettingsObjectJsonWriter = new AccountSettingsObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_SETTINGS_PROPERTY_NAME_ACCOUNT, cancellationToken).ConfigureAwait(false);

                await accountSettingsObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Account, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Connections != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_SETTINGS_PROPERTY_NAME_CONNECTIONS, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Connections, cancellationToken).ConfigureAwait(false);
            }

            if (obj.SharingText != null)
            {
                var sharingTextObjectJsonWriter = new SharingTextObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_SETTINGS_PROPERTY_NAME_SHARING_TEXT, cancellationToken).ConfigureAwait(false);

                await sharingTextObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.SharingText, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public async Task Test_SharingObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktSharing traktSharing = new TraktSharing
            {
                Twitter = true,
                Google  = true,
                Tumblr  = true,
                Medium  = true,
                Slack   = true
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SharingObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSharing);

                    stringWriter.ToString().Should().Be(@"{""twitter"":true,""google"":true," +
                                                        @"""tumblr"":true,""medium"":true,""slack"":true}");
                }
        }
Beispiel #15
0
 public async Task Test_SharingObjectJsonWriter_WriteObject_Object_Exceptions()
 {
     var traktJsonWriter          = new SharingObjectJsonWriter();
     Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default);