public void LWAAuthorizationCredentialsWithScopesBuildsSellerlessTokenRequestMeta() { LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials() { ClientId = TestClientId, ClientSecret = TestClientSecret, Endpoint = TestUri, Scopes = new List <string>() { ScopeConstants.ScopeMigrationAPI, ScopeConstants.ScopeNotificationsAPI } }; LWAAccessTokenRequestMeta expected = new LWAAccessTokenRequestMeta() { ClientId = TestClientId, ClientSecret = TestClientSecret, GrantType = LWAAccessTokenRequestMetaBuilder.SellerlessAPIGrantType, Scope = string.Format("{0} {1}", ScopeConstants.ScopeMigrationAPI, ScopeConstants.ScopeNotificationsAPI), RefreshToken = null }; LWAAccessTokenRequestMeta actual = lwaAccessTokenRequestMetaBuilderUnderTest.Build(lwaAuthorizationCredentials); Assert.Equal(expected, actual); }
public void LWAAuthorizationCredentialsWithoutScopesBuildsSellerTokenRequestMeta() { LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials() { ClientId = TestClientId, ClientSecret = TestClientSecret, Endpoint = TestUri, RefreshToken = TestRefreshToken }; LWAAccessTokenRequestMeta expected = new LWAAccessTokenRequestMeta() { ClientId = TestClientId, ClientSecret = TestClientSecret, GrantType = LWAAccessTokenRequestMetaBuilder.SellerAPIGrantType, RefreshToken = TestRefreshToken, Scope = null }; LWAAccessTokenRequestMeta actual = lwaAccessTokenRequestMetaBuilderUnderTest.Build(lwaAuthorizationCredentials); Assert.Equal(expected, actual); }
public void MakeRequestFromMeta() { IRestRequest request = new RestRequest(); LWAAccessTokenRequestMeta expectedLWAAccessTokenRequestMeta = new LWAAccessTokenRequestMeta() { ClientSecret = "expectedSecret", ClientId = "expectedClientId", RefreshToken = "expectedRefreshToken", GrantType = "expectedGrantType" }; mockRestClient.Setup(client => client.Execute(It.IsAny <IRestRequest>())) .Callback((IRestRequest req) => { request = req; }) .Returns(Response); mockLWAAccessTokenRequestMetaBuilder.Setup(builder => builder.Build(LWAAuthorizationCredentials)) .Returns(expectedLWAAccessTokenRequestMeta); LWAClient lwaClientUnderTest = new LWAClient(LWAAuthorizationCredentials); lwaClientUnderTest.RestClient = mockRestClient.Object; lwaClientUnderTest.LWAAccessTokenRequestMetaBuilder = mockLWAAccessTokenRequestMetaBuilder.Object; lwaClientUnderTest.GetAccessToken(); Parameter requestBody = request.Parameters .FirstOrDefault(parameter => parameter.Type.Equals(ParameterType.RequestBody)); JObject jsonRequestBody = JObject.Parse(requestBody.Value.ToString()); Assert.Equal(Method.POST, request.Method); Assert.Equal(TestEndpoint.AbsolutePath, request.Resource); Assert.Equal(expectedLWAAccessTokenRequestMeta.RefreshToken, jsonRequestBody.GetValue("refresh_token")); Assert.Equal(expectedLWAAccessTokenRequestMeta.GrantType, jsonRequestBody.GetValue("grant_type")); Assert.Equal(expectedLWAAccessTokenRequestMeta.ClientId, jsonRequestBody.GetValue("client_id")); Assert.Equal(expectedLWAAccessTokenRequestMeta.ClientSecret, jsonRequestBody.GetValue("client_secret")); }