mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:35:43 -05:00
* Initial changes to have serialization generate its own .exe * Removed additional project from sln file * remove all references to removed temporary project * Moved shared contracts into own dll and fixed imports. Addressed PR comments * Undid having a separate contracts project since that'll be a task for later on. Moved dbcellvalue and saveresultsrequest to Hosting, where they will be imported and shared by the service layer and serialization projects * Switched backslashes in project reference in csproj file to forward slashes for consistency * Moved necessary contracts back to service layer. Refactored CommandOptions to reduce code duplication. Addressed miscellaneous PR suggestions * Accidentally left these files out of previous commit * Initialized loggers for serialization and credentials with the logging directory provided by the cmd line arg, if there is one * Changed default log directory paths for serialization and credentials. Removed unnecessary cast and added a copyright * Changed name of generated executable for serialization service * removed unnecessary object cast * removing unnecessary imports and addressing other PR comments
129 lines
4.3 KiB
C#
129 lines
4.3 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System.IO;
|
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
|
{
|
|
/// <summary>
|
|
/// Tests for the CommandOptions class
|
|
/// </summary>
|
|
public class CommandOptionsTests
|
|
{
|
|
[Fact]
|
|
public void LoggingEnabledWhenFlagProvided()
|
|
{
|
|
var args = new string[] {"--enable-logging"};
|
|
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
|
|
Assert.NotNull(options);
|
|
|
|
Assert.True(options.EnableLogging);
|
|
Assert.False(options.ShouldExit);
|
|
Assert.Equal(options.Locale, string.Empty);
|
|
}
|
|
|
|
[Fact]
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
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);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("en")]
|
|
[InlineData("es")]
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
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);
|
|
}
|
|
|
|
[Fact]
|
|
public void LocaleNotSetWhenNotProvided()
|
|
{
|
|
var args = new string[] {};
|
|
ServiceLayerCommandOptions options = new ServiceLayerCommandOptions(args);
|
|
|
|
// Asserting all options were properly set
|
|
Assert.NotNull(options);
|
|
Assert.False(options.EnableLogging);
|
|
Assert.False(options.ShouldExit);
|
|
Assert.Equal(options.Locale, string.Empty);
|
|
}
|
|
|
|
[Fact]
|
|
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);
|
|
}
|
|
}
|
|
}
|