Exemple #1
0
 public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new EpisodeCollectionProgressObjectJsonWriter();
     ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress();
     Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktEpisodeCollectionProgress);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_StringWriter_Exceptions()
        {
            var traktJsonWriter = new EpisodeCollectionProgressObjectJsonWriter();
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress();
            Func <Task <string> >           action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktEpisodeCollectionProgress);

            action.Should().Throw <ArgumentNullException>();
        }
        public void Test_TraktEpisodeCollectionProgressCollectionProgress_Default_Constructor()
        {
            var episodeCollectionProgress = new TraktEpisodeCollectionProgress();

            episodeCollectionProgress.Number.Should().NotHaveValue();
            episodeCollectionProgress.Completed.Should().NotHaveValue();
            episodeCollectionProgress.CollectedAt.Should().NotHaveValue();
        }
Exemple #4
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_Object_Only_CollectedAt_Property()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                CollectedAt = COLLECTED_AT
            };

            var    traktJsonWriter = new EpisodeCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktEpisodeCollectionProgress);

            json.Should().Be($"{{\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}");
        }
Exemple #5
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_Object_Only_Completed_Property()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                Completed = true
            };

            var    traktJsonWriter = new EpisodeCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktEpisodeCollectionProgress);

            json.Should().Be(@"{""completed"":true}");
        }
Exemple #6
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_Object_Only_Number_Property()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                Number = 1
            };

            var    traktJsonWriter = new EpisodeCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktEpisodeCollectionProgress);

            json.Should().Be(@"{""number"":1}");
        }
        public override async Task <ITraktEpisodeCollectionProgress> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktEpisodeCollectionProgress)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress();

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

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

                        break;

                    case JsonProperties.EPISODE_COLLECTION_PROGRESS_PROPERTY_NAME_COMPLETED:
                        traktEpisodeCollectionProgress.Completed = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

                    case JsonProperties.EPISODE_COLLECTION_PROGRESS_PROPERTY_NAME_COLLECTED_AT:
                    {
                        var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktEpisodeCollectionProgress.CollectedAt = value.Second;
                        }

                        break;
                    }

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

                        break;
                    }
                }

                return(traktEpisodeCollectionProgress);
            }

            return(await Task.FromResult(default(ITraktEpisodeCollectionProgress)));
        }
Exemple #8
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                Number      = 1,
                Completed   = true,
                CollectedAt = COLLECTED_AT
            };

            var    traktJsonWriter = new EpisodeCollectionProgressObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktEpisodeCollectionProgress);

            json.Should().Be(@"{""number"":1,""completed"":true," +
                             $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}");
        }
Exemple #9
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_JsonWriter_Only_CollectedAt_Property()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                CollectedAt = COLLECTED_AT
            };

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

                    stringWriter.ToString().Should().Be($"{{\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}");
                }
        }
Exemple #10
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_JsonWriter_Only_Completed_Property()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                Completed = true
            };

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

                    stringWriter.ToString().Should().Be(@"{""completed"":true}");
                }
        }
Exemple #11
0
        public async Task Test_EpisodeCollectionProgressObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktEpisodeCollectionProgress traktEpisodeCollectionProgress = new TraktEpisodeCollectionProgress
            {
                Number      = 1,
                Completed   = true,
                CollectedAt = COLLECTED_AT
            };

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

                    stringWriter.ToString().Should().Be(@"{""number"":1,""completed"":true," +
                                                        $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}");
                }
        }