public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_StringWriter_Only_Episodes_Property()
        {
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress
            {
                Episodes = new List <ITraktEpisodeCollectionProgress>
                {
                    new TraktEpisodeCollectionProgress
                    {
                        Number      = 1,
                        Completed   = true,
                        CollectedAt = COLLECTED_AT
                    },
                    new TraktEpisodeCollectionProgress
                    {
                        Number      = 2,
                        Completed   = true,
                        CollectedAt = COLLECTED_AT
                    }
                }
            };

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

                json.Should().Be(@"{""episodes"":[" +
                                 $"{{\"number\":1,\"completed\":true,\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}," +
                                 $"{{\"number\":2,\"completed\":true,\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}" +
                                 "]}");
            }
        }
        public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress
            {
                Number    = 1,
                Aired     = 24,
                Completed = 12,
                Episodes  = new List <ITraktEpisodeCollectionProgress>
                {
                    new TraktEpisodeCollectionProgress
                    {
                        Number      = 1,
                        Completed   = true,
                        CollectedAt = COLLECTED_AT
                    },
                    new TraktEpisodeCollectionProgress
                    {
                        Number      = 2,
                        Completed   = true,
                        CollectedAt = COLLECTED_AT
                    }
                }
            };

            var    traktJsonWriter = new SeasonCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeasonCollectionProgress);

            json.Should().Be(@"{""number"":1,""aired"":24,""completed"":12," +
                             @"""episodes"":[" +
                             $"{{\"number\":1,\"completed\":true,\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}," +
                             $"{{\"number\":2,\"completed\":true,\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}" +
                             "]}");
        }
 public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var traktJsonWriter = new SeasonCollectionProgressObjectJsonWriter();
     ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress();
     Func <Task <string> >          action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktSeasonCollectionProgress);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var traktJsonWriter = new SeasonCollectionProgressObjectJsonWriter();
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress();
            Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktSeasonCollectionProgress);

            action.Should().Throw <ArgumentNullException>();
        }
コード例 #5
0
        public void Test_TraktSeasonCollectionProgress_Default_Constructor()
        {
            var seasonCollectionProgress = new TraktSeasonCollectionProgress();

            seasonCollectionProgress.Number.Should().NotHaveValue();
            seasonCollectionProgress.Aired.Should().NotHaveValue();
            seasonCollectionProgress.Completed.Should().NotHaveValue();
            seasonCollectionProgress.Episodes.Should().BeNull();
        }
        public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_Object_Only_Completed_Property()
        {
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress
            {
                Completed = 12
            };

            var    traktJsonWriter = new SeasonCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeasonCollectionProgress);

            json.Should().Be(@"{""completed"":12}");
        }
        public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_Object_Only_Number_Property()
        {
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress
            {
                Number = 1
            };

            var    traktJsonWriter = new SeasonCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeasonCollectionProgress);

            json.Should().Be(@"{""number"":1}");
        }
コード例 #8
0
        public override async Task <ITraktSeasonCollectionProgress> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktSeasonCollectionProgress)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var episodeCollectionProgressArrayReader = new EpisodeCollectionProgressArrayJsonReader();
                ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.SEASON_COLLECTION_PROGRESS_PROPERTY_NAME_NUMBER:
                        traktSeasonCollectionProgress.Number = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.SEASON_COLLECTION_PROGRESS_PROPERTY_NAME_AIRED:
                        traktSeasonCollectionProgress.Aired = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.SEASON_COLLECTION_PROGRESS_PROPERTY_NAME_COMPLETED:
                        traktSeasonCollectionProgress.Completed = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.SEASON_COLLECTION_PROGRESS_PROPERTY_NAME_EPISODES:
                        traktSeasonCollectionProgress.Episodes = await episodeCollectionProgressArrayReader.ReadArrayAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktSeasonCollectionProgress);
            }

            return(await Task.FromResult(default(ITraktSeasonCollectionProgress)));
        }
        public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_StringWriter_Only_Aired_Property()
        {
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress
            {
                Aired = 24
            };

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

                json.Should().Be(@"{""aired"":24}");
            }
        }
        public async Task Test_SeasonCollectionProgressObjectJsonWriter_WriteObject_JsonWriter_Only_Completed_Property()
        {
            ITraktSeasonCollectionProgress traktSeasonCollectionProgress = new TraktSeasonCollectionProgress
            {
                Completed = 12
            };

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

                    stringWriter.ToString().Should().Be(@"{""completed"":12}");
                }
        }