public async Task Test_CollectionMovieObjectJsonWriter_WriteObject_JsonWriter_Only_Movie_Property()
        {
            ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie
            {
                Movie = new TraktMovie
                {
                    Title = "Star Wars: The Force Awakens",
                    Year  = 2015,
                    Ids   = new TraktMovieIds
                    {
                        Trakt = 94024U,
                        Slug  = "star-wars-the-force-awakens-2015",
                        Imdb  = "tt2488496",
                        Tmdb  = 140607U
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be(@"{""movie"":{""title"":""Star Wars: The Force Awakens"",""year"":2015," +
                                                        @"""ids"":{""trakt"":94024,""slug"":""star-wars-the-force-awakens-2015""," +
                                                        @"""imdb"":""tt2488496"",""tmdb"":140607}}}");
                }
        }
Exemplo n.º 2
0
        public void Test_TraktCollectionMovie_Default_Constructor()
        {
            var collectionMovie = new TraktCollectionMovie();

            collectionMovie.CollectedAt.Should().NotHaveValue();
            collectionMovie.Metadata.Should().BeNull();

            collectionMovie.Movie.Should().BeNull();
            collectionMovie.Title.Should().BeNullOrEmpty();
            collectionMovie.Year.Should().NotHaveValue();
            collectionMovie.Ids.Should().BeNull();
            collectionMovie.Tagline.Should().BeNullOrEmpty();
            collectionMovie.Overview.Should().BeNullOrEmpty();
            collectionMovie.Released.Should().NotHaveValue();
            collectionMovie.Runtime.Should().NotHaveValue();
            collectionMovie.UpdatedAt.Should().NotHaveValue();
            collectionMovie.Trailer.Should().BeNullOrEmpty();
            collectionMovie.Homepage.Should().BeNullOrEmpty();
            collectionMovie.Rating.Should().NotHaveValue();
            collectionMovie.Votes.Should().NotHaveValue();
            collectionMovie.LanguageCode.Should().BeNullOrEmpty();
            collectionMovie.AvailableTranslationLanguageCodes.Should().BeNull();
            collectionMovie.Genres.Should().BeNull();
            collectionMovie.Certification.Should().BeNullOrEmpty();
            collectionMovie.CountryCode.Should().BeNullOrEmpty();
        }
 public async Task Test_CollectionMovieObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new CollectionMovieObjectJsonWriter();
     ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie();
     Func <Task>           action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCollectionMovie);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
Exemplo n.º 4
0
        public void TestTraktCollectionMovieDefaultConstructor()
        {
            var collectionMovie = new TraktCollectionMovie();

            collectionMovie.CollectedAt.Should().NotHaveValue();
            collectionMovie.Movie.Should().BeNull();
            collectionMovie.Metadata.Should().BeNull();
        }
        public void Test_CollectionMovieObjectJsonWriter_WriteObject_StringWriter_Exceptions()
        {
            var traktJsonWriter = new CollectionMovieObjectJsonWriter();
            ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie();
            Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCollectionMovie);

            action.Should().Throw <ArgumentNullException>();
        }
        public override async Task <ITraktCollectionMovie> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktCollectionMovie)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader    = new MovieObjectJsonReader();
                var metadataObjectReader = new MetadataObjectJsonReader();

                ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie();

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

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

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

                        break;
                    }

                    case JsonProperties.COLLECTION_MOVIE_PROPERTY_NAME_MOVIE:
                        traktCollectionMovie.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.COLLECTION_MOVIE_PROPERTY_NAME_METADATA:
                        traktCollectionMovie.Metadata = await metadataObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktCollectionMovie);
            }

            return(await Task.FromResult(default(ITraktCollectionMovie)));
        }
        public async Task Test_CollectionMovieObjectJsonWriter_WriteObject_StringWriter_Only_CollectedAt_Property()
        {
            ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie
            {
                CollectedAt = COLLECTED_AT
            };

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

                json.Should().Be($"{{\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}");
            }
        }
        public async Task Test_CollectionMovieObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie
            {
                CollectedAt = COLLECTED_AT,
                Metadata    = new TraktMetadata
                {
                    MediaType        = TraktMediaType.Bluray,
                    MediaResolution  = TraktMediaResolution.HD_1080p,
                    Audio            = TraktMediaAudio.DTS,
                    AudioChannels    = TraktMediaAudioChannel.Channels_6_1,
                    ThreeDimensional = false
                },
                Movie = new TraktMovie
                {
                    Title = "Star Wars: The Force Awakens",
                    Year  = 2015,
                    Ids   = new TraktMovieIds
                    {
                        Trakt = 94024U,
                        Slug  = "star-wars-the-force-awakens-2015",
                        Imdb  = "tt2488496",
                        Tmdb  = 140607U
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be($"{{\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""movie"":{""title"":""Star Wars: The Force Awakens"",""year"":2015," +
                                                        @"""ids"":{""trakt"":94024,""slug"":""star-wars-the-force-awakens-2015""," +
                                                        @"""imdb"":""tt2488496"",""tmdb"":140607}}," +
                                                        @"""metadata"":{""media_type"":""bluray"",""resolution"":""hd_1080p""," +
                                                        @"""audio"":""dts"",""audio_channels"":""6.1"",""3d"":false}}");
                }
        }
        public async Task Test_CollectionMovieObjectJsonWriter_WriteObject_StringWriter_Only_Metadata_Property()
        {
            ITraktCollectionMovie traktCollectionMovie = new TraktCollectionMovie
            {
                Metadata = new TraktMetadata
                {
                    MediaType        = TraktMediaType.Bluray,
                    MediaResolution  = TraktMediaResolution.HD_1080p,
                    Audio            = TraktMediaAudio.DTS,
                    AudioChannels    = TraktMediaAudioChannel.Channels_6_1,
                    ThreeDimensional = false
                }
            };

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

                json.Should().Be(@"{""metadata"":{""media_type"":""bluray"",""resolution"":""hd_1080p""," +
                                 @"""audio"":""dts"",""audio_channels"":""6.1"",""3d"":false}}");
            }
        }