Ejemplo n.º 1
0
        public void CreateDifferentTokenEachTime()
        {
            var tokenRepository = new Mock <IRepository <Token> >();
            var userRepository  = new LocalRepository <InsideUser>();
            var provider        = new AccessTokenProvider(tokenRepository.Object, userRepository);
            var userId          = "NewGuidString";

            userRepository.Add(new InsideUser()
            {
                Id = userId
            });
            var result = provider.GetToken(userId);

            tokenRepository.Verify(tr => tr.Add(It.IsAny <Token>()), Times.Once);

            Assert.AreEqual(DateTime.Today.AddDays(30).Date, result.ExpirationDate.Date);
            Assert.AreEqual("NewGuidString", result.UserId);

            var result2 = provider.GetToken(userId);

            tokenRepository.Verify(tr => tr.Add(It.IsAny <Token>()), Times.Exactly(2));

            Assert.AreEqual(DateTime.Today.AddDays(30).Date, result2.ExpirationDate.Date);
            Assert.AreEqual("NewGuidString", result2.UserId);

            Assert.AreNotEqual(result.AccessToken, result2.AccessToken);
        }