Esempio n. 1
0
        public async Task AbstractEditProjectFileCommand_NonSaveAction_DoesNotOverwriteProjectFile(FileActionTypes actionType)
        {
            var projectPath     = $"C:\\Project1\\Project1.{EditProjectFileCommand.Extension}";
            var tempFile        = "C:\\Temp\\asdf.xyz";
            var tempProjFile    = $"{tempFile}.{EditProjectFileCommand.Extension}";
            var expectedCaption = $"Project1.{EditProjectFileCommand.Extension}";
            var projectXml      = @"<Project></Project>";

            var fileSystem = new IFileSystemMock();
            var textDoc    = ITextDocumentFactory.Create();
            var frame      = IVsWindowFrameFactory.ImplementShowAndSetProperty(VSConstants.S_OK, (prop, obj) => VSConstants.S_OK);

            var command = SetupScenario(projectXml, tempFile, tempProjFile, projectPath, expectedCaption, fileSystem, textDoc, frame);
            var tree    = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot})
");
            var nodes   = ImmutableHashSet.Create(tree);

            // Verify the frame was setup correctly
            Assert.True(await command.TryHandleCommandAsync(nodes, CommandId, true, 0, IntPtr.Zero, IntPtr.Zero));

            var args = new TextDocumentFileActionEventArgs(tempProjFile, DateTime.Now, actionType);

            Mock.Get(textDoc).Raise(t => t.FileActionOccurred += null, args);
            Assert.False(fileSystem.FileExists(projectPath));
        }
Esempio n. 2
0
        public async Task AbstractEditProjectFileCommand_CorrectNode_CreatesWindowCorrectly()
        {
            var projectPath                = $"C:\\Project1\\Project1.{EditProjectFileCommand.Extension}";
            var tempFile                   = "C:\\Temp\\asdf.xyz";
            var tempProjFile               = $"{tempFile}.{EditProjectFileCommand.Extension}";
            var expectedCaption            = $"Project1.{EditProjectFileCommand.Extension}";
            var projectXml                 = @"<Project></Project>";
            var captionSet                 = false;
            var autoOpenSet                = false;
            var listenerSet                = false;
            IVsWindowFrameNotify2 notifier = null;

            var fileSystem = new IFileSystemMock();
            var textDoc    = ITextDocumentFactory.Create();
            var frame      = IVsWindowFrameFactory.ImplementShowAndSetProperty(VSConstants.S_OK, (property, obj) =>
            {
                switch (property)
                {
                case (int)__VSFPROPID5.VSFPROPID_OverrideCaption:
                    captionSet = true;
                    break;

                case (int)__VSFPROPID5.VSFPROPID_DontAutoOpen:
                    autoOpenSet = true;
                    break;

                case (int)__VSFPROPID.VSFPROPID_ViewHelper:
                    listenerSet = true;
                    Assert.IsAssignableFrom <IVsWindowFrameNotify2>(obj);
                    notifier = obj as IVsWindowFrameNotify2;
                    break;

                default:
                    Assert.False(true, $"Unexpected property ID {property}");
                    break;
                }

                return(VSConstants.S_OK);
            });

            var command = SetupScenario(projectXml, tempFile, tempProjFile, projectPath, expectedCaption, fileSystem, textDoc, frame);
            var tree    = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot})
");
            var nodes   = ImmutableHashSet.Create(tree);

            // Verify the frame was setup correctly
            Assert.True(await command.TryHandleCommandAsync(nodes, CommandId, true, 0, IntPtr.Zero, IntPtr.Zero));
            Assert.Equal(projectXml, fileSystem.ReadAllText(tempProjFile));
            Mock.Get(frame).Verify(f => f.SetProperty((int)__VSFPROPID5.VSFPROPID_OverrideCaption, expectedCaption));
            Mock.Get(frame).Verify(f => f.Show());
            Assert.True(captionSet);
            Assert.True(autoOpenSet);
            Assert.True(listenerSet);
            Assert.NotNull(notifier);

            // Now see if the event correctly saved the text from the buffer into the project file
            var args = new TextDocumentFileActionEventArgs(tempProjFile, DateTime.Now, FileActionTypes.ContentSavedToDisk);

            Mock.Get(textDoc).Raise(t => t.FileActionOccurred += null, args);
            Assert.Equal(projectXml, fileSystem.ReadAllText(projectPath));

            // Finally, ensure the cleanup works as expected. We don't do anything with the passed option. The notifier
            // should remove the file temp file from the filesystem.
            Assert.Equal(VSConstants.S_OK, notifier.OnClose(0));
            Assert.False(fileSystem.FileExists(tempProjFile));
        }