public void TestSetTokensFiresEvent()
        {
            var credentials = new MeliCredentials(MeliSite.Panama, 123456, "secret", "oldToken");

            credentials.TokensChanged += (sender, args) => receivedEvents.Add(args);

            var model = new TokenResponse { AccessToken = "access", RefreshToken = "refresh" };

            credentials.SetTokens(model);

            Assert.AreEqual(1, receivedEvents.Count);
            Assert.AreSame(model, receivedEvents[0].Info);

            model.AccessToken = "new";
            model.RefreshToken = "value";

            Assert.AreEqual("oldToken", model.PreviousAccessToken);
            Assert.AreEqual("oldToken", receivedEvents[0].Info.PreviousAccessToken);

            credentials.SetTokens(model);

            Assert.AreEqual(2, receivedEvents.Count);
            Assert.AreSame(model, receivedEvents[0].Info);
            Assert.AreSame(receivedEvents[0].Info, receivedEvents[1].Info);
            Assert.AreEqual("access", model.PreviousAccessToken);
            Assert.AreEqual("access", receivedEvents[1].Info.PreviousAccessToken);
        }
        public void TestSetTokensFiresEvent()
        {
            var credentials = new MeliCredentials(MeliSite.Panama, 123456, "secret", "oldToken");

            credentials.TokensChanged += (sender, args) => receivedEvents.Add(args);

            var model = new TokenResponse {
                AccessToken = "access", RefreshToken = "refresh"
            };

            credentials.SetTokens(model);

            Assert.AreEqual(1, receivedEvents.Count);
            Assert.AreSame(model, receivedEvents[0].Info);

            model.AccessToken  = "new";
            model.RefreshToken = "value";

            Assert.AreEqual("oldToken", model.PreviousAccessToken);
            Assert.AreEqual("oldToken", receivedEvents[0].Info.PreviousAccessToken);

            credentials.SetTokens(model);

            Assert.AreEqual(2, receivedEvents.Count);
            Assert.AreSame(model, receivedEvents[0].Info);
            Assert.AreSame(receivedEvents[0].Info, receivedEvents[1].Info);
            Assert.AreEqual("access", model.PreviousAccessToken);
            Assert.AreEqual("access", receivedEvents[1].Info.PreviousAccessToken);
        }
        public void TestConstructor()
        {
            var credentials = new MeliCredentials(MeliSite.Panama, 123456, "secret", "access token", "refresh token");

            Assert.AreEqual(MeliSite.Panama, credentials.Site);
            Assert.AreEqual(123456, credentials.ClientId);
            Assert.AreEqual("secret", credentials.ClientSecret);
            Assert.AreEqual("access token", credentials.AccessToken);
            Assert.AreEqual("refresh token", credentials.RefreshToken);
        }
        public void TestConstructor()
        {
            var credentials = new MeliCredentials(MeliSite.Panama, 123456, "secret", "access token", "refresh token");

            Assert.AreEqual(MeliSite.Panama, credentials.Site);
            Assert.AreEqual(123456, credentials.ClientId);
            Assert.AreEqual("secret", credentials.ClientSecret);
            Assert.AreEqual("access token", credentials.AccessToken);
            Assert.AreEqual("refresh token", credentials.RefreshToken);
        }
        public void TestSetTokens()
        {
            var credentials = new MeliCredentials(MeliSite.Panama, 123456, "secret", "oldToken", "oldRefreshToken");

            var model = new TokenResponse {AccessToken = "newToken", RefreshToken = "newRefreshToken"};

            credentials.SetTokens(model);

            Assert.AreEqual("newToken", credentials.AccessToken);
            Assert.AreEqual("oldToken", model.PreviousAccessToken);
            Assert.AreEqual("newRefreshToken", credentials.RefreshToken);
        }
        public void TestSetTokens()
        {
            var credentials = new MeliCredentials(MeliSite.Panama, 123456, "secret", "oldToken", "oldRefreshToken");

            var model = new TokenResponse {
                AccessToken = "newToken", RefreshToken = "newRefreshToken"
            };

            credentials.SetTokens(model);

            Assert.AreEqual("newToken", credentials.AccessToken);
            Assert.AreEqual("oldToken", model.PreviousAccessToken);
            Assert.AreEqual("newRefreshToken", credentials.RefreshToken);
        }
        public void Setup()
        {
            providerMock = new Mock <IHttpClientProvider>();
            mockHttp     = new MockHttpMessageHandler();

            var credentials = new MeliCredentials(MeliSite.Argentina, 123456, "secret");

            service = new MeliApiService
            {
                HttpClientProvider = providerMock.Object,
                Credentials        = credentials
            };

            providerMock.Setup(call => call.Create(It.IsAny <bool>()))
            .Returns(new HttpClient(mockHttp));
        }
        public void Setup()
        {
            providerMock = new Mock<IHttpClientProvider>();
            mockHttp = new MockHttpMessageHandler();

            var credentials = new MeliCredentials(MeliSite.Argentina, 123456, "secret");

            service = new MeliApiService
                      {
                          HttpClientProvider = providerMock.Object,
                          Credentials = credentials
                      };

            providerMock.Setup(call => call.Create(It.IsAny<bool>()))
                        .Returns(new HttpClient(mockHttp));
        }