示例#1
0
 public void GetMappingItemCollection_throws_for_null_viewCacheFactory()
 {
     Assert.Equal(
         "viewCacheFactory",
         Assert.Throws <ArgumentNullException>(
             () => InteractiveViews.GetMappingItemCollection(null)).ParamName);
 }
示例#2
0
 public void GetMappingItemCollection_throws_if_no_mapping_item_collection_for_viewCacheFactory()
 {
     Assert.Equal(
         "No StorageMappingItemCollection instance found for the provided DbMappingViewCacheFactory.",
         Assert.Throws <InvalidOperationException>(
             () => InteractiveViews.GetMappingItemCollection(new Mock <DbMappingViewCacheFactory>().Object))
         .Message);
 }
示例#3
0
        public void SetViewCacheFactory_registers_factory_for_DbContext()
        {
            using (var ctx = new DbContext(TestUtils.TempDbConnectionString))
            {
                var viewCacheFactory = new Mock <DbMappingViewCacheFactory>().Object;
                InteractiveViews.SetViewCacheFactory(ctx, viewCacheFactory);

                var mappingItemCollection =
                    (StorageMappingItemCollection)
                    (((IObjectContextAdapter)ctx).ObjectContext)
                    .MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);

                Assert.Same(mappingItemCollection, InteractiveViews.GetMappingItemCollection(viewCacheFactory));
                Assert.Same(viewCacheFactory, mappingItemCollection.MappingViewCacheFactory);
            }
        }
示例#4
0
        public void SetViewCacheFactory_registers_factory_for_ObjectContext()
        {
            using (var entityConnection = new EntityConnection(TestUtils.CreateFakeMetadataWorkspace(), new SqlConnection(TestUtils.TempDbConnectionString)))
            {
                using (var objectCtx = new ObjectContext(entityConnection))
                {
                    var viewCacheFactory = new Mock <DbMappingViewCacheFactory>().Object;
                    InteractiveViews.SetViewCacheFactory(objectCtx, viewCacheFactory);

                    var mappingItemCollection =
                        (StorageMappingItemCollection)objectCtx
                        .MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);

                    Assert.Same(mappingItemCollection, InteractiveViews.GetMappingItemCollection(viewCacheFactory));
                    Assert.Same(viewCacheFactory, mappingItemCollection.MappingViewCacheFactory);
                }
            }
        }
 // virtual for mocking
 internal virtual StorageMappingItemCollection GetMappingItemCollection()
 {
     return(InteractiveViews.GetMappingItemCollection(this));
 }