Esempio n. 1
0
        public async Task Test_CrewMemberObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktCrewMember traktCrewMember = new TraktCrewMember
            {
                Jobs = new List <string>
                {
                    "Crew Member"
                },
                Person = new TraktPerson
                {
                    Name = "Bryan Cranston",
                    Ids  = new TraktPersonIds
                    {
                        Trakt  = 297737U,
                        Slug   = "bryan-cranston",
                        Imdb   = "nm0186505",
                        Tmdb   = 17419U,
                        TvRage = 1797U
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be(@"{""jobs"":[""Crew Member""]," +
                                                        @"""person"":{""name"":""Bryan Cranston""," +
                                                        @"""ids"":{""trakt"":297737,""slug"":""bryan-cranston""," +
                                                        @"""imdb"":""nm0186505"",""tmdb"":17419,""tvrage"":1797}}}");
                }
        }
Esempio n. 2
0
        public async Task Test_CrewMemberObjectJsonWriter_WriteObject_StringWriter_Only_Person_Property()
        {
            ITraktCrewMember traktCrewMember = new TraktCrewMember
            {
                Person = new TraktPerson
                {
                    Name = "Bryan Cranston",
                    Ids  = new TraktPersonIds
                    {
                        Trakt  = 297737U,
                        Slug   = "bryan-cranston",
                        Imdb   = "nm0186505",
                        Tmdb   = 17419U,
                        TvRage = 1797U
                    }
                }
            };

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

                json.Should().Be(@"{""person"":{""name"":""Bryan Cranston""," +
                                 @"""ids"":{""trakt"":297737,""slug"":""bryan-cranston""," +
                                 @"""imdb"":""nm0186505"",""tmdb"":17419,""tvrage"":1797}}}");
            }
        }
 public async Task Test_CrewMemberObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new CrewMemberObjectJsonWriter();
     ITraktCrewMember traktCrewMember = new TraktCrewMember();
     Func <Task>      action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCrewMember);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void TestTraktCrewMemberDefaultConstructor()
        {
            var crewMember = new TraktCrewMember();

            crewMember.Job.Should().BeNullOrEmpty();
            crewMember.Person.Should().BeNull();
        }
Esempio n. 5
0
        public void Test_TraktCrewMember_Default_Constructor()
        {
            var traktCrewMember = new TraktCrewMember();

            traktCrewMember.Job.Should().BeNull();
            traktCrewMember.Person.Should().BeNull();
        }
Esempio n. 6
0
        public void Test_CrewMemberObjectJsonWriter_WriteObject_StringWriter_Exceptions()
        {
            var traktJsonWriter = new CrewMemberObjectJsonWriter();
            ITraktCrewMember      traktCrewMember = new TraktCrewMember();
            Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCrewMember);

            action.Should().Throw <ArgumentNullException>();
        }
Esempio n. 7
0
        public async Task Test_CrewMemberObjectJsonWriter_WriteObject_StringWriter_Empty()
        {
            ITraktCrewMember traktCrewMember = new TraktCrewMember();

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

                json.Should().Be(@"{}");
            }
        }
Esempio n. 8
0
        public async Task Test_CrewMemberObjectJsonWriter_WriteObject_JsonWriter_Empty()
        {
            ITraktCrewMember traktCrewMember = new TraktCrewMember();

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

                    stringWriter.ToString().Should().Be(@"{}");
                }
        }
Esempio n. 9
0
        public async Task Test_CrewMemberObjectJsonWriter_WriteObject_StringWriter_Only_Jobs_Property()
        {
            ITraktCrewMember traktCrewMember = new TraktCrewMember
            {
                Jobs = new List <string>
                {
                    "Crew Member"
                }
            };

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

                json.Should().Be(@"{""jobs"":[""Crew Member""]}");
            }
        }
        public override async Task <ITraktCrewMember> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktCrewMember)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var personReader = new PersonObjectJsonReader();
                ITraktCrewMember traktCrewMember = new TraktCrewMember();

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

                    switch (propertyName)
                    {
                    case JsonProperties.CREW_MEMBER_PROPERTY_NAME_JOB:
                        traktCrewMember.Job = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.CREW_MEMBER_PROPERTY_NAME_PERSON:
                        traktCrewMember.Person = await personReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktCrewMember);
            }

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