Exemplo n.º 1
0
    protected virtual async Task <List <SelectItem <object> > > GetLookupItemsAsync(string filter)
    {
        var selectItems = new List <SelectItem <object> >();

        var url = PropertyInfo.Lookup.Url;

        if (!filter.IsNullOrEmpty())
        {
            url += $"?{PropertyInfo.Lookup.FilterParamName}={filter.Trim()}";
        }

        var response = await LookupApiService.SendAsync(url);

        var document       = JsonDocument.Parse(response);
        var itemsArrayProp = document.RootElement.GetProperty(PropertyInfo.Lookup.ResultListPropertyName);

        foreach (var item in itemsArrayProp.EnumerateArray())
        {
            selectItems.Add(new SelectItem <object>
            {
                Text  = item.GetProperty(PropertyInfo.Lookup.DisplayPropertyName).GetString(),
                Value = JsonSerializer.Deserialize(
                    item.GetProperty(PropertyInfo.Lookup.ValuePropertyName).GetRawText(), PropertyInfo.Type)
            });
        }

        return(selectItems);
    }
        public async Task InsertQueryDeleteLASets()
        {
            var client        = IocConfig.CreateHttpClient();
            var clientWrapper = new HttpClientWrapper(client, IocConfig.CreateJsonMediaTypeFormatter());
            var l             = new LookupApiService(clientWrapper, new SecurityApiService(clientWrapper));
            var las           = (await l.LocalAuthorityGetAllAsync()).ToArray();

            var subject = new LocalAuthoritySetRepository();

            for (int i = 0; i < 1000; i++)
            {
                var laIds = Enumerable.Range(0, RandomNumber.Next(0, 15)).Select(x => las.ElementAt(RandomNumber.Next(las.Length)).Id).ToArray();
                await subject.CreateAsync(new LocalAuthoritySet
                {
                    Ids   = laIds,
                    Title = Lorem.Sentence(2)
                });
            }

            //var result = await subject.GetAllAsync(100);
            //Assert.AreEqual(100, result.Items.Count());
            //foreach (var item in result.Items)
            //{
            //    Assert.IsNotNull(item.Ids);
            //    Assert.That(item.Ids.Count, Is.EqualTo(3));
            //}


            //result = await subject.GetAllAsync(1000);
            //foreach (var item in result.Items)
            //{
            //    await subject.DeleteAsync(item.RowKey);
            //}
        }
        public async Task InsertQueryDeleteLASets()
        {
            var client        = IocConfig.CreateHttpClient();
            var clientWrapper = new HttpClientWrapper(client, IocConfig.CreateJsonMediaTypeFormatter());
            var l             = new LookupApiService(clientWrapper, new SecurityApiService(clientWrapper));
            var las           = (await l.LocalAuthorityGetAllAsync()).ToArray();

            var subject = new LocalAuthoritySetRepository();

            for (var i = 0; i < 1000; i++)
            {
                var laIds = Enumerable.Range(0, RandomNumber.Next(0, 15)).Select(x => las.ElementAt(RandomNumber.Next(las.Length)).Id).ToArray();
                await subject.CreateAsync(new LocalAuthoritySet
                {
                    Ids   = laIds,
                    Title = Lorem.Sentence(2)
                });
            }
        }