public void GetTokenTest()
        {
            var v = "";

            var models = new GetTokenModel.Input();

            models.OpMid     = "aaaa1bbbb2cccc3dddd4eeee5ffff6ee";
            models.CardNo    = "7413159981000227";
            models.CallTime  = DateTime.Now.ToString("yyyyMMddhhmmss");
            models.MachineID = "Machine0001";
            models.Mask      = models.GetInMask();

            v = JsonConvert.SerializeObject(models);

            var controller = new SecurityController();

            var result = controller.GetToken(AesUtility.Encrypt(v));

            result = result.AesDecrypt();

            var resultObj = result.FromJson <ApiResult>();

            if (resultObj.ErrorCode == "000")
            {
                Assert.IsTrue(true, "errorCode為000");
            }

            Assert.IsFalse(true, resultObj.ErrorMessage);
        }
Esempio n. 2
0
        public void IsValidTest()
        {
            GetTokenModel.Input model1 = new GetTokenModel.Input();
            var result1  = model1.IsValid <GetTokenModel.Ouput>();
            var expected = EnumItem.Get(Ref.ErrorCode._002).FinalValue;
            var actual   = result1.ErrorCode;

            Assert.AreEqual(expected, actual);

            GetTokenModel.Input model2 = new GetTokenModel.Input();

            model2.CallTime  = DateTime.Now.ToString("yyyyMMddhhmmss");
            model2.MachineID = "machineA";
            model2.Mask      = model1.GetInMask();
            model2.CallTime  = DateTime.Now.ToString("yyyyMMddhhmmss");
            var result2 = model2.IsValid <GetTokenModel.Ouput>();
            var exp     = EnumItem.Get(Ref.ErrorCode._001).FinalValue;
            var act     = result2.ErrorCode;

            Assert.AreEqual(exp, act);
        }
        /// <summary>
        /// 儲存token進資料表
        /// </summary>
        /// <param name="cardNo"></param>
        /// <param name="opMid"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static ApiResult <string> TokenSave(GetTokenModel.Input model, string token)
        {
            var entity      = new Entities();
            var tokenRecord = new Token_Record();

            tokenRecord.Token_Machine_ID = model.MachineID;
            // tokenRecord.Token_Function_ID;
            tokenRecord.Token = token;

            tokenRecord.Token_Create_User = SystemUser;
            tokenRecord.Token_Update_User = SystemUser;
            tokenRecord.Token_Create_Date = DateTime.Now;
            tokenRecord.Token_Update_Date = DateTime.Now;
            tokenRecord.Token_StartDate   = DateTime.Now;
            tokenRecord.Token_ExpireDate  = GetTokenExpireDate(tokenRecord.Token_StartDate, AesConfig.Duration);

            using (var db = new Entities())
            {
                db.Token_Record.Add(tokenRecord);
                db.Entry(tokenRecord).State = EntityState.Added;
                var result = db.SaveChanges();
            }
            return(new ApiResult <string>());
        }