Ejemplo n.º 1
0
        public async Task CheckCompleteOrderTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.CheckCompleteOrderAsync(null, default));

            var result = await ApiInstance.CheckCompleteOrderAsync(DateTime.Now);

            Assert.NotNull(result);
        }
Ejemplo n.º 2
0
        public async Task GetPageNumExtTest()
        {
            var res = await ApiInstance.GetPageNumAsync(contractSkuPoolExt : true);

            Assert.True(res.Success, res.ResultMessage);
            var pageNum = res.Result;

            Assert.NotNull(pageNum);
            Assert.NotEmpty(pageNum);
            Assert.Contains(pageNum, v => v.ContractSkuPoolExt != null);
        }
Ejemplo n.º 3
0
        public async Task CheckAreaTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.CheckAreaAsync(null, 0, 0, 0, 0));

            var jdAddr = TestHelper.JDArress;
            var res    = await ApiInstance.CheckAreaAsync(jdAddr.ProvinceId, jdAddr.CityId, jdAddr.CountyId, jdAddr.TownId.Value);

            Assert.True(res.Success, res.ResultMessage);
            Assert.NotNull(res.Result);
            Assert.True(res.Result.Success);
        }
Ejemplo n.º 4
0
        private async Task UploadStatus()
        {
            if (firstHeartBeat)
            {
                var token = await _apiInstance.Authenticate(new AuthenticationId
                {
                    Id = _appConfig.Id
                });

                _apiInstance.AuthorizationToken = $"Bearer {token.AccessToken}";
            }

            var instance = new ApiInstance
            {
                Id      = _appConfig.Id,
                Uptime  = (int)(DateTime.UtcNow - (_manager as ApplicationManager).StartTime).TotalSeconds,
                Version = Program.Version,
                Servers = _manager.GetServers().Select(s =>
                                                       new ApiServer()
                {
                    ClientNum    = s.ClientNum,
                    Game         = s.GameName.ToString(),
                    Version      = s.Version,
                    Gametype     = s.Gametype,
                    Hostname     = s.Hostname,
                    Map          = s.CurrentMap.Name,
                    MaxClientNum = s.MaxClients,
                    Id           = s.EndPoint,
                    Port         = (short)s.Port,
                    IPAddress    = s.IP
                }).ToList(),
                WebfrontUrl = _appConfig.WebfrontUrl
            };

            Response <ResultMessage> response = null;

            if (firstHeartBeat)
            {
                response = await _apiInstance.AddInstance(instance);
            }

            else
            {
                response = await _apiInstance.UpdateInstance(instance.Id, instance);

                firstHeartBeat = false;
            }

            if (response.ResponseMessage.StatusCode != System.Net.HttpStatusCode.OK)
            {
                _logger.LogWarning("Non success response code from master is {statusCode}, message is {message}", response.ResponseMessage.StatusCode, response.StringContent);
            }
        }
Ejemplo n.º 5
0
        public async Task ProductCheckTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.ProductCheckAsync(null, default));

            var res = await ApiInstance.ProductCheckAsync(TestHelper.SkuNormal1);

            Assert.True(res.Success, res.ResultMessage);
            var result = res.Result;

            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
Ejemplo n.º 6
0
        public async Task GetDetailVideoTest()
        {
            var res = await ApiInstance.GetDetailAsync(TestHelper.SkuVideo);

            Assert.True(res.Success, res.ResultMessage);
            var detail = res.Result;

            Assert.NotNull(detail);
            Assert.True(detail.IsVideo);
            var video = detail.AsVideo();

            Assert.Equal(TestHelper.SkuVideoSinger, video.Singer);
        }
Ejemplo n.º 7
0
        public async Task GetSellPriceTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetSellPriceAsync(null, null));

            var sku = $"{TestHelper.SkuNormal1},{TestHelper.SkuNormal2}";
            var res = await ApiInstance.GetSellPriceAsync(sku);

            Assert.True(res.Success, res.ResultMessage);
            var result = res.Result;

            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
Ejemplo n.º 8
0
        public async Task GetTownTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetTownAsync(null, 0));

            var res = await ApiInstance.GetTownAsync(TestHelper.JDArress.CountyId);

            Assert.True(res.Success, res.ResultMessage);
            var town = res.Result;

            Assert.NotNull(town);
            Assert.NotEmpty(town);
            Assert.Contains(TestHelper.JDArress.Town, town.Keys);
        }
Ejemplo n.º 9
0
        public async Task GetCountyTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetCountyAsync(null, 0));

            var res = await ApiInstance.GetCountyAsync(TestHelper.JDArress.CityId);

            Assert.True(res.Success, res.ResultMessage);
            var country = res.Result;

            Assert.NotNull(country);
            Assert.NotEmpty(country);
            Assert.Contains(TestHelper.JDArress.County, country.Keys);
        }
Ejemplo n.º 10
0
        public async Task GetDetailBookTest()
        {
            var res = await ApiInstance.GetDetailAsync(TestHelper.SkuBook);

            Assert.True(res.Success, res.ResultMessage);
            var detail = res.Result;

            Assert.NotNull(detail);
            Assert.True(detail.IsBook);
            var book = detail.AsBook();

            Assert.Equal(TestHelper.SkuBookAuthor, book.Author);
            Assert.Equal(TestHelper.SkuBookISBN, book.ISBN);
        }
Ejemplo n.º 11
0
        public async Task GetSkuByPageTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetSkuByPageAsync(null, default));

            var pageNum = TestHelper.ProductPageNum.Select(v => v.PageNum).First();
            var res     = await ApiInstance.GetSkuByPageAsync(pageNum, 1);

            Assert.True(res.Success, res.ResultMessage);
            var pnSku = res.Result;

            Assert.NotNull(pnSku);
            Assert.True(pnSku.PageCount > 0);
            Assert.NotEmpty(pnSku.SkuIds);
        }
Ejemplo n.º 12
0
        public async Task GetPageNumTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetPageNumAsync(null));

            var res = await ApiInstance.GetPageNumAsync();

            Assert.True(res.Success, res.ResultMessage);
            var pageNum = res.Result;

            Assert.NotNull(pageNum);
            Assert.NotEmpty(pageNum);
            Assert.DoesNotContain(pageNum, v => v.ContractSkuPoolExt != null);
            TestHelper.ProductPageNum = pageNum;
        }
Ejemplo n.º 13
0
        public async Task SkuStateTestAsync()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.SkuStateAsync(null, default));

            var sku = TestHelper.SkuNormal1;
            var res = await ApiInstance.SkuStateAsync(sku);

            Assert.True(res.Success, res.ResultMessage);
            var skuState = res.Result;

            Assert.NotNull(skuState);
            Assert.NotEmpty(skuState);
            Assert.Equal(sku, skuState[0].SKU.ToString());
        }
Ejemplo n.º 14
0
        public async Task GetDetailTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetDetailAsync(null, default));

            var res = await ApiInstance.GetDetailAsync(TestHelper.SkuNormal1, "isSelf,isJDLogistics");

            Assert.True(res.Success, res.ResultMessage);
            var detail = res.Result;

            Assert.NotNull(detail);
            Assert.Equal(TestHelper.SkuNormal1BrandName, detail.BrandName);
            var keys = detail.ExtData.Keys;

            Assert.Contains("isSelf", keys);
            Assert.Contains("isJDLogistics", keys);
        }
Ejemplo n.º 15
0
        public async Task SkuImageTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.SkuImageAsync(null, default));

            var sku = TestHelper.SkuNormal1;
            var res = await ApiInstance.SkuImageAsync(sku);

            Assert.True(res.Success, res.ResultMessage);
            var skuImage = res.Result;

            Assert.NotNull(skuImage);
            Assert.Contains(sku, skuImage.Keys);
            var images = skuImage.GetValueOrDefault(sku);

            Assert.NotEmpty(images);
            Assert.Equal(1, images.Count(v => v.IsPrimary));
        }
Ejemplo n.º 16
0
        public async Task GetUnionBalanceTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetUnionBalanceAsync(null, null));

            var pin = TestHelper.VopClient.UserName;
            var res = await ApiInstance.GetUnionBalanceAsync(pin);

            Assert.True(res.Success, res.ResultMessage);
            var result = res.Result;

            Assert.NotNull(result);
            Assert.NotNull(result.Balance);
            Assert.Equal(result.Balance.Pin, pin);
            //测试帐号无金采权限时不返回geious内容
            //Assert.NotNull(result.Geious);
            //Assert.Equal(result.Geious.PIN, pin);
        }
Ejemplo n.º 17
0
        public AuthenticatedTestFixture()
        {
            ApiInstance =
                TestHelpers.GetDefaultInstaApiInstance(UserSessionData.ForUsername(_username).WithPassword(_password));
            const string stateFile = "state.bin";

            try
            {
                if (File.Exists(stateFile))
                {
                    Stream fs = File.OpenRead(stateFile);
                    fs.Seek(0, SeekOrigin.Begin);
                    ApiInstance.LoadStateDataFromStream(fs);
                    if (ApiInstance.IsUserAuthenticated)
                    {
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            var loginTask = Task.Run(ApiInstance.LoginAsync);

            if (!loginTask.Wait(TimeSpan.FromSeconds(30)))
            {
                throw new Exception($"Unable to login, user: {_username}, password: {_password}.");
            }

            if (!loginTask.Result.Succeeded)
            {
                return;
            }
            var state = ApiInstance.GetStateDataAsStream();

            using (var fileStream = File.Create(stateFile))
            {
                state.Seek(0, SeekOrigin.Begin);
                state.CopyTo(fileStream);
            }
        }
Ejemplo n.º 18
0
        public async Task GetBalanceDetailTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetBalanceDetailAsync(null));

            //测试账号采用对公转账模式,没有余额相关内容
            var res = await ApiInstance.GetBalanceDetailAsync();

            Assert.NotNull(res);
            var result = res.Result;

            Assert.NotNull(result);

            //使用测试JSON验证反序列化结果
            var demoJson = "{\"success\":true,\"resultMessage\":\"操作成功\",\"resultCode\":\"0000\",\"result\":{\"total\":281,\"pageSize\":20,\"pageNo\":1,\"pageCount\":15,\"data\":[{\"id\":2427064792,\"accountType\":1,\"amount\":-1,\"pin\":\"测试y\",\"orderId\":\"84567164608\",\"tradeType\":1209,\"tradeTypeName\":\"实物/礼品卡余额支付\",\"createdDate\":\"2019-01-04 12:44:58\",\"notePub\":\"订单:84567164608,消费余额:1\",\"tradeNo\":3429237517},{\"id\":2417527803,\"accountType\":1,\"amount\":1,\"pin\":\"测试y\",\"orderId\":\"84079230412\",\"tradeType\":758,\"tradeTypeName\":\"余额支付\",\"createdDate\":\"2018-12-27 14:07:06\",\"notePub\":\"订单84079230412退款为京东余额\",\"tradeNo\":3420482480}]}}";
            var demo     = JsonSerializer.Deserialize <RspResult <BalanceDetail> >(demoJson, JdVopApi.JsonSerializerOptions);

            result = demo.Result;
            Assert.NotNull(result);
            Assert.NotEmpty(result.Data);
        }
Ejemplo n.º 19
0
        public async Task GetJDAddressFromAddressTest()
        {
            await Assert.ThrowsAsync <ArgumentException>(() => JdVopApi.GetJDAddressFromAddressAsync(null, default));

            var jdAddr = TestHelper.JDArress;
            var res    = await ApiInstance.GetJDAddressFromAddressAsync(TestHelper.JDAddressTest);

            Assert.True(res.Success, res.ResultMessage);
            var jdAddrRes = res.Result;

            Assert.NotNull(jdAddrRes);
            Assert.Equal("4744", jdAddrRes.NationId);
            Assert.Equal("中国", jdAddrRes.Nation);
            Assert.Equal(jdAddr.ProvinceId, jdAddrRes.ProvinceId);
            Assert.Equal(jdAddr.Province, jdAddrRes.Province);
            Assert.Equal(jdAddr.CityId, jdAddrRes.CityId);
            Assert.Equal(jdAddr.City, jdAddrRes.City);
            Assert.Equal(jdAddr.CountyId, jdAddrRes.CountyId);
            Assert.Equal(jdAddr.County, jdAddrRes.County);
            Assert.Equal(jdAddr.TownId, jdAddrRes.TownId);
            Assert.Equal(jdAddr.Town, jdAddrRes.Town);
        }
Ejemplo n.º 20
0
 public async Task <HttpResponse <Product[]> > GetByCategoryId(int categoryId)
 {
     return(Ok(await ApiInstance.GetProducts(categoryId)));
 }
Ejemplo n.º 21
0
 public async Task <HttpResponse <Variation[]> > GetVariations(int productId)
 {
     return(Ok(await ApiInstance.GetProductVariations(productId)));
 }
Ejemplo n.º 22
0
 public async Task <HttpResponse <Product[]> > Search(string criteria)
 {
     return(Ok(await ApiInstance.SearchProducts(criteria)));
 }
Ejemplo n.º 23
0
 public override async Task <HttpResponse <ProductTag[]> > GetAsync(string endpointName = null, HttpRequest request = null)
 => Ok(await ApiInstance.GetTags());