private void PreviewBeforeQueryStatus(object sender, EventArgs eventArgs)
        {
            try
            {
                var menuCommand = sender as OleMenuCommand;
                if (menuCommand == null)
                {
                    return;
                }

                var dte2         = DTEExtensions.GetInstance();
                var selectedItem = dte2.GetSelectedItem();
                // cache selected config project
                _selectedProjectItem = selectedItem.ProjectItem;
                if (ConfigTransformManager.IsTransformConfigName(_selectedProjectItem.Name))
                {
                    menuCommand.Visible = true;
                }
                else
                {
                    menuCommand.Visible = false;
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture,
                                              "Exception in PreviewBeforeQueryStatus() of: {0}. Exception message: {1}", this,
                                              e.Message));
            }
        }
예제 #2
0
        public void EditProjectFile_WhenAnyConfig_ThenShowMessageBoxAndAddXmlDataToProjectFileAndSave()
        {
            //Arrange
            var vsServices = new Mock <IVsServices>();
            var projectXml = new Mock <IVsProjectXmlTransform>();

            ConfigTransformManager.VsService           = vsServices.Object;
            ConfigTransformManager.ProjectXmlTransform = projectXml.Object;

            vsServices.Setup(
                s =>
                s.ShowMessageBox(It.IsAny <string>(), It.IsAny <string>(), OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                                 OLEMSGICON.OLEMSGICON_QUERY)).Returns(6).Verifiable();

            var solutionTestHelper = new SolutionTestHelper();

            solutionTestHelper.CreateSolution();

            //Act
            var isSaved = ConfigTransformManager.EditProjectFile(solutionTestHelper.AnyConfigProjectItemMock.Object);

            //Assert
            solutionTestHelper.ProjectTargetMock.Verify(v => v.Save(It.IsAny <string>()));
            projectXml.Verify(v => v.AddTransformTask());
            projectXml.Verify(v => v.AddAfterBuildTarget(RootAnyConfig, @"..\my.common", true));
            projectXml.Verify(v => v.Save());
        }
예제 #3
0
        public void GetTransformConfigName_Throws_NotSupportedException()
        {
            //Arrange
            const string sourceConfigName       = JustConfig;
            const string buildConfigurationName = BuildMock;

            //Act
            ConfigTransformManager.GetTransformConfigName(sourceConfigName, buildConfigurationName);
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var          editProjectFile = ConfigTransformManager.EditProjectFile(_selectedProjectItem);
            const string reloadMessage   = @"Changes were made in project file.";
            const string noChangeMessage = @"No changes were made.";
            var          displayMessage  = editProjectFile ? reloadMessage : noChangeMessage;

            // Show a Message Box
            VsServices.Instance.ShowMessageBox(displayMessage);
        }
예제 #5
0
        public void IsRootAppConfig_WhenNotAppAndConfig_ReturnFalse()
        {
            //Arrange
            const string sourceConfigName = RootAnyConfig;

            //Act
            var actual = ConfigTransformManager.IsRootAppConfig(sourceConfigName);

            //Assert
            Assert.IsFalse(actual);
        }
예제 #6
0
        public void IsTransformConfigName_WhenNotEndingWithConfig_ReturnFalse()
        {
            //Arrange
            const string sourceConfigName = FileWith3Dots;

            //Act
            var actual = ConfigTransformManager.IsTransformConfigName(sourceConfigName);

            //Assert
            Assert.IsFalse(actual);
        }
예제 #7
0
        public void IsTransformConfigName_WhenNotHavingConfigurationInName_ReturnFalse()
        {
            //Arrange
            const string sourceConfigName = RootAppConfig;

            //Act
            var actual = ConfigTransformManager.IsTransformConfigName(sourceConfigName);

            //Assert
            Assert.IsFalse(actual);
        }
예제 #8
0
        public void IsRootConfig_WhenItIsCsFile_ReturnFalse()
        {
            //Arrange
            const string sourceConfigName = CsFile;

            //Act
            var actual = ConfigTransformManager.IsRootConfig(sourceConfigName);

            //Assert
            Assert.IsFalse(actual);
        }
 private void PreviewMenuItemCallback(object sender, EventArgs eventArgs)
 {
     try
     {
         ConfigTransformManager.PreviewTransform(_selectedProjectItem);
     }
     catch (Exception e)
     {
         Trace.WriteLine(string.Format(CultureInfo.CurrentCulture,
                                       "Exception in PreviewMenuItemCallback() of: {0}. Exception message: {1}", this, e.Message));
     }
 }
예제 #10
0
        public void GetTransformConfigName_WhenMoreDots_Success()
        {
            //Arrange
            const string sourceConfigName       = FileWithMoreDots;
            const string buildConfigurationName = BuildMock;
            const string expected = @"file.with.more.dots.MockBuild.config";

            //Act
            var actual = ConfigTransformManager.GetTransformConfigName(sourceConfigName, buildConfigurationName);

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #11
0
        public void GetTransformConfigName_Success()
        {
            //Arrange
            const string sourceConfigName       = RootAppConfig;
            const string buildConfigurationName = BuildMock;
            const string expected = @"app.MockBuild.config";

            //Act
            var actual = ConfigTransformManager.GetTransformConfigName(sourceConfigName, buildConfigurationName);

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #12
0
        public void IsRootConfig_WhenHavingConfigurationInNameAndNotEndingWithConfig_ReturnFalse()
        {
            //Arrange
            const string sourceConfigName = TransformWithoutConfigExtension;

            //Act
            bool actual;

            actual = ConfigTransformManager.IsRootConfig(sourceConfigName);

            //Assert
            Assert.IsFalse(actual);
        }
예제 #13
0
        public void CreateLinkedConfigFiles_WhenAnyConfig_ThenAddFilesAndSaveTargetProject()
        {
            //Arrange
            var solutionTestHelper = new SolutionTestHelper();

            solutionTestHelper.CreateSolution();

            var fileWrapperMock = new Mock <IFileWrapper>();

            fileWrapperMock.Setup(wrapper => wrapper.Exists(It.IsAny <string>())).Returns(true);
            ConfigTransformManager.FileWrapper = fileWrapperMock.Object;

            //Act
            ConfigTransformManager.CreateLinkedConfigFiles(solutionTestHelper.AnyConfigProjectItemMock.Object);

            //Assert
            solutionTestHelper.AnyConfigProjectItemChildsMock.Verify(v => v.AddFromFile(@"c:\myproject\my.common\any.debug.config"));
            solutionTestHelper.AnyConfigProjectItemChildsMock.Verify(v => v.AddFromFile(@"c:\myproject\my.common\any.release.config"));
        }