From 67e535ae64ed64062a6637c40d5ac69924ab605c Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Sun, 14 Jul 2024 11:48:55 -0400 Subject: [PATCH] cleaned up all warnings closes #49 closes #47 --- .../WebLogger.Crestron.csproj | 1 + .../WebLogger.Crestron/WebLoggerExtensions.cs | 8 +- .../WebLogger.Crestron/WebLoggerHttpServer.cs | 12 +- .../IncrementalCommandStoreGenerator.cs | 43 ++--- .../WebLogger.Generators.csproj | 13 +- .../Commands/LoggerLevelCommand.cs | 21 +++ .../Formatting/CustomDateFormatter.cs | 2 +- .../Formatting/IRenderMessages.cs | 27 +++ .../Formatting/RenderHtml.cs | 38 +++-- .../Formatting/RenderSinkTextColor.cs | 15 +- .../WebLogger.Serilog.csproj | 1 + source/WebLogger.Serilog/WebLoggerSink.cs | 9 +- source/WebLogger/Render/HtmlElementOptions.cs | 12 ++ source/WebLogger/Utilities/HtmlInformation.cs | 22 +-- source/WebLogger/WebLogger.csproj | 1 + .../Logger/WebLoggerTests.cs | 161 +++++++++--------- 16 files changed, 222 insertions(+), 164 deletions(-) diff --git a/source/WebLogger.Crestron/WebLogger.Crestron.csproj b/source/WebLogger.Crestron/WebLogger.Crestron.csproj index 479d7bd..6dce3ce 100644 --- a/source/WebLogger.Crestron/WebLogger.Crestron.csproj +++ b/source/WebLogger.Crestron/WebLogger.Crestron.csproj @@ -2,6 +2,7 @@ True + 9 WebLogger Crestron Console Provides a web socket servers used to send/receive console communications from an embedded HTML user interface to a application. diff --git a/source/WebLogger.Crestron/WebLoggerExtensions.cs b/source/WebLogger.Crestron/WebLoggerExtensions.cs index 69377a9..4162b47 100644 --- a/source/WebLogger.Crestron/WebLoggerExtensions.cs +++ b/source/WebLogger.Crestron/WebLoggerExtensions.cs @@ -1,4 +1,8 @@ -using System.Reflection; +#if NET6_0_OR_GREATER +#pragma warning disable CA1806 +#endif + +using System.Reflection; using WebLogger.Utilities; namespace WebLogger.Crestron @@ -17,7 +21,7 @@ public static class WebLoggerExtensions /// public static IWebLogger ServeWebLoggerHtml(this IWebLogger logger, int httpSeverPort) { - var webPageServer = new WebLoggerHttpServer( + new WebLoggerHttpServer( port: httpSeverPort, directory: logger.HtmlDirectory); diff --git a/source/WebLogger.Crestron/WebLoggerHttpServer.cs b/source/WebLogger.Crestron/WebLoggerHttpServer.cs index ada1d3f..da1b279 100644 --- a/source/WebLogger.Crestron/WebLoggerHttpServer.cs +++ b/source/WebLogger.Crestron/WebLoggerHttpServer.cs @@ -1,4 +1,7 @@ -using Crestron.SimplSharp; + +#pragma warning disable IDE1006 + +using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.Net.Http; using System; @@ -17,7 +20,8 @@ public sealed class WebLoggerHttpServer : IDisposable /// /// The extension content types /// - public static Dictionary ExtensionContentTypes; + private static Dictionary _extensionContentTypes; + /// /// Gets the type of the content. /// @@ -25,7 +29,7 @@ public sealed class WebLoggerHttpServer : IDisposable /// System.String. public static string GetContentType(string extension) { - var type = ExtensionContentTypes.TryGetValue(extension, out var contentType) ? contentType : "text/plain"; + var type = _extensionContentTypes.TryGetValue(extension, out var contentType) ? contentType : "text/plain"; return type; } @@ -40,7 +44,7 @@ public static string GetContentType(string extension) /// File Directory to Serve public WebLoggerHttpServer(int port, string directory) { - ExtensionContentTypes = new Dictionary + _extensionContentTypes = new Dictionary { { ".html", "text/html" }, { ".json", "application/json" }, diff --git a/source/WebLogger.Generators/IncrementalCommandStoreGenerator.cs b/source/WebLogger.Generators/IncrementalCommandStoreGenerator.cs index 5725dba..1209ff1 100644 --- a/source/WebLogger.Generators/IncrementalCommandStoreGenerator.cs +++ b/source/WebLogger.Generators/IncrementalCommandStoreGenerator.cs @@ -1,4 +1,13 @@ -using Microsoft.CodeAnalysis; +#pragma warning disable RS1024 +#pragma warning disable IDE0079 + +#if NET6_0_OR_GREATER +#pragma warning disable CA1067 +#else +#pragma warning disable IDE1041 +#endif + +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using System; @@ -16,8 +25,6 @@ public class IncrementalCommandStoreGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { - //context.RegisterPostInitializationOutput(PostInitializationCallback); - IncrementalValuesProvider provider = context.SyntaxProvider .CreateSyntaxProvider(SyntacticPredicate, SemanticTransform) .Where(static ((INamedTypeSymbol, Dictionary>)? type) => type.HasValue) @@ -27,23 +34,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterSourceOutput(provider, Execute); } - private static void PostInitializationCallback(IncrementalGeneratorPostInitializationContext context) - { - - //context.AddSource(Constants.CommandStoreAttributeFile, Constants.CommandStoreAttributeValue); - //context.AddSource(Constants.TargetCommandAttributeFile, Constants.TargetCommandAttributeValue); - //context.AddSource(Constants.StoredCommandsInterfaceExtensionsFile, Constants.StoredCommandsInterfaceExtensionsValue); - //context.AddSource(Constants.StoredCommandsInterfaceFile, Constants.StoredCommandsInterfaceValue); - } - private static bool SyntacticPredicate(SyntaxNode node, CancellationToken cancellation) { - if (node is not AttributeSyntax { Name: IdentifierNameSyntax { Identifier: { Text: "CommandStore" } } } attribute) - { - return false; - } - - return true; + return node is AttributeSyntax { Name: IdentifierNameSyntax { Identifier: { Text: "CommandStore" } } }; } private static (INamedTypeSymbol, Dictionary>)? SemanticTransform(GeneratorSyntaxContext context, CancellationToken cancellation) @@ -58,7 +51,7 @@ private static (INamedTypeSymbol, Dictionary>)? Sema return null; // 2. Ensure the class does not already implement the command store and ensure the attribute is applied - ISymbol typeSymbol = context.SemanticModel.GetDeclaredSymbol(candidate); + ISymbol typeSymbol = context.SemanticModel.GetDeclaredSymbol(candidate, cancellation); if (typeSymbol is not INamedTypeSymbol type) return null; @@ -279,14 +272,14 @@ public bool Equals(TargetClassCaptureContext other) /// internal class TargetClassCaptureContextComparer : IEqualityComparer { - private static readonly Lazy _lazy = new(() => new TargetClassCaptureContextComparer()); - public static TargetClassCaptureContextComparer Instance => _lazy.Value; + private static readonly Lazy Lazy = new(() => new TargetClassCaptureContextComparer()); + public static TargetClassCaptureContextComparer Instance => Lazy.Value; public bool Equals(TargetClassCaptureContext x, TargetClassCaptureContext y) { if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null)) return false; - if (ReferenceEquals(y, null)) return false; + if (x is null) return false; + if (y is null) return false; if (x.GetType() != y.GetType()) return false; return x.Equals(y); @@ -343,11 +336,11 @@ private static void Execute(SourceProductionContext context, TargetClassCaptureC int i = 1; foreach (var property in method.PropertyValues) { - methods.Append("\"").Append(i == 1? property.RemoveWhiteSpace().ToUpper() : property).Append("\""); + methods.Append('\\').Append(i == 1? property.RemoveWhiteSpace().ToUpper() : property).Append('\\'); if (i != 3) { - methods.Append(","); + methods.Append(','); } i++; } diff --git a/source/WebLogger.Generators/WebLogger.Generators.csproj b/source/WebLogger.Generators/WebLogger.Generators.csproj index ed81cdc..fcd2637 100644 --- a/source/WebLogger.Generators/WebLogger.Generators.csproj +++ b/source/WebLogger.Generators/WebLogger.Generators.csproj @@ -6,18 +6,9 @@ True WebLogger Command Source Generators Source generators used to created custom CLI commands used by the WebLogger console. Simply tag your handler methods with a specific attribute and your command will be generated. - - - - True - \ - - - True - \ - - + CS1591 + diff --git a/source/WebLogger.Serilog/Commands/LoggerLevelCommand.cs b/source/WebLogger.Serilog/Commands/LoggerLevelCommand.cs index 99472b8..834bf42 100644 --- a/source/WebLogger.Serilog/Commands/LoggerLevelCommand.cs +++ b/source/WebLogger.Serilog/Commands/LoggerLevelCommand.cs @@ -5,20 +5,41 @@ namespace WebLogger { + /// + /// Sets the serilog log level + /// public class LoggerLevelCommand : IWebLoggerCommand { + + /// + /// Log level switcher + /// public LoggingLevelSwitch LoggingLevelSwitch; + /// + /// Creates the new command + /// + /// with a provided level public LoggerLevelCommand(LogEventLevel level) { LoggingLevelSwitch = new LoggingLevelSwitch(level); } + /// public string Command => "SERILOGLEVEL"; + /// public string Description => "Changes the Verbosity"; + /// public string Help => "SerilogLevel [LoggingLevel] (Values: Debug, Verbose, Information, Warning, Error, Fatal)"; + /// public Func, ICommandResponse> CommandHandler => Handler; + /// + /// Handles the data parameters passed from the command. + /// + /// The command + /// The argument list + /// public ICommandResponse Handler(string command, List args) { if (args == null || args.Count == 0) diff --git a/source/WebLogger.Serilog/Formatting/CustomDateFormatter.cs b/source/WebLogger.Serilog/Formatting/CustomDateFormatter.cs index e08e58e..c489e93 100644 --- a/source/WebLogger.Serilog/Formatting/CustomDateFormatter.cs +++ b/source/WebLogger.Serilog/Formatting/CustomDateFormatter.cs @@ -35,7 +35,7 @@ public object GetFormat(Type formatType) if (formatType != typeof(DateTimeFormatInfo)) return this._basedOn.GetFormat(formatType); - if (!(_basedOn.GetFormat(formatType) is DateTimeFormatInfo basedOnFormatInfo)) + if (_basedOn.GetFormat(formatType) is not DateTimeFormatInfo basedOnFormatInfo) return null; var dateFormatInfo = (DateTimeFormatInfo)basedOnFormatInfo.Clone(); diff --git a/source/WebLogger.Serilog/Formatting/IRenderMessages.cs b/source/WebLogger.Serilog/Formatting/IRenderMessages.cs index d8c57af..05b19eb 100644 --- a/source/WebLogger.Serilog/Formatting/IRenderMessages.cs +++ b/source/WebLogger.Serilog/Formatting/IRenderMessages.cs @@ -3,11 +3,38 @@ namespace WebLogger { + /// + /// Renders a message to the weblogger + /// public interface IRenderMessages { + /// + /// renders verbose messages + /// + /// + /// + /// string RenderVerbose(LogEvent logEvent, IFormatProvider formatProvider); + /// + /// renders an Information messages + /// + /// + /// + /// string RenderInformation(LogEvent logEvent, IFormatProvider formatProvider); + /// + /// renders warnings + /// + /// + /// + /// string RenderWarning(LogEvent logEvent, IFormatProvider formatProvider); + /// + /// renders error messages + /// + /// + /// + /// string RenderError(LogEvent logEvent, IFormatProvider formatProvider); } } \ No newline at end of file diff --git a/source/WebLogger.Serilog/Formatting/RenderHtml.cs b/source/WebLogger.Serilog/Formatting/RenderHtml.cs index 7a19ff9..4756a1b 100644 --- a/source/WebLogger.Serilog/Formatting/RenderHtml.cs +++ b/source/WebLogger.Serilog/Formatting/RenderHtml.cs @@ -6,50 +6,49 @@ namespace WebLogger { + /// + /// Renders the output as an HTML element + /// public sealed class RenderSinkHtml : IRenderMessages { - private const string _styleyleHeader = "padding:10px;margin:10px;font-weight:bold;background-color:"; - private const string _styleyleSuffix = ";"; + + private const string StyleHeader = "padding:10px;margin:10px;font-weight:bold;background-color:"; + private const char StyleSuffix = ';'; private static HtmlElement CreatePrefix(LogEvent logEvent, Color color) { - var styles = new StringBuilder(_styleyleHeader) + var styles = new StringBuilder(StyleHeader) .RenderColor(color) - .Append(_styleyleSuffix); + .Append(StyleSuffix); var builder = new StringBuilder(logEvent.Timestamp.ToString("HH:mm:ss")) - .Append(" ") + .Append(' ') .Append(logEvent.Level.GetLevel()); return HtmlElement.Span(builder.ToString(), new HtmlElementOptions(additionalStyles: styles.ToString())); } - private string RenderMessage(LogEvent logEvent, IFormatProvider formatProvider, Color color) - { - return HtmlElement.Div(CreatePrefix(logEvent, color) - .Append(HtmlElement.Span(logEvent.RenderMessage(formatProvider)))) - .Render(); - } - + /// public string RenderVerbose(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Verbose); return RenderMessage(logEvent, formatProvider, color); } - + /// public string RenderInformation(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Verbose); return RenderMessage(logEvent, formatProvider, color); } + /// public string RenderWarning(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Warning); return RenderMessage(logEvent, formatProvider, color); } - + /// public string RenderError(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Error); @@ -59,14 +58,14 @@ public string RenderError(LogEvent logEvent, IFormatProvider formatProvider) return CreatePrefix(logEvent, color) .Append(logEvent.RenderMessage(formatProvider)) .Append(HtmlElement.Span(", Exception: ")) - .Append(RenderExceptions(logEvent.Exception, color)) + .Append(RenderExceptions(logEvent.Exception)) .Render(); } return RenderMessage(logEvent, formatProvider, color); } - private static HtmlElement RenderExceptions(Exception exception, Color color) + private static HtmlElement RenderExceptions(Exception exception) { var builder = new StringBuilder("background-color:") .RenderColor(Color.DarkRed) @@ -77,5 +76,12 @@ private static HtmlElement RenderExceptions(Exception exception, Color color) HtmlElement.TableData(exception.ToString(), new HtmlElementOptions(additionalStyles: builder.ToString())) )); } + + private static string RenderMessage(LogEvent logEvent, IFormatProvider formatProvider, Color color) + { + return HtmlElement.Div(CreatePrefix(logEvent, color) + .Append(HtmlElement.Span(logEvent.RenderMessage(formatProvider)))) + .Render(); + } } } \ No newline at end of file diff --git a/source/WebLogger.Serilog/Formatting/RenderSinkTextColor.cs b/source/WebLogger.Serilog/Formatting/RenderSinkTextColor.cs index e7f4533..62de8f3 100644 --- a/source/WebLogger.Serilog/Formatting/RenderSinkTextColor.cs +++ b/source/WebLogger.Serilog/Formatting/RenderSinkTextColor.cs @@ -6,19 +6,23 @@ namespace WebLogger { + /// + /// Generates colors used for the sink + /// public sealed class RenderSinkTextColor : IRenderMessages { private static HtmlElement CreatePrefix(LogEvent logEvent, Color color) { var builder = new StringBuilder("[") .Append(logEvent.Timestamp.ToString("HH:mm:ss")) - .Append(" ") + .Append(' ') .Append(logEvent.Level.GetLevel()) .Append("] "); return HtmlElement.Span(builder.ToString(), color); } + /// public string RenderVerbose(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Verbose); @@ -27,7 +31,7 @@ public string RenderVerbose(LogEvent logEvent, IFormatProvider formatProvider) .Append(logEvent.RenderMessage(formatProvider)) .Render(); } - + /// public string RenderInformation(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Verbose); @@ -36,6 +40,7 @@ public string RenderInformation(LogEvent logEvent, IFormatProvider formatProvide .Append(logEvent.RenderMessage(formatProvider)) .Render(); } + /// public string RenderWarning(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Warning); @@ -44,7 +49,7 @@ public string RenderWarning(LogEvent logEvent, IFormatProvider formatProvider) .Append(logEvent.RenderMessage(formatProvider)) .Render(); } - + /// public string RenderError(LogEvent logEvent, IFormatProvider formatProvider) { var color = ColorFactory.Instance.GetColor(Severity.Error); @@ -54,7 +59,7 @@ public string RenderError(LogEvent logEvent, IFormatProvider formatProvider) return CreatePrefix(logEvent, color) .Append(logEvent.RenderMessage(formatProvider)) .Append(HtmlElement.Span(", Exception: ")) - .Append(RenderExceptions(logEvent.Exception, color)) + .Append(RenderExceptions(logEvent.Exception)) .Render(); } @@ -63,7 +68,7 @@ public string RenderError(LogEvent logEvent, IFormatProvider formatProvider) .Render(); } - private static HtmlElement RenderExceptions(Exception exception, Color color) + private static HtmlElement RenderExceptions(Exception exception) { var builder = new StringBuilder("background-color:") .RenderColor(Color.DarkRed) diff --git a/source/WebLogger.Serilog/WebLogger.Serilog.csproj b/source/WebLogger.Serilog/WebLogger.Serilog.csproj index edd0386..ddada63 100644 --- a/source/WebLogger.Serilog/WebLogger.Serilog.csproj +++ b/source/WebLogger.Serilog/WebLogger.Serilog.csproj @@ -2,6 +2,7 @@ WebLogger + 9 True WebLogger Serilog Sink A serilog Sink implementation of the weblogger providing a web socket servers used to send/receive console communications from an embedded HTML user interface to a application. diff --git a/source/WebLogger.Serilog/WebLoggerSink.cs b/source/WebLogger.Serilog/WebLoggerSink.cs index c7bc6ca..c0659da 100644 --- a/source/WebLogger.Serilog/WebLoggerSink.cs +++ b/source/WebLogger.Serilog/WebLoggerSink.cs @@ -24,6 +24,7 @@ public sealed class WebLoggerSink : ILogEventSink, IDisposable /// provides the weblogger factory configuration options /// the action provides access to the logger after construction and can be used to provide commands /// The format provider. + /// an optional render you can use to override the default HTML provider public WebLoggerSink(Action options, Action logger = default, IFormatProvider formatProvider = default, IRenderMessages renderer = default) { _logger = WebLoggerFactory.CreateWebLogger(options); @@ -60,7 +61,7 @@ public void Emit(LogEvent logEvent) break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(logEvent)); } } @@ -86,12 +87,8 @@ public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); + // ReSharper disable once GCSuppressFinalizeForTypeWithoutDestructor GC.SuppressFinalize(this); } - - ~WebLoggerSink() - { - - } } } diff --git a/source/WebLogger/Render/HtmlElementOptions.cs b/source/WebLogger/Render/HtmlElementOptions.cs index af56666..9dfab58 100644 --- a/source/WebLogger/Render/HtmlElementOptions.cs +++ b/source/WebLogger/Render/HtmlElementOptions.cs @@ -31,6 +31,7 @@ public sealed class HtmlElementOptions /// Color /// Font Attribute /// Style Attribute + /// Added styles to the element public HtmlElementOptions(Color color = default, string fontFamily = default, int? fontSize = null, string additionalStyles = null) { Color = color; @@ -39,7 +40,18 @@ public HtmlElementOptions(Color color = default, string fontFamily = default, in AdditionalStyles = additionalStyles; } + /// + /// Converts a color to an element + /// + /// the color + /// the element public static implicit operator HtmlElementOptions(Color color) => new HtmlElementOptions(color); + + /// + /// Converts a element to a color + /// + /// the color + /// the color public static implicit operator Color(HtmlElementOptions options) => options.Color; } } \ No newline at end of file diff --git a/source/WebLogger/Utilities/HtmlInformation.cs b/source/WebLogger/Utilities/HtmlInformation.cs index 5726c5e..4491f32 100644 --- a/source/WebLogger/Utilities/HtmlInformation.cs +++ b/source/WebLogger/Utilities/HtmlInformation.cs @@ -33,14 +33,12 @@ internal static string ReadInformationFile(string htmlDirectory) try { - using (var reader = new StreamReader(path)) - { - var file = reader.ReadToEnd(); + using var reader = new StreamReader(path); + var file = reader.ReadToEnd(); - return file; - } + return file; } - catch (IOException e) + catch (IOException) { return string.Empty; } @@ -100,15 +98,13 @@ internal static void CreateInfoFile(string htmlDirectory) if(!Directory.Exists(htmlDirectory)) Directory.CreateDirectory(htmlDirectory); - using (var writer = new FileStream(path, FileMode.Create)) - { - var builder = new StringBuilder("#VERSION:") - .Append(Assembly.GetAssembly(typeof(IAssemblyMarker)).GetName().Version); + using var writer = new FileStream(path, FileMode.Create); + var builder = new StringBuilder("#VERSION:") + .Append(Assembly.GetAssembly(typeof(IAssemblyMarker))!.GetName().Version); - var bytes = Encoding.UTF8.GetBytes(builder.ToString()); + var bytes = Encoding.UTF8.GetBytes(builder.ToString()); - writer.Write(bytes, 0, bytes.Length); - } + writer.Write(bytes, 0, bytes.Length); } catch (IOException) { diff --git a/source/WebLogger/WebLogger.csproj b/source/WebLogger/WebLogger.csproj index 7b5d1cf..a1c9b76 100644 --- a/source/WebLogger/WebLogger.csproj +++ b/source/WebLogger/WebLogger.csproj @@ -2,6 +2,7 @@ True + 9 WebLogger Console Provides a web socket servers used to send/receive console communications from an embedded HTML user interface to a application. This was originally created for use on Crestron VC4 but has since been migrated to netstandard for use in native runtime application. diff --git a/tests/WebLogger_UnitTests/Logger/WebLoggerTests.cs b/tests/WebLogger_UnitTests/Logger/WebLoggerTests.cs index 1de146f..f6d3305 100644 --- a/tests/WebLogger_UnitTests/Logger/WebLoggerTests.cs +++ b/tests/WebLogger_UnitTests/Logger/WebLoggerTests.cs @@ -1,115 +1,114 @@ using System.Net.Sockets; -namespace WebLogger_UnitTests.Logger +namespace WebLogger_UnitTests.Logger; + +[TestClass] +public class WebLoggerTests { - [TestClass] - public class WebLoggerTests - { - [TestMethod] - public void WebLogger_Starts_WebSocketServer() - { - var logger = WebLoggerFactory.CreateWebLogger(); + [TestMethod] + public void WebLogger_Starts_WebSocketServer() + { + var logger = WebLoggerFactory.CreateWebLogger(); - logger.Start(); - Assert.IsTrue(logger.IsRunning); + logger.Start(); + Assert.IsTrue(logger.IsRunning); - var client = new TcpClient(); - client.Connect("127.0.0.1", 54321); - Assert.IsTrue(client.Connected); + var client = new TcpClient(); + client.Connect("127.0.0.1", 54321); + Assert.IsTrue(client.Connected); - client.Close(); - logger.Stop(); - logger.Dispose(); - } + client.Close(); + logger.Stop(); + logger.Dispose(); + } - [TestMethod] - public void WebLogger_StartsAndStops_WebSocketServer() - { - var logger = WebLoggerFactory.CreateWebLogger(); - logger.Start(); - Assert.IsTrue(logger.IsRunning); + [TestMethod] + public void WebLogger_StartsAndStops_WebSocketServer() + { + var logger = WebLoggerFactory.CreateWebLogger(); + logger.Start(); + Assert.IsTrue(logger.IsRunning); - var client = new TcpClient(); - client.Connect("127.0.0.1", 54321); - Assert.IsTrue(client.Connected); + var client = new TcpClient(); + client.Connect("127.0.0.1", 54321); + Assert.IsTrue(client.Connected); - client.Close(); - logger.Stop(); - logger.Dispose(); + client.Close(); + logger.Stop(); + logger.Dispose(); - Assert.IsFalse(client.Connected); - Assert.IsFalse(logger.IsRunning); + Assert.IsFalse(client.Connected); + Assert.IsFalse(logger.IsRunning); - } + } - [TestMethod] - public void WebLogger_Dispose_StopsWebSocketServer() - { - var logger = WebLoggerFactory.CreateWebLogger(); + [TestMethod] + public void WebLogger_Dispose_StopsWebSocketServer() + { + var logger = WebLoggerFactory.CreateWebLogger(); - logger.Start(); - Assert.IsTrue(logger.IsRunning); + logger.Start(); + Assert.IsTrue(logger.IsRunning); - var client = new TcpClient(); - client.Connect("127.0.0.1", 54321); - Assert.IsTrue(client.Connected); + var client = new TcpClient(); + client.Connect("127.0.0.1", 54321); + Assert.IsTrue(client.Connected); - client.Close(); - logger.Dispose(); + client.Close(); + logger.Dispose(); - Assert.IsFalse(logger.IsRunning); - } + Assert.IsFalse(logger.IsRunning); + } - [TestMethod] - public void WebLogger_ExtractsEmbeddedWebpage_WhenNoPageIsFound() + [TestMethod] + public void WebLogger_ExtractsEmbeddedWebpage_WhenNoPageIsFound() + { + var logger = WebLoggerFactory.CreateWebLogger(options => { - var logger = WebLoggerFactory.CreateWebLogger(options => - { - options.DestinationWebpageDirectory = ConstantValues.DefaultHtmlDirectory; - }); + options.DestinationWebpageDirectory = ConstantValues.DefaultHtmlDirectory; + }); - if(Directory.Exists(ConstantValues.DefaultHtmlDirectory)) - Directory.Delete(ConstantValues.DefaultHtmlDirectory, true); + if(Directory.Exists(ConstantValues.DefaultHtmlDirectory)) + Directory.Delete(ConstantValues.DefaultHtmlDirectory, true); - Assert.IsFalse(Directory.Exists(ConstantValues.DefaultHtmlDirectory)); + Assert.IsFalse(Directory.Exists(ConstantValues.DefaultHtmlDirectory)); - logger.Start(); + logger.Start(); - Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html"))); - Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "console.js"))); - Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "style.css"))); + Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html"))); + Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "console.js"))); + Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "style.css"))); - var info = new FileInfo(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html")); + var info = new FileInfo(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html")); - var dif= info.CreationTime - DateTime.Now; + var dif= info.CreationTime - DateTime.Now; - Assert.IsTrue(dif.Seconds < 3); - } + Assert.IsTrue(dif.Seconds < 3); + } - //[TestMethod] - //public void WebLogger_DoesNotExtractEmbeddedWebpage_WhenPageIsFound() - //{ - // var logger = WebLoggerFactory.CreateWebLogger(options => - // { - // options.DestinationWebpageDirectory = ConstantValues.DefaultHtmlDirectory; - // }); + //[TestMethod] + //public void WebLogger_DoesNotExtractEmbeddedWebpage_WhenPageIsFound() + //{ + // var logger = WebLoggerFactory.CreateWebLogger(options => + // { + // options.DestinationWebpageDirectory = ConstantValues.DefaultHtmlDirectory; + // }); - // logger.Start(); - // Path.Combine(ConstantValues.DefaultHtmlDirectory, "console.js"); + // logger.Start(); + // Path.Combine(ConstantValues.DefaultHtmlDirectory, "console.js"); - // Assert.IsTrue(Directory.Exists(ConstantValues.DefaultHtmlDirectory)); + // Assert.IsTrue(Directory.Exists(ConstantValues.DefaultHtmlDirectory)); - // Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html"))); - // Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "console.js"))); - // Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "style.css"))); + // Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html"))); + // Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "console.js"))); + // Assert.IsTrue(File.Exists(Path.Combine(ConstantValues.DefaultHtmlDirectory, "style.css"))); - // var info = new FileInfo(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html")); + // var info = new FileInfo(Path.Combine(ConstantValues.DefaultHtmlDirectory, "index.html")); - // var dif= DateTime.Now - info.CreationTime; + // var dif= DateTime.Now - info.CreationTime; - // Assert.IsTrue(dif.Milliseconds > 20); - //} - } -} + // Assert.IsTrue(dif.Milliseconds > 20); + //} +} \ No newline at end of file