public void DefaultValuesAreUsedWhenNoArgumentsAreProvided()
 {
     int?testNo = 1;
     // Test 1: All defaults, no options specified
     {
         var args = new string[] { };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++);
     }
     // Test 2: All defaults, -logDir as  null
     {
         var args = new string[] { "--log-dir", null };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++);
     }
     // Test 3: All defaults, -logDir as  empty string
     {
         var args = new string[] { "--log-dir", string.Empty };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++);
     }
     // Test 4: All defaults, -log-file as  null
     {
         var args = new string[] { "--log-file", null };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, logFilePath: null);
     }
     // Test 5: All defaults, -log-file as  empty string
     {
         var args = new string[] { "--log-file", string.Empty };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, logFilePath: string.Empty);
     }
 }
Esempio n. 2
0
        public void UsageIsShownWhenBadArgumentsProvided()
        {
            var args = new string[] { "--unknown-argument", "/bad-argument" };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            Assert.NotNull(options);

            Assert.True(options.ShouldExit);
            Assert.Equal(options.Locale, string.Empty);
        }
Esempio n. 3
0
        public void UsageIsShownWhenHelpFlagProvided()
        {
            var args = new string[] { "--help" };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            Assert.NotNull(options);

            Assert.True(options.ShouldExit);
            Assert.Equal(options.Locale, string.Empty);
        }
        public void LocaleNotSetWhenNotProvided()
        {
            var args = new string[] {};
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.Locale, string.Empty);
        }
Esempio n. 5
0
        public void LocaleSetWhenProvided(string locale)
        {
            var args = new string[] { "--locale", locale };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);;

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.Locale, locale);
        }
Esempio n. 6
0
        public void ShouldExitNotSetWhenInvalidLocale()
        {
            string locale = "invalid";
            var    args   = new string[] { "--locale", locale };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
        }
Esempio n. 7
0
        public void LoggingDisabledWhenFlagNotProvided()
        {
            var args = new string[] {};
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            Assert.NotNull(options);

            Assert.False(options.EnableLogging);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.Locale, string.Empty);
        }
Esempio n. 8
0
        public void LoggingDirectorySet()
        {
            string logDir = Directory.GetCurrentDirectory();
            var    args   = new string[] { "--log-dir", logDir };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.LoggingDirectory, logDir);
        }
        public void LogFilePathSet()
        {
            string expectedFilePath            = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var    args                        = new string[] { "--log-file", expectedFilePath };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.LogFilePath, expectedFilePath);
        }
        public void AutoFlushLogSet()
        {
            bool expectedAutoFlush = true;
            var  args = new string[] { "--autoflush-log" };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.AutoFlushLog, expectedAutoFlush);
        }
        public void TracingLevelSet()
        {
            string expectedLevel = "Information";
            var    args          = new string[] { "--tracing-level", expectedLevel };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            // Asserting all options were properly set
            Assert.NotNull(options);
            Assert.False(options.ShouldExit);
            Assert.Equal(options.TracingLevel, expectedLevel);
        }
        private static void VerifyCommandOptions(ServiceLayerCommandOptions options, int?testNo = null, string errorMessage = "", string tracingLevel = null, string logFilePath = null, bool shouldExit = false, string locale = "", bool autoFlushLog = false)
        {
            Assert.NotNull(options);
            string MsgPrefix = testNo != null ? $"TestNo:{testNo} ::" : string.Empty;

            Assert.True(errorMessage == options.ErrorMessage, $"{MsgPrefix} options:{nameof(errorMessage)} should be '{errorMessage}'");
            Assert.True(tracingLevel == options.TracingLevel, $"{MsgPrefix} options:{nameof(tracingLevel)} should be '{tracingLevel}'");
            Assert.True(logFilePath == options.LogFilePath, $"{MsgPrefix} options:{nameof(logFilePath)} should be '{logFilePath}'");
            Assert.True(shouldExit == options.ShouldExit, $"{MsgPrefix} options:{nameof(shouldExit)} should be '{shouldExit}'");
            Assert.True(autoFlushLog == options.AutoFlushLog, $"{MsgPrefix} options:{nameof(autoFlushLog)} should be '{autoFlushLog}'");
            Assert.True(options.Locale == locale, $"{MsgPrefix} options:{nameof(locale)} should be '{locale}'");
        }
Esempio n. 13
0
        public void DefaultValuesAreUsedWhenNoArgumentsAreProvided()
        {
            var args = new string[] {};
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            Assert.NotNull(options);

            Assert.False(options.EnableLogging);
            Assert.False(options.ShouldExit);
            Assert.True(string.IsNullOrWhiteSpace(options.LoggingDirectory));
            Assert.Equal(options.Locale, string.Empty);
        }
Esempio n. 14
0
        public void SrStringsTestWithEnLocalization()
        {
            string locale = "en";
            var    args   = new string[] { "--locale", locale };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            Assert.Equal(SR.Culture.Name, options.Locale);
            Assert.Equal(options.Locale, locale);

            var TestLocalizationConstant = SR.TestLocalizationConstant;

            Assert.Equal(TestLocalizationConstant, "test");
        }
Esempio n. 15
0
        public void SrStringsTestWithNullLocalization()
        {
            SR.Culture = null;
            var args = new string[] { "" };
            ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);

            Assert.Null(SR.Culture);
            Assert.Equal(options.Locale, "");

            var TestLocalizationConstant = SR.TestLocalizationConstant;

            Assert.Equal(TestLocalizationConstant, "test");
        }
Esempio n. 16
0
        /// <summary>
        /// Main entry point into the SQL Tools API Service Layer
        /// </summary>
        internal static void Main(string[] args)
        {
            try
            {
                // read command-line arguments
                ServiceLayerCommandOptions commandOptions = new ServiceLayerCommandOptions(args);
                if (commandOptions.ShouldExit)
                {
                    return;
                }

                string logFilePath = commandOptions.LogFilePath;
                if (string.IsNullOrWhiteSpace(logFilePath))
                {
                    logFilePath = Logger.GenerateLogFilePath("sqltools");
                }

                Logger.AutoFlush = commandOptions.AutoFlushLog;

                Logger.Initialize(tracingLevel: commandOptions.TracingLevel, logFilePath: logFilePath, traceSource: "sqltools");

                // set up the host details and profile paths
                var hostDetails = new HostDetails(version: new Version(1, 0));

                SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
                ServiceHost     serviceHost     = HostLoader.CreateAndStartServiceHost(sqlToolsContext);

                serviceHost.WaitForExit();
            }
            catch (Exception ex)
            {
                try
                {
                    Logger.WriteWithCallstack(TraceEventType.Critical, $"An unhandled exception occurred: {ex}");
                }
                catch (Exception loggerEx)
                {
                    Console.WriteLine($"Error: Logger unavailable: {loggerEx}");
                    Console.WriteLine($"An unhandled exception occurred: {ex}");
                }
                Environment.Exit(1);
            }
            finally
            {
                Logger.Close();
            }
        }
        private static void VerifyCommandOptions(ServiceLayerCommandOptions options, int?testNo = null, string errorMessage = "", string tracingLevel = null, string logFilePath = null, bool shouldExit = false, string locale = "", string logDirectory = null)
        {
            Assert.NotNull(options);
            string MsgPrefix = testNo != null ? $"TestNo:{testNo} ::" : string.Empty;

            Assert.True(errorMessage == options.ErrorMessage, $"{MsgPrefix} options:{nameof(errorMessage)} should be '{errorMessage}'");
            Assert.True(tracingLevel == options.TracingLevel, $"{MsgPrefix} options:{nameof(tracingLevel)} should be '{tracingLevel}'");
            Assert.True(logFilePath == options.LogFilePath, $"{MsgPrefix} options:{nameof(logFilePath)} should be '{logFilePath}'");
            Assert.True(shouldExit == options.ShouldExit, $"{MsgPrefix} options:{nameof(shouldExit)} should be '{shouldExit}'");
            Assert.False(string.IsNullOrWhiteSpace(options.LoggingDirectory));
            if (string.IsNullOrWhiteSpace(logDirectory))
            {
                logDirectory = Path.Combine(options.DefaultLogRoot, options.ServiceName);
            }
            Assert.True(logDirectory == options.LoggingDirectory, $"{MsgPrefix} options:{nameof(logDirectory)} should be '{logDirectory}'");
            Assert.True(options.Locale == locale, $"{MsgPrefix} options:{nameof(locale)} should be '{locale}'");
        }
 public void DefaultValuesAreUsedWhenNoArgumentsAreProvided()
 {
     int?testNo = 1;
     // Test 1: All defaults, no options specified
     {
         var args = new string[] { };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++);
     }
     // Test 2: All defaults, -autoflush-log as  null
     {
         var args = new string[] { "--autoflush-log", null };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, autoFlushLog: true);
     }
     // Test 3: All defaults, -autoflush-log as  empty string
     {
         var args = new string[] { "--autoflush-log", string.Empty };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, autoFlushLog: true);
     }
     // Test 4: All defaults, -tracing-level as  empty string
     {
         var args = new string[] { "--tracing-level", string.Empty };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, tracingLevel: string.Empty);
     }
     // Test 5: All defaults, -tracing-level as  null
     {
         var args = new string[] { "--tracing-level", null };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, tracingLevel: null);
     }
     // Test 6: All defaults, -log-file as  empty string
     {
         var args = new string[] { "--log-file", string.Empty };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, logFilePath: string.Empty);
     }
     // Test 6: All defaults, -log-file as null
     {
         var args = new string[] { "--log-file", null };
         ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
         VerifyCommandOptions(options, testNo++, logFilePath: null);
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Main entry point into the SQL Tools API Service Layer
        /// </summary>
        internal static void Main(string[] args)
        {
            try
            {
                // read command-line arguments
                ServiceLayerCommandOptions commandOptions = new ServiceLayerCommandOptions(args);
                if (commandOptions.ShouldExit)
                {
                    return;
                }

                string logFilePath = commandOptions.LogFilePath;
                if (string.IsNullOrWhiteSpace(logFilePath))
                {
                    logFilePath = "sqltools";
                }
                if (!string.IsNullOrWhiteSpace(commandOptions.LoggingDirectory))
                {
                    logFilePath = Path.Combine(commandOptions.LoggingDirectory, logFilePath);
                }

                // turn on Verbose logging during early development
                // we need to switch to Information when preparing for public preview
                Logger.Initialize(tracingLevel: commandOptions.TracingLevel, logFilePath: logFilePath, traceSource: "sqltools");
                Logger.Write(TraceEventType.Information, "Starting SQL Tools Service Layer");

                // set up the host details and profile paths
                var hostDetails = new HostDetails(version: new Version(1, 0));

                SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
                ServiceHost     serviceHost     = HostLoader.CreateAndStartServiceHost(sqlToolsContext);

                serviceHost.WaitForExit();
            }
            catch (Exception e)
            {
                Logger.WriteWithCallstack(TraceEventType.Critical, $"An unhandled exception occurred: {e}");
                Environment.Exit(1);
            }
            finally
            {
                Logger.Close();
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Main entry point into the SQL Tools API Service Host
        /// </summary>
        internal static void Main(string[] args)
        {
            try
            {
                // read command-line arguments
                ServiceLayerCommandOptions commandOptions = new ServiceLayerCommandOptions(args);
                if (commandOptions.ShouldExit)
                {
                    return;
                }

                string logFilePath = "sqltools";
                if (!string.IsNullOrWhiteSpace(commandOptions.LoggingDirectory))
                {
                    logFilePath = Path.Combine(commandOptions.LoggingDirectory, logFilePath);
                }

                // turn on Verbose logging during early development
                // we need to switch to Normal when preparing for public preview
                Logger.Initialize(logFilePath: logFilePath, minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging);
                Logger.Write(LogLevel.Normal, "Starting SQL Tools Service Host");

                // set up the host details and profile paths
                var hostDetails = new HostDetails(version: new Version(1, 0));

                SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
                ServiceHost     serviceHost     = HostLoader.CreateAndStartServiceHost(sqlToolsContext);

                serviceHost.WaitForExit();
            }
            catch (Exception e)
            {
                Logger.Write(LogLevel.Error, string.Format("An unhandled exception occurred: {0}", e));
                Environment.Exit(1);
            }
        }