コード例 #1
0
        public static async Task <SingleResult <T> > TryGetSingle <T>(this IAcceptanceTestInfrastructureProvider provider, string url, Predicate <T> condition = null, string instanceName = Settings.DEFAULT_SERVICE_NAME) where T : class
        {
            if (condition == null)
            {
                condition = _ => true;
            }

            var response = await provider.GetInternal <List <T> >(url, instanceName);

            T item = null;

            if (response != null)
            {
                var items = response.Where(i => condition(i)).ToList();

                if (items.Count > 1)
                {
                    throw new InvalidOperationException("More than one matching element found");
                }

                item = items.SingleOrDefault();
            }

            if (item != null)
            {
                return(SingleResult <T> .New(item));
            }

            return(SingleResult <T> .Empty);
        }
コード例 #2
0
        public static async Task <SingleResult <T> > TryGet <T>(this IAcceptanceTestInfrastructureProvider provider, string url, Func <T, Task <bool> > condition, string instanceName = Settings.DEFAULT_SERVICE_NAME) where T : class
        {
            var response = await provider.GetInternal <T>(url, instanceName).ConfigureAwait(false);

            if (response == null || !await condition(response).ConfigureAwait(false))
            {
                return(SingleResult <T> .Empty);
            }

            return(SingleResult <T> .New(response));
        }
コード例 #3
0
        public static async Task <ManyResult <T> > TryGetMany <T>(this IAcceptanceTestInfrastructureProvider provider, string url, Predicate <T> condition = null, string instanceName = Settings.DEFAULT_SERVICE_NAME) where T : class
        {
            if (condition == null)
            {
                condition = _ => true;
            }

            var response = await provider.GetInternal <List <T> >(url, instanceName).ConfigureAwait(false);

            if (response == null || !response.Any(m => condition(m)))
            {
                return(ManyResult <T> .Empty);
            }

            return(ManyResult <T> .New(true, response));
        }
コード例 #4
0
        public static async Task <SingleResult <T> > TryGet <T>(this IAcceptanceTestInfrastructureProvider provider, string url, Predicate <T> condition = null) where T : class
        {
            if (condition == null)
            {
                condition = _ => true;
            }

            var response = await provider.GetInternal <T>(url).ConfigureAwait(false);

            if (response == null || !condition(response))
            {
                return(SingleResult <T> .Empty);
            }

            return(SingleResult <T> .New(response));
        }