Exemple #1
0
        public void EnsureGenerateTokens_regenerate_tokens_every_call()
        {
            var sessionTokenCounter    = 0;
            var keyManagerTokenCounter = 100;

            _sessionAuthApiMock.Setup(obj => obj.V1Async(default(CancellationToken))).Returns(() =>
            {
                ++sessionTokenCounter;
                return(Task.FromResult(new Token()
                {
                    Name = "sessionToken", Token1 = "s" + sessionTokenCounter.ToString()
                }));
            });
            _keyAuthApiMock.Setup(obj => obj.V1Async(default(CancellationToken))).Returns(() =>
            {
                ++keyManagerTokenCounter;
                return(Task.FromResult(new Token()
                {
                    Name = "keyManagerToken", Token1 = "km" + keyManagerTokenCounter.ToString()
                }));
            });
            var userSessionManager = new UserSessionManager(_sessionAuthApiMock.Object, _keyAuthApiMock.Object, _certificate);

            Assert.Equal("s1", userSessionManager.SessionToken);
            Assert.Equal("km101", userSessionManager.KeyManagerToken);
            Assert.Equal("s1", userSessionManager.SessionToken);
            Assert.Equal("km101", userSessionManager.KeyManagerToken);

            userSessionManager.GenerateTokens();
            Assert.Equal("s2", userSessionManager.SessionToken);
            Assert.Equal("km102", userSessionManager.KeyManagerToken);
            Assert.Equal("km102", userSessionManager.KeyManagerToken);
        }
        public void EnsureGenerateTokens_regenerate_tokens_every_call()
        {
            var sessionTokenCounter    = 0;
            var keyManagerTokenCounter = 100;

            _sessionAuthApiMock.Setup(obj => obj.V1AuthenticatePost()).Returns(() =>
            {
                ++sessionTokenCounter;
                return(new Token("sessionToken", "s" + sessionTokenCounter.ToString()));
            });
            _keyAuthApiMock.Setup(obj => obj.V1AuthenticatePost()).Returns(() =>
            {
                ++keyManagerTokenCounter;
                return(new Token("keyManagerToken", "km" + keyManagerTokenCounter.ToString()));
            });
            var userSessionManager = new UserSessionManager(_sessionAuthApiMock.Object, _keyAuthApiMock.Object, _certificate);

            Assert.Equal("s1", userSessionManager.SessionToken);
            Assert.Equal("km101", userSessionManager.KeyManagerToken);
            Assert.Equal("s1", userSessionManager.SessionToken);
            Assert.Equal("km101", userSessionManager.KeyManagerToken);

            userSessionManager.GenerateTokens();
            Assert.Equal("s2", userSessionManager.SessionToken);
            Assert.Equal("km102", userSessionManager.KeyManagerToken);
            Assert.Equal("km102", userSessionManager.KeyManagerToken);
        }