Exemplo n.º 1
0
        public MetadataWorkspace GetMetadataWorkspace(
            DbConnectionOptions effectiveConnectionOptions)
        {
            MetadataArtifactLoader artifactLoader = this.GetArtifactLoader(effectiveConnectionOptions);

            return(this.GetMetadataWorkspace(MetadataCache.CreateMetadataCacheKey((IList <string>)artifactLoader.GetPaths(), effectiveConnectionOptions["provider"]), artifactLoader));
        }
Exemplo n.º 2
0
        private static string CreateMetadataCacheKey(IList <string> paths, string providerName)
        {
            int    resultCount = 0;
            string result;

            MetadataCache.CreateMetadataCacheKeyWithCount(paths, providerName, false, ref resultCount, out result);
            MetadataCache.CreateMetadataCacheKeyWithCount(paths, providerName, true, ref resultCount, out result);
            return(result);
        }
Exemplo n.º 3
0
 public MetadataWorkspace GetMetadataWorkspace(
     string cacheKey,
     MetadataArtifactLoader artifactLoader)
 {
     return(this._cachedWorkspaces.GetOrAdd(cacheKey, (Func <string, MetadataWorkspace>)(k =>
     {
         EdmItemCollection edmItemCollection = MetadataCache.LoadEdmItemCollection(artifactLoader);
         Lazy <StorageMappingItemCollection> mappingLoader = new Lazy <StorageMappingItemCollection>((Func <StorageMappingItemCollection>)(() => MetadataCache.LoadStoreCollection(edmItemCollection, artifactLoader)));
         return new MetadataWorkspace((Func <EdmItemCollection>)(() => edmItemCollection), (Func <StoreItemCollection>)(() => mappingLoader.Value.StoreItemCollection), (Func <StorageMappingItemCollection>)(() => mappingLoader.Value));
     })));
 }
Exemplo n.º 4
0
        public MetadataArtifactLoader GetArtifactLoader(
            DbConnectionOptions effectiveConnectionOptions)
        {
            string connectionOption = effectiveConnectionOptions["metadata"];

            if (string.IsNullOrEmpty(connectionOption))
            {
                return(MetadataArtifactLoader.Create(new List <MetadataArtifactLoader>()));
            }
            List <MetadataArtifactLoader> metadataArtifactLoaderList = this._artifactLoaderCache.Evaluate(connectionOption);

            return(MetadataArtifactLoader.Create(MetadataCache.ShouldRecalculateMetadataArtifactLoader((IEnumerable <MetadataArtifactLoader>)metadataArtifactLoaderList) ? MetadataCache.SplitPaths(connectionOption) : metadataArtifactLoaderList));
        }
Exemplo n.º 5
0
            public void Clear_clears_all_cached_workspaces()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");

                var cache = new MetadataCache();

                var workspace = cache.GetMetadataWorkspace(options.Object);

                cache.Clear();

                Assert.NotSame(workspace, cache.GetMetadataWorkspace(options.Object));
            }
Exemplo n.º 6
0
            public void GetMetadataWorkspace_returns_cached_workspace_based_on_cache_key()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);

                var loader1 = new MetadataCache().GetArtifactLoader(options.Object);
                var loader2 = new MetadataCache().GetArtifactLoader(options.Object);

                var cache = new MetadataCache();

                Assert.Same(
                    cache.GetMetadataWorkspace("Key Lime", loader1),
                    cache.GetMetadataWorkspace("Key Lime", loader2));
            }
            public void GetArtifactLoader_returns_cached_loaders_when_provided_same_input()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                var cache = new MetadataCache();

                var loaders1 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList<MetadataArtifactLoader>();
                var loaders2 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList<MetadataArtifactLoader>();

                Assert.Equal(3, loaders1.Count);
                Assert.Equal(3, loaders2.Count);

                for (var i = 0; i < loaders1.Count; i++)
                {
                    Assert.Same(loaders1[i], loaders2[i]);
                }
            }
Exemplo n.º 8
0
            public void GetArtifactLoader_returns_cached_loaders_when_provided_same_input()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                var cache = new MetadataCache();

                var loaders1 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList <MetadataArtifactLoader>();
                var loaders2 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList <MetadataArtifactLoader>();

                Assert.Equal(3, loaders1.Count);
                Assert.Equal(3, loaders2.Count);

                for (var i = 0; i < loaders1.Count; i++)
                {
                    Assert.Same(loaders1[i], loaders2[i]);
                }
            }
Exemplo n.º 9
0
            public void GetArtifactLoader_does_not_use_cached_loaders_when_metadata_directory_is_used_for_loading()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataDirs);
                var cache = new MetadataCache();

                var loaders1 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList <MetadataArtifactLoader>();
                var loaders2 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList <MetadataArtifactLoader>();

                Assert.Equal(3, loaders1.Count);
                Assert.Equal(3, loaders2.Count);

                for (var i = 0; i < loaders1.Count; i++)
                {
                    Assert.NotSame(loaders1[i], loaders2[i]);
                }
            }
Exemplo n.º 10
0
            public void GetMetadataWorkspace_uses_given_artifact_loader_to_create_workspace()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);

                var loader    = new MetadataCache().GetArtifactLoader(options.Object);
                var workspace = new MetadataCache().GetMetadataWorkspace("Key Lime", loader);

                var edmItemCollection = (EdmItemCollection)workspace.GetItemCollection(DataSpace.CSpace);

                Assert.NotNull(edmItemCollection.GetItem <EntityType>("MetadataCacheTests.BlogEdmx"));

                var storeItemCollection = (StoreItemCollection)workspace.GetItemCollection(DataSpace.SSpace);

                Assert.NotNull(storeItemCollection.GetItem <EntityType>("CodeFirstDatabaseSchema.BlogEdmx"));

                Assert.IsType <StorageMappingItemCollection>(workspace.GetItemCollection(DataSpace.CSSpace));
            }
Exemplo n.º 11
0
            public void Clear_clears_all_cached_artifact_loaders()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                var cache = new MetadataCache();

                var loaders1 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList <MetadataArtifactLoader>();

                cache.Clear();

                var loaders2 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList <MetadataArtifactLoader>();

                Assert.Equal(3, loaders1.Count);
                Assert.Equal(3, loaders2.Count);

                for (var i = 0; i < loaders1.Count; i++)
                {
                    Assert.NotSame(loaders1[i], loaders2[i]);
                }
            }
Exemplo n.º 12
0
            public void GetMetadataWorkspace_caches_based_on_artifact_paths_and_store_provider()
            {
                var options = new Mock <DbConnectionOptions>();

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");

                var cache = new MetadataCache();

                var workspace = cache.GetMetadataWorkspace(options.Object);

                Assert.Same(workspace, cache.GetMetadataWorkspace(options.Object));

                options.Setup(m => m["provider"]).Returns("Another Provider");
                Assert.NotSame(workspace, cache.GetMetadataWorkspace(options.Object));

                options.Setup(m => m["metadata"]).Returns(EmbdeddedMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");
                Assert.NotSame(workspace, cache.GetMetadataWorkspace(options.Object));

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");
                Assert.Same(workspace, cache.GetMetadataWorkspace(options.Object));
            }
            public void Clear_clears_all_cached_artifact_loaders()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                var cache = new MetadataCache();

                var loaders1 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList<MetadataArtifactLoader>();

                cache.Clear();

                var loaders2 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList<MetadataArtifactLoader>();

                Assert.Equal(3, loaders1.Count);
                Assert.Equal(3, loaders2.Count);

                for (var i = 0; i < loaders1.Count; i++)
                {
                    Assert.NotSame(loaders1[i], loaders2[i]);
                }
            }
            public void Clear_clears_all_cached_workspaces()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");

                var cache = new MetadataCache();

                var workspace = cache.GetMetadataWorkspace(options.Object);

                cache.Clear();

                Assert.NotSame(workspace, cache.GetMetadataWorkspace(options.Object));
            }
            public void GetMetadataWorkspace_caches_based_on_artifact_paths_and_store_provider()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");

                var cache = new MetadataCache();

                var workspace = cache.GetMetadataWorkspace(options.Object);
                Assert.Same(workspace, cache.GetMetadataWorkspace(options.Object));

                options.Setup(m => m["provider"]).Returns("Another Provider");
                Assert.NotSame(workspace, cache.GetMetadataWorkspace(options.Object));

                options.Setup(m => m["metadata"]).Returns(EmbdeddedMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");
                Assert.NotSame(workspace, cache.GetMetadataWorkspace(options.Object));

                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);
                options.Setup(m => m["provider"]).Returns("Some Provider");
                Assert.Same(workspace, cache.GetMetadataWorkspace(options.Object));
            }
            public void GetMetadataWorkspace_returns_cached_workspace_based_on_cache_key()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);

                var loader1 = new MetadataCache().GetArtifactLoader(options.Object);
                var loader2 = new MetadataCache().GetArtifactLoader(options.Object);

                var cache = new MetadataCache();

                Assert.Same(
                    cache.GetMetadataWorkspace("Key Lime", loader1),
                    cache.GetMetadataWorkspace("Key Lime", loader2));
            }
            public void GetMetadataWorkspace_uses_given_artifact_loader_to_create_workspace()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataPaths);

                var loader = new MetadataCache().GetArtifactLoader(options.Object);
                var workspace = new MetadataCache().GetMetadataWorkspace("Key Lime", loader);

                var edmItemCollection = (EdmItemCollection)workspace.GetItemCollection(DataSpace.CSpace);
                Assert.NotNull(edmItemCollection.GetItem<EntityType>("MetadataCacheTests.BlogEdmx"));

                var storeItemCollection = (StoreItemCollection)workspace.GetItemCollection(DataSpace.SSpace);
                Assert.NotNull(storeItemCollection.GetItem<EntityType>("CodeFirstDatabaseSchema.BlogEdmx"));

                Assert.IsType<StorageMappingItemCollection>(workspace.GetItemCollection(DataSpace.CSSpace));
            }
            public void GetArtifactLoader_does_not_use_cached_loaders_when_metadata_directory_is_used_for_loading()
            {
                var options = new Mock<DbConnectionOptions>();
                options.Setup(m => m["metadata"]).Returns(FileMetadataDirs);
                var cache = new MetadataCache();

                var loaders1 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList<MetadataArtifactLoader>();
                var loaders2 = ((MetadataArtifactLoaderComposite)cache.GetArtifactLoader(options.Object)).ToList<MetadataArtifactLoader>();

                Assert.Equal(3, loaders1.Count);
                Assert.Equal(3, loaders2.Count);

                for (var i = 0; i < loaders1.Count; i++)
                {
                    Assert.NotSame(loaders1[i], loaders2[i]);
                }
            }