예제 #1
0
        /// <inheritdoc />
        public async Task <IActionResult> GetSingleAsync(string filter)
        {
            try
            {
                var filtered = filter != null;
                IGetSingleBasket <T> basket;
                if (filtered)
                {
                    var parsedFilter = new FilterParser <T>(filter).Parse();
                    basket = new GetSingleBasket <T>(new GetSingleRequest <T>(parsedFilter));
                }
                else
                {
                    basket = new GetSingleBasket <T>();
                }

                await _shaft.SendAsync(basket);

                return(new OkObjectResult(basket.AscentPayload));
            }
            catch (Exception ex)
            {
                return(GetErrorResult(ex));
            }
        }
예제 #2
0
        private void PrintOrganismCounts()
        {
            var frogCountBasket    = new GetSingleBasket <FrogCount>();
            var tadpoleCountBasket = new GetSingleBasket <TadpoleCount>();
            var tasks = new Task[]
            {
                _frogCountMine.SendAsync(frogCountBasket),
                _tadpoleCountMine.SendAsync(tadpoleCountBasket)
            };

            Task.WaitAll(tasks);

            System.Console.WriteLine(
                $"There are {frogCountBasket.AscentPayload.Count} frogs and {tadpoleCountBasket.AscentPayload.Count} tadpoles");
        }
예제 #3
0
        public void Construct()
        {
            var filter  = new Filter <Frog>(new[] { new FilterTerm(nameof(Frog.Name), FilterOperators.StartsWith, "Fr") });
            var request = new GetSingleRequest <Frog>(filter);

            Assert.Same(filter, request.Filter);

            var basket = new GetSingleBasket <Frog>(request);

            Assert.Equal(typeof(Frog), basket.DataType);
            Assert.Same(request, basket.DescentPayload);

            basket = new GetSingleBasket <Frog>(new GetSingleRequest <Frog>());
            Assert.Equal(typeof(Frog), basket.DataType);
            Assert.Null(basket.DescentPayload.Filter);
        }
예제 #4
0
        public async Task GetSingle()
        {
            var mine   = new FrogMine("allowed");
            var basket = new GetSingleBasket <Frog>();
            await mine.SendAsync(basket);

            Assert.Equal(465, basket.AscentPayload.Id);

            mine   = new FrogMine("GetSingle");
            basket = new GetSingleBasket <Frog>();
            await mine.SendAsync(basket);

            Assert.Equal(465, basket.AscentPayload.Id);

            mine   = new FrogMine("not-allowed");
            basket = new GetSingleBasket <Frog>();
            await Assert.ThrowsAnyAsync <ShaftException>(() => mine.SendAsync(basket));
        }