public void Test_AuthorizationObjectJsonWriter_WriteObject_Object_Exceptions() { var traktJsonWriter = new AuthorizationObjectJsonWriter(); Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(ITraktAuthorization)); action.Should().Throw <ArgumentNullException>(); }
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>(); }
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}"); }
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)); }
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("{}"); } }
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""}"); } }
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}"); }
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}"); } }
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""}"); } }
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""}"); } }
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""}"); } }
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}"); } }