Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }