예제 #1
0
        public async Task Test_SyncRecommendationsPostMovieObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktSyncRecommendationsPostMovie traktSyncRecommendationsPostMovie = new TraktSyncRecommendationsPostMovie
            {
                Title = "Batman Begins",
                Year  = 2005,
                Ids   = new TraktMovieIds
                {
                    Trakt = 1,
                    Slug  = "batman-begins-2005",
                    Imdb  = "tt0372784",
                    Tmdb  = 272
                },
                Notes = "One of Chritian Bale's most iconic roles."
            };

            using var stringWriter = new StringWriter();
            using var jsonWriter   = new JsonTextWriter(stringWriter);
            var traktJsonWriter = new SyncRecommendationsPostMovieObjectJsonWriter();
            await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSyncRecommendationsPostMovie);

            stringWriter.ToString().Should().Be(@"{""title"":""Batman Begins"",""year"":2005," +
                                                @"""ids"":{""trakt"":1,""slug"":""batman-begins-2005""," +
                                                @"""imdb"":""tt0372784"",""tmdb"":272}," +
                                                @"""notes"":""One of Chritian Bale's most iconic roles.""}");
        }
예제 #2
0
 public async Task Test_SyncRecommendationsPostMovieObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new SyncRecommendationsPostMovieObjectJsonWriter();
     ITraktSyncRecommendationsPostMovie traktSyncRecommendationsPostMovie = new TraktSyncRecommendationsPostMovie();
     Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktSyncRecommendationsPostMovie);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void Test_TraktSyncRecommendationsPostMovie_Default_Constructor()
        {
            var syncRecommendationsPostMovie = new TraktSyncRecommendationsPostMovie();

            syncRecommendationsPostMovie.Title.Should().BeNull();
            syncRecommendationsPostMovie.Year.Should().BeNull();
            syncRecommendationsPostMovie.Ids.Should().BeNull();
            syncRecommendationsPostMovie.Notes.Should().BeNull();
        }
        private ITraktSyncRecommendationsPostMovie CreateSyncRecommendationsPostMovie(ITraktMovie movie, string notes = null)
        {
            var syncRecommendationsPostMovie = new TraktSyncRecommendationsPostMovie
            {
                Ids   = movie.Ids,
                Title = movie.Title,
                Year  = movie.Year
            };

            if (!string.IsNullOrWhiteSpace(notes))
            {
                syncRecommendationsPostMovie.Notes = notes;
            }

            return(syncRecommendationsPostMovie);
        }
예제 #5
0
        public override async Task <ITraktSyncRecommendationsPostMovie> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktSyncRecommendationsPostMovie traktSyncRecommendationsPostMovie = new TraktSyncRecommendationsPostMovie();
                var movieIdsObjectJsonReader = new MovieIdsObjectJsonReader();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_TITLE:
                        traktSyncRecommendationsPostMovie.Title = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_YEAR:
                        traktSyncRecommendationsPostMovie.Year = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_IDS:
                        traktSyncRecommendationsPostMovie.Ids = await movieIdsObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_NOTES:
                        traktSyncRecommendationsPostMovie.Notes = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktSyncRecommendationsPostMovie);
            }

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