Exemplo n.º 1
0
        public void BTest()
        {
            JsonDB DB = new JsonDB();

            DB.InitJsonDB();

            //Set
            var productId = Guid.Empty;
            var product   = new DGDADemo.Product.Models.Product()
            {
                Id          = productId,
                Name        = "Product 1",
                Price       = 10,
                Description = "Description 1",
                InStock     = true
            };

            DB.Set(productId, product);

            var productGet = DB.Get <DGDADemo.Product.Models.Product>(Guid.Empty).ToList();

            Assert.AreEqual(product.Name, productGet[0].Name);
            Assert.AreEqual(product.InStock, productGet[0].InStock);
            Assert.AreEqual(product.Description, productGet[0].Description);
            Assert.AreEqual(product.Price, productGet[0].Price);
        }
            UniRx.IObservable <Net.HTTPResult> LoginAsAuto(AccountLoginParam argc)
            {
                return(Observable.Range(0, 1)
                       .SelectMany(_ => {
                    JsonDB db = new JsonDB("account");
                    var obj = db.Get(argc.extension);
                    if (obj.Type == JTokenType.Null)
                    {
                        throw new Sas.Exception(Sas.ERRNO.LOCAL_HOST_NOT_FIND_EXIST.ToErrCode());
                    }

                    AutoLoginFile body = obj.ToObject <AutoLoginFile> ();
                    ;
                    var hashed = body.signature;
                    body.signature = null;

                    var json = Newtonsoft.Json.JsonConvert.SerializeObject(body);
                    var pbkdf = new Rfc2898DeriveBytes(json, SecureHelper.APP_SALT.GetByte(Convert.FromBase64String), 3483);
                    var signature = Convert.ToBase64String(pbkdf.GetBytes(256));
                    if (!string.Equals(signature, hashed))
                    {
                        throw new Sas.Exception(Sas.ERRNO.LOCAL_HOST_SIGNATURE_ERR.ToErrCode());
                    }

                    var param = new AccountLoginReqParam();
                    param.sns = SNS.AUTO.GetHashCode();
                    param.token = Convert.FromBase64String(body.password);
                    var inst = context.requester.Post(context.server + "/Account/LoginAuto");
                    inst.mReq.Headers.Add("sas-accesstoken", body.token);
                    return inst.Invoke(JObject.FromObject(param));
                }));
            }
Exemplo n.º 3
0
        /// <summary>
        ///A test for Get
        ///</summary>
        public void GetTestHelper <T>()
        {
            JsonDB          target   = new JsonDB(); // TODO: Initialize to an appropriate value
            Guid            key      = new Guid();   // TODO: Initialize to an appropriate value
            IEnumerable <T> expected = null;         // TODO: Initialize to an appropriate value
            IEnumerable <T> actual;

            actual = target.Get <T>(key);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }