Ejemplo n.º 1
0
 public async Task Test_CastAndCrewObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var traktJsonWriter = new CastAndCrewObjectJsonWriter();
     ITraktCastAndCrew     traktCastAndCrew = new TraktCastAndCrew();
     Func <Task <string> > action           = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCastAndCrew);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void TestTraktCastAndCrewDefaultConstructor()
        {
            var castAndCrew = new TraktCastAndCrew();

            castAndCrew.Cast.Should().BeNull();
            castAndCrew.Crew.Should().BeNull();
        }
        public void Test_TraktCastAndCrew_Default_Constructor()
        {
            var traktCastAndCrew = new TraktCastAndCrew();

            traktCastAndCrew.Cast.Should().BeNull();
            traktCastAndCrew.Crew.Should().BeNull();
        }
        public void Test_CastAndCrewObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var traktJsonWriter = new CastAndCrewObjectJsonWriter();
            ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew();
            Func <Task>       action           = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCastAndCrew);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 5
0
        public async Task Test_CastAndCrewObjectJsonWriter_WriteObject_StringWriter_Empty()
        {
            ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew();

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

                json.Should().Be("{}");
            }
        }
        public async Task Test_CastAndCrewObjectJsonWriter_WriteObject_JsonWriter_Empty()
        {
            ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew();

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

                    stringWriter.ToString().Should().Be("{}");
                }
        }
        public async Task Test_CastAndCrewObjectJsonWriter_WriteObject_JsonWriter_Only_Cast_Property()
        {
            ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew
            {
                Cast = new List <ITraktCastMember>
                {
                    new TraktCastMember
                    {
                        Characters = new List <string>
                        {
                            "Character 1"
                        },
                        Person = new TraktPerson
                        {
                            Name = "Person 1",
                            Ids  = new TraktPersonIds
                            {
                                Slug = "person-1"
                            }
                        }
                    },
                    new TraktCastMember
                    {
                        Characters = new List <string>
                        {
                            "Character 2"
                        },
                        Person = new TraktPerson
                        {
                            Name = "Person 2",
                            Ids  = new TraktPersonIds
                            {
                                Slug = "person-2"
                            }
                        }
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be(@"{""cast"":[{""characters"":[""Character 1""],""person"":{""name"":""Person 1"",""ids"":{""trakt"":0,""slug"":""person-1""}}}," +
                                                        @"{""characters"":[""Character 2""],""person"":{""name"":""Person 2"",""ids"":{""trakt"":0,""slug"":""person-2""}}}]}");
                }
        }
Ejemplo n.º 8
0
        public override async Task <ITraktCastAndCrew> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktCastAndCrew)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var castReader = new CastMemberArrayJsonReader();
                var crewReader = new CrewObjectJsonReader();
                ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew();

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

                    switch (propertyName)
                    {
                    case JsonProperties.CAST_AND_CREW_PROPERTY_NAME_CAST:
                        traktCastAndCrew.Cast = await castReader.ReadArrayAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.CAST_AND_CREW_PROPERTY_NAME_CREW:
                        traktCastAndCrew.Crew = await crewReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktCastAndCrew);
            }

            return(await Task.FromResult(default(ITraktCastAndCrew)));
        }
Ejemplo n.º 9
0
        public async Task Test_CastAndCrewObjectJsonWriter_WriteObject_StringWriter_Only_Crew_Property()
        {
            ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew
            {
                Crew = new TraktCrew
                {
                    Directing = new List <ITraktCrewMember>
                    {
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Director 1"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 1",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-1"
                                }
                            }
                        },
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Director 2"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 2",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-2"
                                }
                            }
                        }
                    },
                    Editing = new List <ITraktCrewMember>
                    {
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Editor 1"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 3",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-3"
                                }
                            }
                        },
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Editor 2"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 4",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-4"
                                }
                            }
                        }
                    }
                }
            };

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

                json.Should().Be(@"{""crew"":{" +
                                 @"""directing"":" +
                                 @"[{""jobs"":[""Director 1""],""person"":{""name"":""Person 1"",""ids"":{""trakt"":0,""slug"":""person-1""}}}," +
                                 @"{""jobs"":[""Director 2""],""person"":{""name"":""Person 2"",""ids"":{""trakt"":0,""slug"":""person-2""}}}]," +
                                 @"""editing"":" +
                                 @"[{""jobs"":[""Editor 1""],""person"":{""name"":""Person 3"",""ids"":{""trakt"":0,""slug"":""person-3""}}}," +
                                 @"{""jobs"":[""Editor 2""],""person"":{""name"":""Person 4"",""ids"":{""trakt"":0,""slug"":""person-4""}}}]" +
                                 @"}}");
            }
        }
        public async Task Test_CastAndCrewObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew
            {
                Cast = new List <ITraktCastMember>
                {
                    new TraktCastMember
                    {
                        Characters = new List <string>
                        {
                            "Character 1"
                        },
                        Person = new TraktPerson
                        {
                            Name = "Person 1",
                            Ids  = new TraktPersonIds
                            {
                                Slug = "person-1"
                            }
                        }
                    },
                    new TraktCastMember
                    {
                        Characters = new List <string>
                        {
                            "Character 2"
                        },
                        Person = new TraktPerson
                        {
                            Name = "Person 2",
                            Ids  = new TraktPersonIds
                            {
                                Slug = "person-2"
                            }
                        }
                    }
                },
                Crew = new TraktCrew
                {
                    Directing = new List <ITraktCrewMember>
                    {
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Director 1"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 1",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-1"
                                }
                            }
                        },
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Director 2"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 2",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-2"
                                }
                            }
                        }
                    },
                    Editing = new List <ITraktCrewMember>
                    {
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Editor 1"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 3",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-3"
                                }
                            }
                        },
                        new TraktCrewMember
                        {
                            Jobs = new List <string>
                            {
                                "Editor 2"
                            },
                            Person = new TraktPerson
                            {
                                Name = "Person 4",
                                Ids  = new TraktPersonIds
                                {
                                    Slug = "person-4"
                                }
                            }
                        }
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be(@"{""cast"":[{""characters"":[""Character 1""],""person"":{""name"":""Person 1"",""ids"":{""trakt"":0,""slug"":""person-1""}}}," +
                                                        @"{""characters"":[""Character 2""],""person"":{""name"":""Person 2"",""ids"":{""trakt"":0,""slug"":""person-2""}}}]," +
                                                        @"""crew"":{" +
                                                        @"""directing"":" +
                                                        @"[{""jobs"":[""Director 1""],""person"":{""name"":""Person 1"",""ids"":{""trakt"":0,""slug"":""person-1""}}}," +
                                                        @"{""jobs"":[""Director 2""],""person"":{""name"":""Person 2"",""ids"":{""trakt"":0,""slug"":""person-2""}}}]," +
                                                        @"""editing"":" +
                                                        @"[{""jobs"":[""Editor 1""],""person"":{""name"":""Person 3"",""ids"":{""trakt"":0,""slug"":""person-3""}}}," +
                                                        @"{""jobs"":[""Editor 2""],""person"":{""name"":""Person 4"",""ids"":{""trakt"":0,""slug"":""person-4""}}}]}" +
                                                        @"}");
                }
        }