public void GenerateModel_writes_errors_if_any_returned_from_model_generation()
        {
            var modelGenCache = new ModelGenErrorCache();
            var mockPackage = new Mock<IEdmPackage>();
            mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache);

            PackageManager.Package = mockPackage.Object;
            var mockHostContext = new Mock<ModelBuilderEngineHostContext>();
            var mockModelBuilderSettings = CreateMockModelBuilderSettings();
            var mockModelBuilderEngine = new Mock<ModelBuilderEngine> { CallBase = true };

            var error = new EdmSchemaError("testError", 42, EdmSchemaErrorSeverity.Warning);

            mockModelBuilderEngine
                .Setup(m => m.GenerateModels(It.IsAny<string>(), It.IsAny<ModelBuilderSettings>(), It.IsAny<List<EdmSchemaError>>()))
                .Callback(
                    (string storeModelNamespace, ModelBuilderSettings settings, List<EdmSchemaError> errors) => errors.Add(error))
                .Returns(new DbModel(new DbProviderInfo("System.Data.SqlClient", "2008"), Mock.Of<DbProviderManifest>()));

            mockModelBuilderEngine.Object.GenerateModel(mockModelBuilderSettings.Object, Mock.Of<IVsUtils>(), mockHostContext.Object);

            mockModelBuilderEngine
                .Verify(m => m.GenerateModels(
                    It.IsAny<string>(), It.IsAny<ModelBuilderSettings>(), It.IsAny<List<EdmSchemaError>>()), Times.Once());

            mockHostContext.Verify(h => h.LogMessage(It.IsAny<string>()), Times.Exactly(3));
            mockHostContext
                .Verify(h => h.LogMessage(It.IsRegex(Resources.Engine_ModelGenErrors.Substring(1, 20))), Times.Once());
            mockHostContext
                .Verify(h => h.LogMessage(It.IsRegex(Resources.Engine_ModelGenException)), Times.Never());

            Assert.Same(error, modelGenCache.GetErrors(mockModelBuilderSettings.Object.ModelPath).Single());
        }
            public void ProcessModel_calls_into_model_generation_extension_dispatcher()
            {
                var modelGenCache = new ModelGenErrorCache();
                var mockPackage = new Mock<IEdmPackage>();
                mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache);

                PackageManager.Package = mockPackage.Object;

                var mockInitialContentsFactory = new Mock<IInitialModelContentsFactory>();
                mockInitialContentsFactory
                    .Setup(f => f.GetInitialModelContents(It.IsAny<Version>()))
                    .Returns(new InitialModelContentsFactory().GetInitialModelContents(EntityFrameworkVersion.Version3));

                var settings = CreateMockModelBuilderSettings().Object;
                var mockHostContext = new Mock<VSModelBuilderEngineHostContext>(settings);

                var mockModelBuilderEngine = new Mock<EdmxModelBuilderEngine>(mockInitialContentsFactory.Object) { CallBase = true };

                mockModelBuilderEngine
                    .Setup(m => m.GenerateModels(It.IsAny<string>(), It.IsAny<ModelBuilderSettings>(), It.IsAny<List<EdmSchemaError>>()))
                    .Returns(new DbModel(new DbProviderInfo("System.Data.SqlClient", "2008"), Mock.Of<DbProviderManifest>()));

                mockModelBuilderEngine.Object.GenerateModel(settings, Mock.Of<IVsUtils>(), mockHostContext.Object);

                mockHostContext.Verify(h => h.DispatchToModelGenerationExtensions(), Times.Once());
            }
예제 #3
0
 // testing only
 internal OneEFWizard(ConfigFileUtils configFileUtils = null, IVsUtils vsUtils = null, IErrorListHelper errorListHelper = null, ModelGenErrorCache errorCache = null, 
     List<KeyValuePair<string, string>> generatedCode = null)
 {
     _configFileUtils = configFileUtils;
     _generatedCode = generatedCode ?? new List<KeyValuePair<string, string>>();
     _vsUtils = vsUtils;
     _errorListHelper = errorListHelper;
     _errorCache = errorCache;
 }
        public void Can_add_get_remove_errors()
        {
            var errorCache = new ModelGenErrorCache();
            var errors = new List<EdmSchemaError>(new[] { new EdmSchemaError("test", 42, EdmSchemaErrorSeverity.Error) });

            errorCache.AddErrors("abc", errors);
            Assert.Same(errors, errorCache.GetErrors("abc"));

            errorCache.RemoveErrors("abc");
            Assert.Null(errorCache.GetErrors("abc"));
        }
예제 #5
0
        public void Can_add_get_remove_errors()
        {
            var errorCache = new ModelGenErrorCache();
            var errors     = new List <EdmSchemaError>(new[] { new EdmSchemaError("test", 42, EdmSchemaErrorSeverity.Error) });

            errorCache.AddErrors("abc", errors);
            Assert.Same(errors, errorCache.GetErrors("abc"));

            errorCache.RemoveErrors("abc");
            Assert.Null(errorCache.GetErrors("abc"));
        }
            public void ProcessModel_serializes_model_to_edmx_and_adds_designer_otions()
            {
                var modelGenCache = new ModelGenErrorCache();
                var mockPackage = new Mock<IEdmPackage>();
                mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache);

                PackageManager.Package = mockPackage.Object;

                var mockInitialContentsFactory = new Mock<IInitialModelContentsFactory>();
                mockInitialContentsFactory
                    .Setup(f => f.GetInitialModelContents(It.IsAny<Version>()))
                    .Returns(new InitialModelContentsFactory().GetInitialModelContents(EntityFrameworkVersion.Version3));

                var settings = CreateMockModelBuilderSettings().Object;

                var mockModelBuilderEngine = new Mock<EdmxModelBuilderEngine>(mockInitialContentsFactory.Object) { CallBase = true };

                mockModelBuilderEngine
                    .Setup(m => m.GenerateModels(It.IsAny<string>(), It.IsAny<ModelBuilderSettings>(), It.IsAny<List<EdmSchemaError>>()))
                    .Returns(new DbModel(new DbProviderInfo("System.Data.SqlClient", "2008"), Mock.Of<DbProviderManifest>()));

                mockModelBuilderEngine.Object.GenerateModel(settings, Mock.Of<IVsUtils>(), Mock.Of<ModelBuilderEngineHostContext>());

                var edmx = mockModelBuilderEngine.Object.Edmx;

                Assert.NotEmpty(
                    edmx
                        .Descendants().Where(e => e.Name.LocalName == "StorageModels")
                        .Elements().Where(e => e.Name.LocalName == "Schema"));

                Assert.NotEmpty(
                    edmx
                        .Descendants().Where(e => e.Name.LocalName == "ConceptualModels")
                        .Elements().Where(e => e.Name.LocalName == "Schema"));

                Assert.NotEmpty(
                    edmx
                        .Descendants().Where(e => e.Name.LocalName == "Mappings")
                        .Elements().Where(e => e.Name.LocalName == "Mapping"));

                Assert.Equal(
                    3,
                    edmx
                        .Descendants().Where(e => e.Name.LocalName == "DesignerInfoPropertySet")
                        .Elements().Count(e => e.Name.LocalName == "DesignerProperty"));
            }
예제 #7
0
        public void GetModelGenErrors_returns_errors_stored_in_ModelGenCache()
        {
            var modelGenCache = new ModelGenErrorCache();
            var errors = new List<EdmSchemaError>(new[] { new EdmSchemaError("test", 42, EdmSchemaErrorSeverity.Error) });
            modelGenCache.AddErrors(@"C:\temp.edmx", errors);

            var mockPackage = new Mock<IEdmPackage>();
            mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache);
            PackageManager.Package = mockPackage.Object;

            var modelManager = new Mock<ModelManager>(null, null).Object;
            var modelProvider = new Mock<XmlModelProvider>().Object;
            using (var vsArtifact = new VSArtifact(modelManager, new Uri(@"C:\temp.edmx"), modelProvider))
            {
                Assert.Same(errors, vsArtifact.GetModelGenErrors());
            }
        }
예제 #8
0
        private static OneEFWizard CreateOneEFWizard(string itemPath, IEnumerable<EdmSchemaError> edmSchemaErrors, out Mock<IErrorListHelper> mockErrorListHelper, out Mock<ProjectItem> mockProjectItem)
        {
            var mockDte = new Mock<DTE>();
            mockDte.As<IOleServiceProvider>();
            var mockProject = new Mock<Project>();
            mockProject.Setup(p => p.DTE).Returns(mockDte.Object);

            var mockVsUtils = new Mock<IVsUtils>();
            mockErrorListHelper = new Mock<IErrorListHelper>();
            var errorCache = new ModelGenErrorCache();

            if (edmSchemaErrors != null)
            {
                errorCache.AddErrors(
                    itemPath,
                    edmSchemaErrors.ToList());
            }

            mockProjectItem = new Mock<ProjectItem>();
            mockProjectItem.Setup(p => p.get_FileNames(1)).Returns(itemPath);
            mockProjectItem.Setup(p => p.ContainingProject).Returns(mockProject.Object);

            return new OneEFWizard(
                vsUtils: mockVsUtils.Object, errorListHelper: mockErrorListHelper.Object, errorCache: errorCache);
        }
        protected override void Initialize()
        {
            base.Initialize();

            // for command line builds we only have a minimal set of functionality to only support building
            if (IsBuildingFromCommandLine)
            {
                InitializeForCommandLineBuilds();
            }
            else
            {
                // HACK HACK -- find a better place to do this.
                EFModelErrorTaskNavigator.DslDesignerOnNavigate = DSLDesignerNavigationHelper.NavigateTo;
                // --

                HostContext.Instance.LogUpdateModelWizardErrorAction = ErrorListHelper.LogUpdateModelWizardError;
                PackageManager.Package = this;
                _dispatcher = Dispatcher.CurrentDispatcher;

                // make sure that we can load the XML Editor package
                var vsShell = (IVsShell)GetService(typeof(SVsShell));
                if (vsShell != null)
                {
                    var editorPackageGuid = CommonPackageConstants.xmlEditorPackageGuid;
                    IVsPackage editorPackage;
                    NativeMethods.ThrowOnFailure(vsShell.LoadPackage(ref editorPackageGuid, out editorPackage));
                }

                _documentFrameMgr = new EntityDesignDocumentFrameMgr(PackageManager.Package);
                _modelChangeEventListener = new ModelChangeEventListener();
                _guidsCache = new AggregateProjectTypeGuidCache();
                _modelGenErrorCache = new ModelGenErrorCache();
                _connectionManager = new ConnectionManager();

                AddToolWindow(typeof(MappingDetailsWindow));

                // Register for VS Events
                ErrorListHelper.RegisterForNotifications();

                // Add the handler to show our Explorer. This is for the top-level 'Entity Data Model Browser' command that is added to the
                // 'View' main menu. This is different from the 'Model Browser' command on the designer context menu.
                _viewExplorerCmd = AddCommand(
                    ShowExplorerWindow, ShowExplorerWindow_BeforeQueryStatus, MicrosoftDataEntityDesignCommands.ViewExplorer);

                // Add the handler to show our MappingDesigner. This is for the top-level 'Entity Data Model Mapping Details' command that is added
                // to the 'View' main menu. This is different from the 'Mapping Details' command on the designer context menu.
                _viewMappingCmd = AddCommand(
                    ShowMappingDetailsWindow, ShowMappingDetailsWindow_BeforeQueryStatus, MicrosoftDataEntityDesignCommands.ViewMapping);

                // Subscribe to Project's target framework retargeting
                var projectRetargetingService = GetService(typeof(SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting;
                Debug.Assert(null != projectRetargetingService, "TrackProjectRetargeting service is null");
                _trackProjectRetargetingEventsCookie = 0;
                if (projectRetargetingService != null)
                {
                    projectRetargetingService.AdviseTrackProjectRetargetingEvents(this, out _trackProjectRetargetingEventsCookie);
                }

                // There is no SQL CE support dev12 onward, so removing the references

#if (VS11)
                // Subscribe to the SQL CE and SqlDatabaseFile upgrade services
                var sqlCeUpgradeService = GetGlobalService(typeof(IVsSqlCeUpgradeService)) as IVsSqlCeUpgradeService;
#endif

                var sqlDatabaseFileUpgradeService =
                    GetGlobalService(typeof(IVsSqlDatabaseFileUpgradeService)) as IVsSqlDatabaseFileUpgradeService;

#if (VS12ORNEWER)
                if (sqlDatabaseFileUpgradeService == null)
#else
                if (sqlCeUpgradeService == null
                    || sqlDatabaseFileUpgradeService == null)
#endif
                {
                    // attempt to start IVsSqlCeUpgradeService and IVsSqlDatabaseFileUpgradeService
                    BootstrapVSDesigner();

#if (VS11)
                    if (sqlCeUpgradeService == null)
                    {
                        sqlCeUpgradeService = GetGlobalService(typeof(IVsSqlCeUpgradeService)) as IVsSqlCeUpgradeService;
                    }
#endif

                    if (sqlDatabaseFileUpgradeService == null)
                    {
                        sqlDatabaseFileUpgradeService =
                            GetGlobalService(typeof(IVsSqlDatabaseFileUpgradeService)) as IVsSqlDatabaseFileUpgradeService;
                    }
                }

#if (VS11)
                Debug.Assert(null != sqlCeUpgradeService, "sqlCeUpgradeService service is null");
                if (sqlCeUpgradeService != null)
                {
                    sqlCeUpgradeService.OnUpgradeProject += EdmUtils.SqlCeUpgradeService_OnUpgradeProject;
                }
#endif

                Debug.Assert(null != sqlDatabaseFileUpgradeService, "sqlDatabaseFileUpgradeService service is null");
                if (sqlDatabaseFileUpgradeService != null)
                {
                    sqlDatabaseFileUpgradeService.OnUpgradeProject += EdmUtils.SqlDatabaseFileUpgradeService_OnUpgradeProject;
                }
            }
        }
예제 #10
0
 /// <summary>
 /// This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 public OneEFWizard()
 {
     _vsUtils = new VsUtilsWrapper();
     _errorListHelper = new ErrorListHelperWrapper();
     _errorCache = PackageManager.Package.ModelGenErrorCache;
 }