Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.Test/ServiceHost/LoggerTests.cs
Benjamin Russell 41198e9357 Adding sr.strings file and removing hard-coded strings (#52)
* Strings sweep for connection service

* String sweep for credentials service

* String sweep for hosting

* String sweep for query execution service

* String sweep for Workspace service

* Renaming utility namespace to match standards

Renaming Microsoft.SqlTools.EditorServices.Utility to
Microsoft.SqlTools.ServiceLayer.Utility to match the naming changes done a
while back. Also renaming them on the files that use them

* Namespace change on reliable connection

* Adding the new resx and designer files

* Final bug fixes for srgen

Fixing flakey moq package name

* Removing todo as per @kevcunnane

* Adding using statements as per @llali's comment

* Fixing issues from broken unit tests

Note: This feature contains changes that will break the contract for
saving as CSV and JSON. On success, null is returned as a message instead
of "Success". Changes will be made to the vscode component to handle this
change.
2016-09-16 16:18:25 -07:00

63 lines
2.1 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;
using System.IO;
using System.Linq;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
{
/// <summary>
/// Logger test cases
/// </summary>
public class LoggerTests
{
/// <summary>
/// Test to verify that the logger initialization is generating a valid file
/// </summary>
[Fact]
public void LoggerDefaultFile()
{
// delete any existing log files from the current directory
Directory.GetFiles(Directory.GetCurrentDirectory())
.Where(fileName
=> fileName.Contains("sqltools_")
&& fileName.EndsWith(".log", StringComparison.OrdinalIgnoreCase))
.ToList()
.ForEach(File.Delete);
// initialize the logger
Logger.Initialize(
logFilePath: Path.Combine(Directory.GetCurrentDirectory(), "sqltools"),
minimumLogLevel: LogLevel.Verbose);
// close the logger
Logger.Close();
// find the name of the new log file
string logFileName = Directory.GetFiles(Directory.GetCurrentDirectory())
.SingleOrDefault(fileName =>
fileName.Contains("sqltools_")
&& fileName.EndsWith(".log", StringComparison.OrdinalIgnoreCase));
// validate the log file was created with desired name
Assert.True(!string.IsNullOrWhiteSpace(logFileName));
if (!string.IsNullOrWhiteSpace(logFileName))
{
Assert.True(logFileName.Length > "sqltools_.log".Length);
Assert.True(File.Exists(logFileName));
// delete the test log file
if (File.Exists(logFileName))
{
File.Delete(logFileName);
}
}
}
}
}