Пример #1
0
 public IActionResult GetAll()
 {
     return(Ok(_settingsManager.GetSettings()));
 }
Пример #2
0
        public void BasicReadWriteTests()
        {
            BuildFileSystemMock((Mock <IFileSystem> fileSystemMock) =>
            {
                FileSystemHelpers.Instance = fileSystemMock.Object;
                var mockTracer             = new Mock <ITracer>();

                var manager = new DiagnosticsSettingsManager(@"x:\test.json", mockTracer.Object);

                // should see default value
                DiagnosticsSettings settings = manager.GetSettings();
                Assert.Equal(false, settings.AzureDriveEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureDriveTraceLevel);
                Assert.Equal(false, settings.AzureTableEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureTableTraceLevel);
                Assert.Equal(false, settings.AzureBlobEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureBlobTraceLevel);

                // update with good value
                manager.UpdateSetting(DiagnosticsSettings.AzureDriveEnabledKey, true);
                manager.UpdateSetting(DiagnosticsSettings.AzureDriveTraceLevelKey, TraceEventType.Verbose);
                manager.UpdateSetting(DiagnosticsSettings.AzureTableEnabledKey, true);
                manager.UpdateSetting(DiagnosticsSettings.AzureTableTraceLevelKey, TraceEventType.Warning);
                manager.UpdateSetting(DiagnosticsSettings.AzureBlobEnabledKey, true);
                manager.UpdateSetting(DiagnosticsSettings.AzureBlobTraceLevelKey, TraceEventType.Information);

                settings = manager.GetSettings();
                Assert.Equal(true, settings.AzureDriveEnabled);
                Assert.Equal(TraceEventType.Verbose, settings.AzureDriveTraceLevel);
                Assert.Equal(true, settings.AzureTableEnabled);
                Assert.Equal(TraceEventType.Warning, settings.AzureTableTraceLevel);
                Assert.Equal(true, settings.AzureBlobEnabled);
                Assert.Equal(TraceEventType.Information, settings.AzureBlobTraceLevel);

                // number and string should be good too
                manager.UpdateSetting(DiagnosticsSettings.AzureDriveTraceLevelKey, 2);
                settings = manager.GetSettings();
                Assert.Equal(TraceEventType.Error, settings.AzureDriveTraceLevel);

                JsonSerializationException exception = null;

                try
                {
                    manager.UpdateSetting(DiagnosticsSettings.AzureTableTraceLevelKey, "Error");
                }
                catch (JsonSerializationException ex)
                {
                    exception = ex;
                }

                Assert.NotNull(exception);
                Assert.Equal("Error getting value from 'AzureTableTraceLevel' on 'Kudu.Contracts.Settings.DiagnosticsSettings'.", exception.Message);

                try
                {
                    manager.UpdateSetting(DiagnosticsSettings.AzureTableTraceLevelKey, "8");
                }
                catch (JsonSerializationException ex)
                {
                    exception = ex;
                }

                Assert.Equal("Error getting value from 'AzureTableTraceLevel' on 'Kudu.Contracts.Settings.DiagnosticsSettings'.", exception.Message);

                try
                {
                    manager.UpdateSetting(DiagnosticsSettings.AzureTableTraceLevelKey, "foo");
                }
                catch (JsonSerializationException ex)
                {
                    exception = ex;
                }

                Assert.Equal("Error getting value from 'AzureTableTraceLevel' on 'Kudu.Contracts.Settings.DiagnosticsSettings'.", exception.Message);

                try
                {
                    manager.UpdateSetting(DiagnosticsSettings.AzureBlobTraceLevelKey, 999);
                }
                catch (JsonSerializationException ex)
                {
                    exception = ex;
                }

                Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Error converting value '{0}'", 999), exception.Message);

                settings = manager.GetSettings();
                Assert.Equal(true, settings.AzureDriveEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureDriveTraceLevel);
                Assert.Equal(true, settings.AzureTableEnabled);
                Assert.Equal(TraceEventType.Warning, settings.AzureTableTraceLevel);
                Assert.Equal(true, settings.AzureBlobEnabled);
                Assert.Equal(TraceEventType.Information, settings.AzureBlobTraceLevel);

                // with corrupted content, kudu will auto-correct content and reset to default value
                manager  = new DiagnosticsSettingsManager(@"x:\bad-content.json", mockTracer.Object);
                settings = manager.GetSettings();
                Assert.Equal(false, settings.AzureDriveEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureDriveTraceLevel);
                Assert.Equal(false, settings.AzureTableEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureTableTraceLevel);
                Assert.Equal(false, settings.AzureBlobEnabled);
                Assert.Equal(TraceEventType.Error, settings.AzureBlobTraceLevel);
            });
        }
Пример #3
0
 public HttpResponseMessage GetAll()
 {
     return(Request.CreateResponse(HttpStatusCode.OK, _settingsManager.GetSettings()));
 }