Exemple #1
0
        public void Test_TraktListIds_GetBestId()
        {
            var listIds = new TraktListIds();

            var bestId = listIds.GetBestId();

            bestId.Should().NotBeNull().And.BeEmpty();

            listIds = new TraktListIds {
                Trakt = 1
            };

            bestId = listIds.GetBestId();
            bestId.Should().Be("1");

            listIds = new TraktListIds {
                Slug = "slug"
            };

            bestId = listIds.GetBestId();
            bestId.Should().Be("slug");

            listIds = new TraktListIds
            {
                Trakt = 1,
                Slug  = "slug"
            };

            bestId = listIds.GetBestId();
            bestId.Should().Be("1");

            new TraktListIds().GetBestId().Should().NotBeNull().And.BeEmpty();
        }
Exemple #2
0
        public void Test_TraktListIds_Default_Constructor()
        {
            var listIds = new TraktListIds();

            listIds.Trakt.Should().Be(0);
            listIds.Slug.Should().BeNull();
            listIds.HasAnyId.Should().BeFalse();
        }
Exemple #3
0
        public void Test_TraktListIds_HasAnyId()
        {
            var listIds = new TraktListIds {
                Trakt = 1
            };

            listIds.HasAnyId.Should().BeTrue();

            listIds = new TraktListIds {
                Slug = "slug"
            };
            listIds.HasAnyId.Should().BeTrue();
        }
        public override async Task <ITraktListIds> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktListIds)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktListIds traktListIds = new TraktListIds();

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

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

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

                        break;
                    }

                    case JsonProperties.LIST_IDS_PROPERTY_NAME_SLUG:
                        traktListIds.Slug = jsonReader.ReadAsString();
                        break;

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

                        break;
                    }
                }

                return(traktListIds);
            }

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