test: add multiple mocks for use with testing project

This commit is contained in:
Andrew Welker
2025-08-13 22:32:59 -05:00
parent 083c270cf3
commit c2ab2f34b7
13 changed files with 1488 additions and 413 deletions

View File

@@ -5,7 +5,7 @@ using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Crestron.SimplSharp.CrestronWebSocketServer
namespace Crestron.SimplSharp.WebScripting
{
/// <summary>Mock HttpCwsServer class for HTTP web server functionality</summary>
public class HttpCwsServer : IDisposable
@@ -92,6 +92,13 @@ namespace Crestron.SimplSharp.CrestronWebSocketServer
_routes.Remove(route.ToLowerInvariant());
}
/// <summary>Unregisters a route handler</summary>
/// <param name="route">Route path to unregister</param>
public void Unregister(string route)
{
RemoveRoute(route);
}
private async Task ProcessRequestsAsync()
{
while (_listening && _httpListener != null)
@@ -243,6 +250,13 @@ namespace Crestron.SimplSharp.CrestronWebSocketServer
set => _response.StatusCode = value;
}
/// <summary>Gets or sets the status description</summary>
public string StatusDescription
{
get => _response.StatusDescription;
set => _response.StatusDescription = value;
}
/// <summary>Gets or sets the content type</summary>
public string? ContentType
{
@@ -287,6 +301,19 @@ namespace Crestron.SimplSharp.CrestronWebSocketServer
{
OutputStream.Write(buffer, offset, count);
}
/// <summary>Ends the response</summary>
public void End()
{
try
{
_response.Close();
}
catch (Exception)
{
// Ignore exceptions during close
}
}
}
/// <summary>Interface for HTTP request handlers</summary>