public async Task Test_IdsObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var         traktJsonWriter = new IdsObjectJsonWriter();
     ITraktIds   traktIds        = new TraktIds();
     Func <Task> action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktIds);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void Test_IdsObjectJsonWriter_WriteObject_StringWriter_Exceptions()
        {
            var                   traktJsonWriter = new IdsObjectJsonWriter();
            ITraktIds             traktIds        = new TraktIds();
            Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktIds);

            action.Should().Throw <ArgumentNullException>();
        }
        public void Test_TraktIds_Default_Constructor()
        {
            var traktIds = new TraktIds();

            traktIds.Trakt.Should().Be(0);
            traktIds.Slug.Should().BeNull();
            traktIds.Tvdb.Should().BeNull();
            traktIds.Imdb.Should().BeNull();
            traktIds.Tmdb.Should().BeNull();
            traktIds.TvRage.Should().BeNull();
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_Object_Only_TvRage_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                TvRage = 101
            };

            var    traktJsonWriter = new IdsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktIds);

            json.Should().Be(@"{""trakt"":0,""tvrage"":101}");
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_Object_Only_Tmdb_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                Tmdb = 789
            };

            var    traktJsonWriter = new IdsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktIds);

            json.Should().Be(@"{""trakt"":0,""tmdb"":789}");
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_Object_Only_Slug_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                Slug = "ids slug"
            };

            var    traktJsonWriter = new IdsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktIds);

            json.Should().Be(@"{""trakt"":0,""slug"":""ids slug""}");
        }
        public void TestTraktIdsDefaultConstructor()
        {
            var ids = new TraktIds();

            ids.Trakt.Should().Be(0);
            ids.Slug.Should().BeNullOrEmpty();
            ids.Tvdb.Should().BeNull();
            ids.Imdb.Should().BeNullOrEmpty();
            ids.Tmdb.Should().BeNull();
            ids.TvRage.Should().BeNull();
            ids.HasAnyId.Should().BeFalse();
            ids.GetBestId().Should().BeEmpty();
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_StringWriter_Only_Imdb_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                Imdb = "ids imdb"
            };

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

                json.Should().Be(@"{""trakt"":0,""imdb"":""ids imdb""}");
            }
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_StringWriter_Only_Trakt_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                Trakt = 123
            };

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

                json.Should().Be(@"{""trakt"":123}");
            }
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_JsonWriter_Only_Tmdb_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                Tmdb = 789
            };

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

                    stringWriter.ToString().Should().Be(@"{""trakt"":0,""tmdb"":789}");
                }
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_JsonWriter_Only_Slug_Property()
        {
            ITraktIds traktIds = new TraktIds
            {
                Slug = "ids slug"
            };

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

                    stringWriter.ToString().Should().Be(@"{""trakt"":0,""slug"":""ids slug""}");
                }
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktIds traktIds = new TraktIds
            {
                Trakt  = 123,
                Slug   = "ids slug",
                Tvdb   = 456,
                Imdb   = "ids imdb",
                Tmdb   = 789,
                TvRage = 101
            };

            var    traktJsonWriter = new IdsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktIds);

            json.Should().Be(@"{""trakt"":123,""slug"":""ids slug"",""tvdb"":456," +
                             @"""imdb"":""ids imdb"",""tmdb"":789,""tvrage"":101}");
        }
        public async Task Test_IdsObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktIds traktIds = new TraktIds
            {
                Trakt  = 123,
                Slug   = "ids slug",
                Tvdb   = 456,
                Imdb   = "ids imdb",
                Tmdb   = 789,
                TvRage = 101
            };

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

                    stringWriter.ToString().Should().Be(@"{""trakt"":123,""slug"":""ids slug"",""tvdb"":456," +
                                                        @"""imdb"":""ids imdb"",""tmdb"":789,""tvrage"":101}");
                }
        }
Exemple #14
0
        public override async Task <ITraktIds> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktIds traktIds = new TraktIds();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_TRAKT:
                    {
                        var value = await JsonReaderHelper.ReadUnsignedIntegerValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktIds.Trakt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_SLUG:
                        traktIds.Slug = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

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

                        if (value.First)
                        {
                            traktIds.Tvdb = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_IMDB:
                        traktIds.Imdb = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

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

                        if (value.First)
                        {
                            traktIds.Tmdb = value.Second;
                        }

                        break;
                    }

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

                        if (value.First)
                        {
                            traktIds.TvRage = value.Second;
                        }

                        break;
                    }

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

                        break;
                    }
                }

                return(traktIds);
            }

            return(await Task.FromResult(default(ITraktIds)));
        }