Пример #1
0
        public async Task RemoveProfileAsync_ProfileExists(bool isInMemory)
        {
            var moqFS = new IFileSystemMock();

            using var provider = GetLaunchSettingsProvider(moqFS);
            var profiles = new List <ILaunchProfile>()
            {
                { new LaunchProfile()
                  {
                      Name = "IIS Express", CommandName = "IISExpress", LaunchBrowser = true
                  } },
                { new LaunchProfile()
                  {
                      Name = "test", ExecutablePath = "c:\\test\\project\\bin\\test.exe", CommandLineArgs = @"-someArg", DoNotPersist = isInMemory
                  } },
                { new LaunchProfile()
                  {
                      Name = "bar", ExecutablePath = "c:\\test\\project\\bin\\bar.exe"
                  } }
            };

            var testSettings = new Mock <ILaunchSettings>();

            testSettings.Setup(m => m.Profiles).Returns(profiles.ToImmutableList());

            provider.SetCurrentSnapshot(testSettings.Object);

            await provider.RemoveProfileAsync("test");

            // Check disk file was written
            Assert.Equal(!isInMemory, moqFS.FileExists(provider.LaunchSettingsFile));

            // Check snapshot
            AssertEx.CollectionLength(provider.CurrentSnapshot.Profiles, 2);
            Assert.Null(provider.CurrentSnapshot.Profiles.FirstOrDefault(p => p.Name.Equals("test")));
        }
Пример #2
0
        public async Task RemoveGlobalSettingAsync_SettingDoesntExist()
        {
            var moqFS = new IFileSystemMock();

            using var provider = GetLaunchSettingsProvider(moqFS);
            SetJsonSerializationProviders(provider);

            var globalSettings = ImmutableStringDictionary <object> .EmptyOrdinal.Add("test", new LaunchProfile());

            var testSettings = new Mock <ILaunchSettings>();

            testSettings.Setup(m => m.GlobalSettings).Returns(globalSettings);
            testSettings.Setup(m => m.Profiles).Returns(ImmutableList <ILaunchProfile> .Empty);

            provider.SetCurrentSnapshot(testSettings.Object);

            await provider.RemoveGlobalSettingAsync("iisSettings");

            // Check disk file was not written
            Assert.False(moqFS.FileExists(provider.LaunchSettingsFile));

            // Check snapshot
            Assert.Single(provider.CurrentSnapshot.GlobalSettings);
        }
        public async Task LaunchSettingsProvider_RemoveProfileAsync_ProfileExists()
        {
            IFileSystemMock moqFS    = new IFileSystemMock();
            var             provider = GetLaunchSettingsProvider(moqFS);

            var profiles = new List <ILaunchProfile>()
            {
                { new LaunchProfile()
                  {
                      Name = "IIS Express", CommandName = "IISExpress", LaunchBrowser = true
                  } },
                { new LaunchProfile()
                  {
                      Name = "test", ExecutablePath = "c:\\test\\project\\bin\\test.exe", CommandLineArgs = @"-someArg"
                  } },
                { new LaunchProfile()
                  {
                      Name = "bar", ExecutablePath = "c:\\test\\project\\bin\\bar.exe"
                  } }
            };

            var testSettings = new Mock <ILaunchSettings>();

            testSettings.Setup(m => m.Profiles).Returns(profiles.ToImmutableList());

            provider.SetCurrentSnapshot(testSettings.Object);

            await provider.RemoveProfileAsync("test").ConfigureAwait(true);

            // Check disk file was written
            Assert.True(moqFS.FileExists(provider.LaunchSettingsFile));

            // Check snapshot
            Assert.Equal(2, provider.CurrentSnapshot.Profiles.Count);
            Assert.Null(provider.CurrentSnapshot.Profiles.FirstOrDefault(p => p.Name.Equals("test")));
        }
Пример #4
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));
        }