Make some classes internal + chnage some files to file-scoped namespaces

This commit is contained in:
Stef Heyenrath
2023-03-22 21:57:23 +01:00
parent 9dea577da1
commit 651486f718
8 changed files with 499 additions and 505 deletions
@@ -1,13 +1,13 @@
using System; using System;
namespace WireMock.Exceptions namespace WireMock.Exceptions;
/// <summary>
/// WireMockException
/// </summary>
/// <seealso cref="Exception" />
public class WireMockException : Exception
{ {
/// <summary>
/// WireMockException
/// </summary>
/// <seealso cref="Exception" />
public class WireMockException : Exception
{
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WireMockException"/> class. /// Initializes a new instance of the <see cref="WireMockException"/> class.
/// </summary> /// </summary>
@@ -31,5 +31,4 @@ namespace WireMock.Exceptions
public WireMockException(string message, Exception inner) : base(message, inner) public WireMockException(string message, Exception inner) : base(message, inner)
{ {
} }
}
} }
@@ -3,13 +3,13 @@ using System.IO;
using WireMock.Util; using WireMock.Util;
using Stef.Validation; using Stef.Validation;
namespace WireMock.Handlers namespace WireMock.Handlers;
/// <summary>
/// Default implementation for a handler to interact with the local file system to read and write static mapping files.
/// </summary>
public class LocalFileSystemHandler : IFileSystemHandler
{ {
/// <summary>
/// Default implementation for a handler to interact with the local file system to read and write static mapping files.
/// </summary>
public class LocalFileSystemHandler : IFileSystemHandler
{
private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings"); private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings");
private static readonly string UnmatchedRequestsFolder = Path.Combine("requests", "unmatched"); private static readonly string UnmatchedRequestsFolder = Path.Combine("requests", "unmatched");
@@ -34,7 +34,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.FolderExists"/> /// <inheritdoc cref="IFileSystemHandler.FolderExists"/>
public virtual bool FolderExists(string path) public virtual bool FolderExists(string path)
{ {
Guard.NotNullOrEmpty(path, nameof(path)); Guard.NotNullOrEmpty(path);
return Directory.Exists(path); return Directory.Exists(path);
} }
@@ -42,7 +42,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.CreateFolder"/> /// <inheritdoc cref="IFileSystemHandler.CreateFolder"/>
public virtual void CreateFolder(string path) public virtual void CreateFolder(string path)
{ {
Guard.NotNullOrEmpty(path, nameof(path)); Guard.NotNullOrEmpty(path);
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
} }
@@ -50,7 +50,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.EnumerateFiles"/> /// <inheritdoc cref="IFileSystemHandler.EnumerateFiles"/>
public virtual IEnumerable<string> EnumerateFiles(string path, bool includeSubdirectories) public virtual IEnumerable<string> EnumerateFiles(string path, bool includeSubdirectories)
{ {
Guard.NotNullOrEmpty(path, nameof(path)); Guard.NotNullOrEmpty(path);
return includeSubdirectories ? Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) : Directory.EnumerateFiles(path); return includeSubdirectories ? Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) : Directory.EnumerateFiles(path);
} }
@@ -64,7 +64,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.ReadMappingFile"/> /// <inheritdoc cref="IFileSystemHandler.ReadMappingFile"/>
public virtual string ReadMappingFile(string path) public virtual string ReadMappingFile(string path)
{ {
Guard.NotNullOrEmpty(path, nameof(path)); Guard.NotNullOrEmpty(path);
return File.ReadAllText(path); return File.ReadAllText(path);
} }
@@ -81,7 +81,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsFile"/> /// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsFile"/>
public virtual byte[] ReadResponseBodyAsFile(string path) public virtual byte[] ReadResponseBodyAsFile(string path)
{ {
Guard.NotNullOrEmpty(path, nameof(path)); Guard.NotNullOrEmpty(path);
path = PathUtils.CleanPath(path); path = PathUtils.CleanPath(path);
// If the file exists at the given path relative to the MappingsFolder, then return that. // If the file exists at the given path relative to the MappingsFolder, then return that.
// Else the path will just be as-is. // Else the path will just be as-is.
@@ -91,7 +91,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsString"/> /// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsString"/>
public virtual string ReadResponseBodyAsString(string path) public virtual string ReadResponseBodyAsString(string path)
{ {
Guard.NotNullOrEmpty(path, nameof(path)); Guard.NotNullOrEmpty(path);
path = PathUtils.CleanPath(path); path = PathUtils.CleanPath(path);
// In case the path is a filename, the path will be adjusted to the MappingFolder. // In case the path is a filename, the path will be adjusted to the MappingFolder.
// Else the path will just be as-is. // Else the path will just be as-is.
@@ -101,7 +101,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.FileExists"/> /// <inheritdoc cref="IFileSystemHandler.FileExists"/>
public virtual bool FileExists(string filename) public virtual bool FileExists(string filename)
{ {
Guard.NotNullOrEmpty(filename, nameof(filename)); Guard.NotNullOrEmpty(filename);
return File.Exists(AdjustPathForMappingFolder(filename)); return File.Exists(AdjustPathForMappingFolder(filename));
} }
@@ -109,8 +109,8 @@ namespace WireMock.Handlers
/// <inheritdoc /> /// <inheritdoc />
public virtual void WriteFile(string filename, byte[] bytes) public virtual void WriteFile(string filename, byte[] bytes)
{ {
Guard.NotNullOrEmpty(filename, nameof(filename)); Guard.NotNullOrEmpty(filename);
Guard.NotNull(bytes, nameof(bytes)); Guard.NotNull(bytes);
File.WriteAllBytes(AdjustPathForMappingFolder(filename), bytes); File.WriteAllBytes(AdjustPathForMappingFolder(filename), bytes);
} }
@@ -128,7 +128,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/> /// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
public virtual void DeleteFile(string filename) public virtual void DeleteFile(string filename)
{ {
Guard.NotNullOrEmpty(filename, nameof(filename)); Guard.NotNullOrEmpty(filename);
File.Delete(AdjustPathForMappingFolder(filename)); File.Delete(AdjustPathForMappingFolder(filename));
} }
@@ -136,7 +136,7 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.ReadFile"/> /// <inheritdoc cref="IFileSystemHandler.ReadFile"/>
public virtual byte[] ReadFile(string filename) public virtual byte[] ReadFile(string filename)
{ {
Guard.NotNullOrEmpty(filename, nameof(filename)); Guard.NotNullOrEmpty(filename);
return File.ReadAllBytes(AdjustPathForMappingFolder(filename)); return File.ReadAllBytes(AdjustPathForMappingFolder(filename));
} }
@@ -156,8 +156,8 @@ namespace WireMock.Handlers
/// <inheritdoc cref="IFileSystemHandler.WriteUnmatchedRequest"/> /// <inheritdoc cref="IFileSystemHandler.WriteUnmatchedRequest"/>
public virtual void WriteUnmatchedRequest(string filename, string text) public virtual void WriteUnmatchedRequest(string filename, string text)
{ {
Guard.NotNullOrEmpty(filename, nameof(filename)); Guard.NotNullOrEmpty(filename);
Guard.NotNull(text, nameof(text)); Guard.NotNull(text);
var folder = GetUnmatchedRequestsFolder(); var folder = GetUnmatchedRequestsFolder();
if (!FolderExists(folder)) if (!FolderExists(folder))
@@ -177,5 +177,4 @@ namespace WireMock.Handlers
{ {
return Path.Combine(GetMappingFolder(), filename); return Path.Combine(GetMappingFolder(), filename);
} }
}
} }
@@ -1,6 +1,5 @@
using System.Net.Http.Headers; using System.Net.Http.Headers;
using AnyOfTypes; using AnyOfTypes;
using JetBrains.Annotations;
using WireMock.Models; using WireMock.Models;
namespace WireMock.Matchers; namespace WireMock.Matchers;
+6 -7
View File
@@ -1,12 +1,12 @@
using System; using System;
namespace WireMock.Models namespace WireMock.Models;
/// <summary>
/// TimeSettingsModel: Start, End and TTL
/// </summary>
public class TimeSettings : ITimeSettings
{ {
/// <summary>
/// TimeSettingsModel: Start, End and TTL
/// </summary>
public class TimeSettings : ITimeSettings
{
/// <inheritdoc /> /// <inheritdoc />
public DateTime? Start { get; set; } public DateTime? Start { get; set; }
@@ -15,5 +15,4 @@ namespace WireMock.Models
/// <inheritdoc /> /// <inheritdoc />
public int? TTL { get; set; } public int? TTL { get; set; }
}
} }
+1 -1
View File
@@ -17,7 +17,7 @@ namespace WireMock.Util;
/// http://www.unicode.org/versions/corrigendum1.html /// http://www.unicode.org/versions/corrigendum1.html
/// http://www.ietf.org/rfc/rfc2279.txt /// http://www.ietf.org/rfc/rfc2279.txt
/// </summary> /// </summary>
public static class BytesEncodingUtils internal static class BytesEncodingUtils
{ {
/// <summary> /// <summary>
/// Tries the get the Encoding from an array of bytes. /// Tries the get the Encoding from an array of bytes.
@@ -1,16 +1,16 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
namespace WireMock.Util namespace WireMock.Util;
/// <summary>
/// A special Collection that overrides methods of <see cref="ObservableCollection{T}"/> to make them thread safe.
/// </summary>
/// <typeparam name="T">The type of elements in the collection.</typeparam>
/// <inheritdoc cref="ObservableCollection{T}" />
internal class ConcurrentObservableCollection<T> : ObservableCollection<T>
{ {
/// <summary>
/// A special Collection that overrides methods of <see cref="ObservableCollection{T}"/> to make them thread safe.
/// </summary>
/// <typeparam name="T">The type of elements in the collection.</typeparam>
/// <inheritdoc cref="ObservableCollection{T}" />
internal class ConcurrentObservableCollection<T> : ObservableCollection<T>
{
private readonly object _lockObject = new object(); private readonly object _lockObject = new object();
/// <summary> /// <summary>
@@ -82,5 +82,4 @@ namespace WireMock.Util
return Items.ToList(); return Items.ToList();
} }
} }
}
} }
@@ -4,14 +4,14 @@ using System.IO;
using JetBrains.Annotations; using JetBrains.Annotations;
using Stef.Validation; using Stef.Validation;
namespace WireMock.Util namespace WireMock.Util;
/// <summary>
/// An EnhancedFileSystemWatcher, which can be used to suppress duplicate events that fire on a single change to the file.
/// </summary>
/// <seealso cref="FileSystemWatcher" />
public class EnhancedFileSystemWatcher : FileSystemWatcher
{ {
/// <summary>
/// An EnhancedFileSystemWatcher, which can be used to suppress duplicate events that fire on a single change to the file.
/// </summary>
/// <seealso cref="FileSystemWatcher" />
public class EnhancedFileSystemWatcher : FileSystemWatcher
{
#region Private Members #region Private Members
// Default Watch Interval in Milliseconds // Default Watch Interval in Milliseconds
private const int DefaultWatchInterval = 100; private const int DefaultWatchInterval = 100;
@@ -250,5 +250,4 @@ namespace WireMock.Util
} }
#endregion #endregion
#endregion #endregion
}
} }
+1 -1
View File
@@ -9,7 +9,7 @@ namespace WireMock.Util;
/// <summary> /// <summary>
/// Port Utility class /// Port Utility class
/// </summary> /// </summary>
public static class PortUtils internal static class PortUtils
{ {
private static readonly Regex UrlDetailsRegex = new(@"^((?<proto>\w+)://)(?<host>[^/]+?):(?<port>\d+)\/?$", RegexOptions.Compiled); private static readonly Regex UrlDetailsRegex = new(@"^((?<proto>\w+)://)(?<host>[^/]+?):(?<port>\d+)\/?$", RegexOptions.Compiled);