public void IsValid_Test()
        {
            #region === ARRANGE ===
            string UUID = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            SessionToken token1 = new SessionToken()
            {
                dateTime = DateTime.Now,
                UUID     = UUID,
                userId   = 55,
                userName = "******"
            };

            SessionToken token2 = new SessionToken()
            {
                dateTime = new DateTime(2000, 1, 1),
                UUID     = UUID,
                userId   = 55,
                userName = "******"
            };

            SessionToken token3 = new SessionToken()
            {
                dateTime     = new DateTime(2000, 1, 1),
                daysToExpire = 0,
                UUID         = UUID,
                userId       = 55,
                userName     = "******"
            };

            #endregion

            #region === ACT ===

            bool result1 = token1.IsValid(UUID);
            bool result2 = token1.IsValid("Some Other UUID");
            bool result3 = token2.IsValid(UUID);
            bool result4 = token3.IsValid(UUID);

            #endregion

            #region === ASSERT ===

            Assert.AreEqual <bool>(true, result1);
            Assert.AreEqual <bool>(false, result2);
            Assert.AreEqual <bool>(false, result3);
            Assert.AreEqual <bool>(true, result4);

            #endregion
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="AdministrationApi" /> class.
        /// </summary>
        /// <param name="currentToken">
        ///     The current token.
        /// </param>
        public AdministrationApi(SessionToken currentToken)
        {
            if (currentToken.IsValid() && currentToken.TokenType == TokenType.Config)
            {
                this.CurrentToken = currentToken;

                // Once all of the BaseApi settings have been created, pass the AdministrationApi into the constructor of all of the sub API managers
                this.REST = new RestManager(this);
                this.Licenses = new LicenseManager(this);
                this.Customers = new CustomerManager(this);
            }
        }
示例#3
0
        public UserAppModel DecryptToken(string UUID, string tokenString)
        {
            SessionToken sessionToken = tokenGenerator.Decrypt(tokenString);

            if (sessionToken.IsValid(UUID))
            {
                AbstractMapper <SessionToken, UserAppModel> mapper = mapperFactory.Create <SessionToken, UserAppModel>();
                return(mapper.Map(sessionToken));
            }
            ;

            return(null);
        }