public void Test_AuthorizationObjectJsonWriter_WriteObject_Object_Exceptions()
        {
            var traktJsonWriter          = new AuthorizationObjectJsonWriter();
            Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(ITraktAuthorization));

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 2
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_StringWriter_Complete()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                AccessToken        = "mockAccessToken",
                RefreshToken       = "mockRefreshToken",
                Scope              = TraktAccessScope.Public,
                ExpiresInSeconds   = 7200,
                TokenType          = TraktAccessTokenType.Bearer,
                CreatedAtTimestamp = 1506271312UL,
                IgnoreExpiration   = true
            };

            using (var stringWriter = new StringWriter())
            {
                var traktJsonWriter = new AuthorizationObjectJsonWriter
                {
                    CompleteSerialization = true
                };

                string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktAuthorization);

                json.Should().Be(@"{""access_token"":""mockAccessToken"",""refresh_token"":""mockRefreshToken""," +
                                 @"""scope"":""public"",""expires_in"":7200,""token_type"":""bearer""," +
                                 @"""created_at"":1506271312,""ignore_expiration"":true}");
            }
        }
 public async Task Test_AuthorizationObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var traktJsonWriter = new AuthorizationObjectJsonWriter();
     ITraktAuthorization   traktAuthorization = new TraktAuthorization();
     Func <Task <string> > action             = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktAuthorization);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
Ejemplo n.º 4
0
        public void Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var traktJsonWriter = new AuthorizationObjectJsonWriter();
            ITraktAuthorization traktAuthorization = new TraktAuthorization();
            Func <Task>         action             = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktAuthorization);

            action.Should().Throw <ArgumentNullException>();
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Empty()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization();
            var    traktJsonWriter = new AuthorizationObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be("{}");
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Only_TokenType_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                TokenType = TraktAccessTokenType.Bearer
            };

            var    traktJsonWriter = new AuthorizationObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be(@"{""token_type"":""bearer""}");
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Only_ExpiresInSeconds_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                ExpiresInSeconds = 7200
            };

            var    traktJsonWriter = new AuthorizationObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be(@"{""expires_in"":7200}");
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Only_Scope_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                Scope = TraktAccessScope.Public
            };

            var    traktJsonWriter = new AuthorizationObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be(@"{""scope"":""public""}");
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Only_RefreshToken_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                RefreshToken = "mockRefreshToken"
            };

            var    traktJsonWriter = new AuthorizationObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be(@"{""refresh_token"":""mockRefreshToken""}");
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Only_CreatedAtTimestamp_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                CreatedAtTimestamp = 1506271312UL
            };

            var    traktJsonWriter = new AuthorizationObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be(@"{""created_at"":1506271312}");
        }
Ejemplo n.º 11
0
        public static Task <string> SerializeAsync(ITraktAuthorization authorization, CancellationToken cancellationToken = default)
        {
            if (authorization == null)
            {
                throw new ArgumentNullException(nameof(authorization), "authorization must not be null");
            }

            IObjectJsonWriter <ITraktAuthorization> objectJsonWriter = JsonFactoryContainer.CreateObjectWriter <ITraktAuthorization>();
            AuthorizationObjectJsonWriter           authorizationObjectJsonWriter = (objectJsonWriter as AuthorizationObjectJsonWriter);

            authorizationObjectJsonWriter.CompleteSerialization = true;
            return(authorizationObjectJsonWriter.WriteObjectAsync(authorization, cancellationToken));
        }
Ejemplo n.º 12
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Empty()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization();

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

                    stringWriter.ToString().Should().Be("{}");
                }
        }
Ejemplo n.º 13
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_StringWriter_Only_AccessToken_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                AccessToken = "mockAccessToken"
            };

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

                json.Should().Be(@"{""access_token"":""mockAccessToken""}");
            }
        }
Ejemplo n.º 14
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Only_CreatedAtTimestamp_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                CreatedAtTimestamp = 1506271312UL
            };

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

                    stringWriter.ToString().Should().Be(@"{""created_at"":1506271312}");
                }
        }
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_Object_Only_IgnoreExpiration_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                IgnoreExpiration = true
            };

            var traktJsonWriter = new AuthorizationObjectJsonWriter
            {
                CompleteSerialization = true
            };

            string json = await traktJsonWriter.WriteObjectAsync(traktAuthorization);

            json.Should().Be(@"{""ignore_expiration"":true}");
        }
Ejemplo n.º 16
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Only_ExpiresInSeconds_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                ExpiresInSeconds = 7200
            };

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

                    stringWriter.ToString().Should().Be(@"{""expires_in"":7200}");
                }
        }
Ejemplo n.º 17
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Only_Scope_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                Scope = TraktAccessScope.Public
            };

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

                    stringWriter.ToString().Should().Be(@"{""scope"":""public""}");
                }
        }
Ejemplo n.º 18
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Only_RefreshToken_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                RefreshToken = "mockRefreshToken"
            };

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

                    stringWriter.ToString().Should().Be(@"{""refresh_token"":""mockRefreshToken""}");
                }
        }
Ejemplo n.º 19
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Only_TokenType_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                TokenType = TraktAccessTokenType.Bearer
            };

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

                    stringWriter.ToString().Should().Be(@"{""token_type"":""bearer""}");
                }
        }
Ejemplo n.º 20
0
        public async Task Test_AuthorizationObjectJsonWriter_WriteObject_JsonWriter_Only_IgnoreExpiration_Property()
        {
            ITraktAuthorization traktAuthorization = new TraktAuthorization
            {
                IgnoreExpiration = true
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new AuthorizationObjectJsonWriter
                    {
                        CompleteSerialization = true
                    };

                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktAuthorization);

                    stringWriter.ToString().Should().Be(@"{""ignore_expiration"":true}");
                }
        }