public void RetargetFilesInProject_retargets_Edmx_files_in_project()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

            var projectItems =
                new[]
            {
                MockDTE.CreateProjectItem("C:\\model1.edmx"),
                MockDTE.CreateProjectItem("D:\\model2.EDMX")
            };

            var fileInfos =
                projectItems.Select(
                    i =>
                    new VSFileFinder.VSFileInfo
            {
                Hierarchy = mockDte.Hierarchy,
                ItemId    = mockDte.AddProjectItem(i),
                Path      = i.Object.get_FileNames(1)
            }).ToArray();

            var mockRetargetingHandler =
                new Mock <RetargetingHandler>(mockDte.Hierarchy, mockDte.ServiceProvider)
            {
                CallBase = true
            };

            mockRetargetingHandler
            .Protected()
            .Setup <IEnumerable <VSFileFinder.VSFileInfo> >("GetEdmxFileInfos")
            .Returns(fileInfos);

            mockRetargetingHandler
            .Protected().Setup <bool>("IsDataServicesEdmx", ItExpr.IsAny <string>()).Returns(false);

            mockRetargetingHandler
            .Protected()
            .Setup <XmlDocument>("RetargetFile", ItExpr.IsAny <string>(), ItExpr.IsAny <Version>()).Returns(new XmlDocument());

            mockRetargetingHandler
            .Protected()
            .Setup("WriteModifiedFiles", ItExpr.IsAny <Project>(), ItExpr.IsAny <Dictionary <string, object> >())
            .Callback(
                (Project project, Dictionary <string, object> documentMap) =>
                Assert.Equal(fileInfos.Select(f => f.Path), documentMap.Keys));

            mockRetargetingHandler.Object.RetargetFilesInProject();

            mockRetargetingHandler.Protected().Verify("IsDataServicesEdmx", Times.Exactly(2), ItExpr.IsAny <string>());
            mockRetargetingHandler.Protected().Verify("RetargetFile", Times.Exactly(2), ItExpr.IsAny <string>(), ItExpr.IsAny <Version>());
        }
示例#2
0
        private static MockDTE SetupMockProjectWithCustomizedTemplate(string templatePath)
        {
            Mock <ProjectItem> mockChildProjectItem = null;

            foreach (var step in templatePath.Split('\\').Reverse())
            {
                var mockProjectItem = MockDTE.CreateProjectItem(step);

                var mockProperty = new Mock <Property>();
                mockProperty.Setup(p => p.Name).Returns("FullPath");
                mockProperty.Setup(p => p.Value).Returns(step);

                var mockProperties = new Mock <Properties>();
                mockProperties.As <IEnumerable>()
                .Setup(p => p.GetEnumerator())
                .Returns(() => new[] { mockProperty.Object }.GetEnumerator());

                mockProjectItem.
                Setup(i => i.Properties)
                .Returns(mockProperties.Object);

                mockProjectItem
                .Setup(p => p.ProjectItems)
                .Returns(CreateProjectItems(mockChildProjectItem == null ? null : mockChildProjectItem.Object));

                mockChildProjectItem = mockProjectItem;
            }

            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

            mockChildProjectItem
            .SetupGet(i => i.ContainingProject)
            .Returns(mockDte.Project);

            Mock.Get(mockDte.Project)
            .Setup(p => p.ProjectItems)
            .Returns(CreateProjectItems(mockChildProjectItem.Object));

            return(mockDte);
        }