コード例 #1
0
 public async Task Test_StatisticsObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new StatisticsObjectJsonWriter();
     ITraktStatistics traktStatistics = new TraktStatistics();
     Func <Task>      action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktStatistics);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
コード例 #2
0
        public void Test_StatisticsObjectJsonWriter_WriteObject_StringWriter_Exceptions()
        {
            var traktJsonWriter = new StatisticsObjectJsonWriter();
            ITraktStatistics      traktStatistics = new TraktStatistics();
            Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktStatistics);

            action.Should().Throw <ArgumentNullException>();
        }
コード例 #3
0
        public void Test_TraktStatistics_Default_Constructor()
        {
            var traktStatistics = new TraktStatistics();

            traktStatistics.Watchers.Should().BeNull();
            traktStatistics.Plays.Should().BeNull();
            traktStatistics.Collectors.Should().BeNull();
            traktStatistics.CollectedEpisodes.Should().BeNull();
            traktStatistics.Comments.Should().BeNull();
            traktStatistics.Lists.Should().BeNull();
            traktStatistics.Votes.Should().BeNull();
        }
コード例 #4
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_Object_Only_Lists_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Lists = 6
            };

            var    traktJsonWriter = new StatisticsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktStatistics);

            json.Should().Be(@"{""lists"":6}");
        }
コード例 #5
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_Object_Only_CollectedEpisodes_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                CollectedEpisodes = 4
            };

            var    traktJsonWriter = new StatisticsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktStatistics);

            json.Should().Be(@"{""collected_episodes"":4}");
        }
コード例 #6
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_Object_Only_Watchers_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Watchers = 1
            };

            var    traktJsonWriter = new StatisticsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktStatistics);

            json.Should().Be(@"{""watchers"":1}");
        }
コード例 #7
0
        public void TestTraktStatisticsDefaultConstructor()
        {
            var stats = new TraktStatistics();

            stats.Watchers.Should().NotHaveValue();
            stats.Plays.Should().NotHaveValue();
            stats.Collectors.Should().NotHaveValue();
            stats.CollectedEpisodes.Should().NotHaveValue();
            stats.Comments.Should().NotHaveValue();
            stats.Lists.Should().NotHaveValue();
            stats.Votes.Should().NotHaveValue();
        }
コード例 #8
0
        public override async Task<ITraktStatistics> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktStatistics traktStatistics = new TraktStatistics();

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

                    switch (propertyName)
                    {
                        case JsonProperties.PROPERTY_NAME_WATCHERS:
                            traktStatistics.Watchers = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_PLAYS:
                            traktStatistics.Plays = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_COLLECTORS:
                            traktStatistics.Collectors = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_COLLECTED_EPISODES:
                            traktStatistics.CollectedEpisodes = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_COMMENTS:
                            traktStatistics.Comments = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_LISTS:
                            traktStatistics.Lists = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_VOTES:
                            traktStatistics.Votes = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_RECOMMENDED:
                            traktStatistics.Recommended = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        default:
                            await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);
                            break;
                    }
                }

                return traktStatistics;
            }

            return await Task.FromResult(default(ITraktStatistics));
        }
コード例 #9
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_StringWriter_Only_Comments_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Comments = 5
            };

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

                json.Should().Be(@"{""comments"":5}");
            }
        }
コード例 #10
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_StringWriter_Only_Recommended_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Recommended = 8
            };

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

                json.Should().Be(@"{""recommended"":8}");
            }
        }
コード例 #11
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_JsonWriter_Only_CollectedEpisodes_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                CollectedEpisodes = 4
            };

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

                    stringWriter.ToString().Should().Be(@"{""collected_episodes"":4}");
                }
        }
コード例 #12
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_JsonWriter_Only_Plays_Property()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Plays = 2
            };

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

                    stringWriter.ToString().Should().Be(@"{""plays"":2}");
                }
        }
コード例 #13
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Watchers          = 1,
                Plays             = 2,
                Collectors        = 3,
                CollectedEpisodes = 4,
                Comments          = 5,
                Lists             = 6,
                Votes             = 7
            };

            var    traktJsonWriter = new StatisticsObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktStatistics);

            json.Should().Be(@"{""watchers"":1,""plays"":2,""collectors"":3," +
                             @"""collected_episodes"":4,""comments"":5,""lists"":6,""votes"":7}");
        }
コード例 #14
0
        public async Task Test_StatisticsObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktStatistics traktStatistics = new TraktStatistics
            {
                Watchers          = 1,
                Plays             = 2,
                Collectors        = 3,
                CollectedEpisodes = 4,
                Comments          = 5,
                Lists             = 6,
                Votes             = 7
            };

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

                    stringWriter.ToString().Should().Be(@"{""watchers"":1,""plays"":2,""collectors"":3," +
                                                        @"""collected_episodes"":4,""comments"":5,""lists"":6,""votes"":7}");
                }
        }