public async Task SaveProfilesToDiskTests()
        {
            var moqFS    = new IFileSystemMock();
            var provider = GetLaunchSettingsProvider(moqFS);

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

            var testSettings = new Mock <ILaunchSettings>();

            testSettings.Setup(m => m.ActiveProfile).Returns(() => { return(profiles[0]); });
            testSettings.Setup(m => m.Profiles).Returns(() =>
            {
                return(profiles.ToImmutableList());
            });
            testSettings.Setup(m => m.GlobalSettings).Returns(() =>
            {
                var iisSettings = new IISSettingsData()
                {
                    AnonymousAuthentication = false,
                    WindowsAuthentication   = true,
                    IISExpressBindingData   = new ServerBindingData()
                    {
                        ApplicationUrl = "http://localhost:12345/",
                        SSLPort        = 44301
                    }
                };
                return(ImmutableStringDictionary <object> .EmptyOrdinal.Add("iisSettings", iisSettings));
            });

            await provider.SaveSettingsToDiskAsyncTest(testSettings.Object);

            // Last Write time should be set
            Assert.Equal(moqFS.LastFileWriteTime(provider.LaunchSettingsFile), provider.LastSettingsFileSyncTimeTest);

            // Check disk contents
            Assert.Equal(JsonStringWithWebSettings, moqFS.ReadAllText(provider.LaunchSettingsFile), ignoreLineEndingDifferences: true);
        }
        public async Task AddOrUpdateGlobalSettingAsync_SettingExists(bool isInMemory, bool existingIsInMemory)
        {
            var moqFS = new IFileSystemMock();

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

                var globalSettings = ImmutableStringDictionary <object> .EmptyOrdinal
                                     .Add("test", new LaunchProfile())
                                     .Add("iisSettings", new IISSettingsData()
                {
                    DoNotPersist = existingIsInMemory
                });

                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);

                var newSettings = new IISSettingsData()
                {
                    WindowsAuthentication = true, DoNotPersist = isInMemory
                };

                await provider.AddOrUpdateGlobalSettingAsync("iisSettings", newSettings);

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

                // Check snapshot
                AssertEx.CollectionLength(provider.CurrentSnapshot.GlobalSettings, 2);
                Assert.True(provider.CurrentSnapshot.GlobalSettings.TryGetValue("iisSettings", out object updatedSettings));

                Assert.True(((IISSettingsData)updatedSettings).WindowsAuthentication);
            }
        }
示例#3
0
        public async Task LaunchSettingsProvider_AddOrUpdateGlobalSettingAsync_SettingExists()
        {
            IFileSystemMock moqFS    = new IFileSystemMock();
            var             provider = GetLaunchSettingsProvider(moqFS);

            // Set the serialization provider
            SetJsonSerializationProviders(provider);

            var globalSettings = ImmutableDictionary <string, object> .Empty
                                 .Add("test", new LaunchProfile())
                                 .Add("iisSettings", new IISSettingsData());

            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);

            var newSettings = new IISSettingsData()
            {
                WindowsAuthentication = true
            };

            await provider.AddOrUpdateGlobalSettingAsync("iisSettings", newSettings).ConfigureAwait(true);

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

            // Check snapshot
            object updatedSettings;

            Assert.Equal(2, provider.CurrentSnapshot.GlobalSettings.Count);
            Assert.True(provider.CurrentSnapshot.GlobalSettings.TryGetValue("iisSettings", out updatedSettings));
            Assert.True(((IISSettingsData)updatedSettings).WindowsAuthentication);
        }
示例#4
0
        public async Task UpdateAndSaveProfilesAsync()
        {
            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 = "bar", ExecutablePath = "c:\\test\\project\\bin\\test.exe", CommandLineArgs = @"-someArg"
                      } }
                };

                var testSettings = new Mock <ILaunchSettings>();
                testSettings.Setup(m => m.ActiveProfile).Returns(() => { return(profiles[0]); });
                testSettings.Setup(m => m.Profiles).Returns(() =>
                {
                    return(profiles.ToImmutableList());
                });

                testSettings.Setup(m => m.GlobalSettings).Returns(() =>
                {
                    var iisSettings = new IISSettingsData()
                    {
                        AnonymousAuthentication = false,
                        WindowsAuthentication   = true,
                        IISExpressBindingData   = new ServerBindingData()
                        {
                            ApplicationUrl = "http://localhost:12345/",
                            SSLPort        = 44301
                        }
                    };
                    return(ImmutableStringDictionary <object> .EmptyOrdinal.Add("iisSettings", iisSettings));
                });

                // Setup SCC to verify it is called before modifying the file
                var mockScc = new Mock <ISourceCodeControlIntegration>(MockBehavior.Strict);
                mockScc.Setup(m => m.CanChangeProjectFilesAsync(It.IsAny <IReadOnlyCollection <string> >())).Returns(Task.FromResult(true));
                var sccProviders = new OrderPrecedenceImportCollection <ISourceCodeControlIntegration>(ImportOrderPrecedenceComparer.PreferenceOrder.PreferredComesFirst, (UnconfiguredProject)null)
                {
                    mockScc.Object
                };
                provider.SetSourceControlProviderCollection(sccProviders);

                await provider.UpdateAndSaveSettingsAsync(testSettings.Object);

                // Check disk contents
                Assert.Equal(JsonStringWithWebSettings, moqFS.ReadAllText(provider.LaunchSettingsFile), ignoreLineEndingDifferences: true);

                // Check snapshot
                AssertEx.CollectionLength(provider.CurrentSnapshot.Profiles, 2);
                Assert.Single(provider.CurrentSnapshot.GlobalSettings);

                // Verify the activeProfile is set to the first one since no existing snapshot
                Assert.Equal("IIS Express", provider.CurrentSnapshot.ActiveProfile.Name);

                mockScc.Verify();
            }
        }