Esempio n. 1
0
        public void TestAnnounceOrder()
        {
            var order            = MerchantOrderRequestBuilder.MakeCompleteRequest();
            var orderAsJson      = JsonHelper.Serialize(order);
            var expectedResponse = MerchantOrderResponseBuilder.NewInstanceAsJson();

            PrepareTokenProviderWithAccessToken(_accessToken);
            _restTemplate.Setup(s => s.Post("order/server/api/order", orderAsJson)).Returns(expectedResponse);

            var actualResponse = _connector.AnnounceMerchantOrder(order);

            _restTemplate.Verify(v => v.SetToken(_accessToken.Token));
            _restTemplate.Verify(v => v.Post("order/server/api/order", orderAsJson));

            Assert.AreEqual(expectedResponse, actualResponse);
        }
Esempio n. 2
0
        public void TestNoAccessTokenProvided()
        {
            var order = MerchantOrderRequestBuilder.MakeCompleteRequest();

            PrepareTokenProviderWithoutAccessToken();
            _restTemplate.Setup(s => s.Get("gatekeeper/refresh", null)).Returns(JsonHelper.Serialize(_secondAccessToken));

            _connector.AnnounceMerchantOrder(order);

            //Verify that a new access token is retrieved
            _restTemplate.Verify(v => v.Get("gatekeeper/refresh", null));

            //Verify that the correct token is used to call the API
            _restTemplate.Verify(v => v.SetToken(_secondAccessToken.Token));

            //Verify that the new access token is stored in the token provider
            _tokenProvider.Verify(v => v.SetValue(TokenProvider.AccessToken, _secondAccessToken.Token));
            _tokenProvider.Verify(v => v.SetValue(TokenProvider.AccessTokenValidUntil, _secondAccessToken.ValidUntil.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz")));
            _tokenProvider.Verify(v => v.SetValue(TokenProvider.AccessTokenDuration, _secondAccessToken.DurationInMilliseconds.ToString()));
        }