Ejemplo n.º 1
0
        public async Task MetadataErrorIsNotCached()
        {
            var baseUri  = new Uri("ftp://localhost/");
            var settings = new ODataClientSettings {
                BaseUri = baseUri
            };

            var client = new ODataClient(settings);

            try
            {
                await client.GetMetadataAsync();
            }
            catch (ArgumentException)
            {
                //only HTTP and HTTPS supported
            }
            catch (AggregateException ex)
            {
                ex = ex.Flatten();
                if (ex.InnerExceptions.Count != 1)
                {
                    throw;
                }
                var arg = ex.InnerException as ArgumentException;
                if (arg == null)
                {
                    throw;
                }
                //only HTTP and HTTPS supported
            }

            var wasCached = true;
            var cached    = EdmMetadataCache.GetOrAdd("ftp://localhost/", x =>
            {
                wasCached = false;
                return(null);
            });

            Assert.False(wasCached);
            Assert.Null(cached);
        }
Ejemplo n.º 2
0
        public async Task MetadataIsCached()
        {
            var settings = new ODataClientSettings {
                BaseUri = _serviceUri
            };
            var client = new ODataClient(settings);

            await client.GetMetadataAsync();

            EdmMetadataCache.GetOrAdd(_serviceUri.ToString(), x => throw new Exception("metadata was not cached."));

            settings.BeforeRequest = x => throw new Exception("metadata cache was not used.");
            await client.GetMetadataAsync();

            settings = new ODataClientSettings {
                BaseUri = _serviceUri, BeforeRequest = x => throw new Exception("not reusing settings will defeat metadata cache.")
            };
            client = new ODataClient(settings);
            await client.GetMetadataAsync();
        }