Ejemplo n.º 1
0
        public void TestTraktCastMemberDefaultConstructor()
        {
            var castMember = new TraktCastMember();

            castMember.Character.Should().BeNullOrEmpty();
            castMember.Person.Should().BeNull();
        }
Ejemplo n.º 2
0
        public void Test_TraktCastMember_Default_Constructor()
        {
            var traktCastMember = new TraktCastMember();

            traktCastMember.Character.Should().BeNull();
            traktCastMember.Person.Should().BeNull();
        }
Ejemplo n.º 3
0
        public async Task Test_CastMemberObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktCastMember traktCastMember = new TraktCastMember
            {
                Characters = new List <string>
                {
                    "Character"
                },
                Person = new TraktPerson
                {
                    Name = "Person",
                    Ids  = new TraktPersonIds
                    {
                        Slug = "person"
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be(@"{""characters"":[""Character""],""person"":{""name"":""Person"",""ids"":{""trakt"":0,""slug"":""person""}}}");
                }
        }
Ejemplo n.º 4
0
 public async Task Test_CastMemberObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new CastMemberObjectJsonWriter();
     ITraktCastMember traktCastMember = new TraktCastMember();
     Func <Task>      action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCastMember);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
Ejemplo n.º 5
0
        public void Test_CastMemberObjectJsonWriter_WriteObject_StringWriter_Exceptions()
        {
            var traktJsonWriter = new CastMemberObjectJsonWriter();
            ITraktCastMember      traktCastMember = new TraktCastMember();
            Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCastMember);

            action.Should().Throw <ArgumentNullException>();
        }
        public async Task Test_CastMemberObjectJsonWriter_WriteObject_StringWriter_Empty()
        {
            ITraktCastMember traktCastMember = new TraktCastMember();

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

                json.Should().Be("{}");
            }
        }
Ejemplo n.º 7
0
        public async Task Test_CastMemberObjectJsonWriter_WriteObject_JsonWriter_Empty()
        {
            ITraktCastMember traktCastMember = new TraktCastMember();

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

                    stringWriter.ToString().Should().Be("{}");
                }
        }
        public async Task Test_CastMemberObjectJsonWriter_WriteObject_StringWriter_Only_Characters_Property()
        {
            ITraktCastMember traktCastMember = new TraktCastMember
            {
                Characters = new List <string>
                {
                    "Character"
                }
            };

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

                json.Should().Be(@"{""characters"":[""Character""]}");
            }
        }
Ejemplo n.º 9
0
        public override async Task <ITraktCastMember> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktCastMember)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var personReader = new PersonObjectJsonReader();
                ITraktCastMember traktCastMember = new TraktCastMember();

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

                    switch (propertyName)
                    {
                    case JsonProperties.CAST_MEMBER_PROPERTY_NAME_CHARACTER:
                        traktCastMember.Character = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.CAST_MEMBER_PROPERTY_NAME_PERSON:
                        traktCastMember.Person = await personReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktCastMember);
            }

            return(await Task.FromResult(default(ITraktCastMember)));
        }
        public async Task Test_CastMemberObjectJsonWriter_WriteObject_StringWriter_Only_Person_Property()
        {
            ITraktCastMember traktCastMember = new TraktCastMember
            {
                Person = new TraktPerson
                {
                    Name = "Person",
                    Ids  = new TraktPersonIds
                    {
                        Slug = "person"
                    }
                }
            };

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

                json.Should().Be(@"{""person"":{""name"":""Person"",""ids"":{""trakt"":0,""slug"":""person""}}}");
            }
        }