示例#1
0
    public void APITestRefreshTokenOk()
    {
        var json   = @"
        {
            ""access_token"": ""abc123"",
            ""expires_in"": 12345,
            ""id_token"": ""abcdefg"",
            ""refresh_token"": ""abc321"",
            ""scope"":""profile openid"",
            ""token_type"": ""Bearer""
        }
        ";
        var called = false;

        LineAPI.RefreshAccessToken(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(token => {
                called = true;
                Assert.AreEqual("abc123", token.Value);
                Assert.AreEqual(12345, token.ExpiresIn);
                Assert.AreEqual("abcdefg", token.IdTokenRaw);
                Assert.AreEqual("abc321", token.RefreshToken);
                Assert.AreEqual("profile openid", token.Scope);
                Assert.AreEqual("Bearer", token.TokenType);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
示例#2
0
    public void APITestGetProfileOk()
    {
        var json   = @"
        {
            ""displayName"": ""testuser"",
            ""userId"": ""user_id"",
            ""pictureUrl"": ""https://example.com/abcd"",
            ""statusMessage"": ""Hi""
        }
        ";
        var called = false;

        LineAPI.GetProfile(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(profile => {
                called = true;
                Assert.AreEqual("user_id", profile.UserId);
                Assert.AreEqual("testuser", profile.DisplayName);
                Assert.AreEqual("Hi", profile.StatusMessage);
                Assert.AreEqual("https://example.com/abcd", profile.PictureUrl);
                Assert.AreEqual("https://example.com/abcd/large", profile.PictureUrlLarge);
                Assert.AreEqual("https://example.com/abcd/small", profile.PictureUrlSmall);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
示例#3
0
    public void APITestVerifyAccessTokenOk()
    {
        var json   = @"
        {
            ""client_id"": ""12345678"",
            ""expires_in"": 12345,
            ""scope"": ""profile openid""
        }
        ";
        var called = false;

        LineAPI.VerifyAccessToken(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(value => {
                called = true;
                Assert.AreEqual(value.ChannelId, "12345678");
                Assert.AreEqual(12345, value.ExpiresIn);
                Assert.AreEqual(value.Scope, "profile openid");
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
示例#4
0
    public void APITestRevokeTokenOk()
    {
        var json   = "{}";
        var called = false;

        LineAPI.RevokeAccessToken(result => {
            called = true;
            Assert.True(result.IsSuccess);
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
    }
示例#5
0
    public void APITestGetBotFriendshipStatusOk()
    {
        var json   = @"
        {
            ""friendFlag"": true
        }
        ";
        var called = false;

        LineAPI.GetBotFriendshipStatus(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(value => {
                called = true;
                Assert.True(value.IsFriend);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
示例#6
0
    public void LoginTestOk()
    {
        var json   = @"
        {
            ""accessToken"": {
                ""access_token"": ""abc123"",
                ""expires_in"": 12345,
                ""id_token"": ""abcdefg"",
                ""refresh_token"": ""abc321"",
                ""scope"":""profile openid"",
                ""token_type"": ""Bearer""
            },
            ""scope"": ""profile openid"",
            ""userProfile"": {
                ""displayName"": ""testuser"",
                ""userId"": ""user_id"",
                ""pictureUrl"": ""https://example.com/abcd"",
                ""statusMessage"": ""Hi""
            },
            ""friendshipStatusChanged"": true
        }
        ";
        var called = false;

        LineAPI.Login(new string[] { "profile" }, null, result => {
            result.MatchOk(value => {
                called = true;
                Assert.AreEqual("abc123", value.AccessToken.Value);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }