Skip to content

Commit

Permalink
General project cleanup (#108)
Browse files Browse the repository at this point in the history
* Added missing xml comments

* Make abstract base class constructors protected
  • Loading branch information
mattherman authored Feb 8, 2023
1 parent a2cfcfd commit 25bc398
Show file tree
Hide file tree
Showing 61 changed files with 676 additions and 167 deletions.
4 changes: 4 additions & 0 deletions MbDotNet/Enums/Method.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma warning disable CS1591
namespace MbDotNet.Enums
{
/// <summary>
/// HTTP Method
/// </summary>
public enum Method
{
Get,
Expand Down
4 changes: 4 additions & 0 deletions MbDotNet/Enums/Protocol.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma warning disable CS1591
namespace MbDotNet.Enums
{
/// <summary>
/// Supported network protocols for defining imposters
/// </summary>
public enum Protocol
{
Http,
Expand Down
4 changes: 4 additions & 0 deletions MbDotNet/Enums/ProxyMode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Runtime.Serialization;
#pragma warning disable CS1591

namespace MbDotNet.Enums
{
/// <summary>
/// Mode for proxy responses
/// </summary>
public enum ProxyMode
{
[EnumMember(Value = "proxyOnce")]
Expand Down
4 changes: 4 additions & 0 deletions MbDotNet/Enums/TcpMode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma warning disable CS1591
namespace MbDotNet.Enums
{
/// <summary>
/// Defines the encoding used for request and response strings in TCP imposters
/// </summary>
public enum TcpMode
{
Text,
Expand Down
3 changes: 3 additions & 0 deletions MbDotNet/Exceptions/ImposterNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace MbDotNet.Exceptions
[Serializable]
public class ImposterNotFoundException : MountebankException
{
/// <inheritdoc />
public ImposterNotFoundException(string message) : base(message) { }

/// <inheritdoc />
public ImposterNotFoundException(string message, Exception innerException) : base(message, innerException) { }
}
}
3 changes: 3 additions & 0 deletions MbDotNet/Exceptions/InvalidProtocolException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace MbDotNet.Exceptions
[Serializable]
public class InvalidProtocolException : MountebankException
{
/// <inheritdoc />
public InvalidProtocolException(string message) : base(message) { }

/// <inheritdoc />
public InvalidProtocolException(string message, Exception innerException) : base(message, innerException) { }
}
}
3 changes: 3 additions & 0 deletions MbDotNet/Exceptions/MountebankException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace MbDotNet.Exceptions
[Serializable]
public class MountebankException : Exception
{
/// <inheritdoc />
public MountebankException(string message) : base(message) { }

/// <inheritdoc />
public MountebankException(string message, Exception innerException) : base(message, innerException) { }
}
}
39 changes: 24 additions & 15 deletions MbDotNet/IClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using MbDotNet.Enums;
Expand All @@ -9,25 +10,26 @@

namespace MbDotNet
{
/// <summary>
/// A client for interacting with the Mountebank API
/// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "CORS is an abbreviation")]
public interface IClient
{
/// <summary>
/// A collection of all of the current imposters. The imposters in this
/// collection may or may not have been added to mountebank. See IImposter.PendingSubmission
/// for more information.
/// collection may or may not have been submitted to mountebank.
/// </summary>
ICollection<Imposter> Imposters { get; }


/// <summary>
/// Get the entry hypermedia
/// </summary>
/// <returns>The Home object which contains entry hypermedia</returns>

Task<Home> GetEntryHypermediaAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Get the logs
/// Get the Mountebank server logs
/// </summary>
/// <returns>The list of logs</returns>
Task<IEnumerable<Log>> GetLogsAsync(CancellationToken cancellationToken = default);
Expand All @@ -41,7 +43,7 @@ public interface IClient
/// The port the imposter will be set up to receive requests on, or null to allow
/// Mountebank to set the port.
/// </param>
/// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param>
/// <param name="name">The name the imposter will receive, useful for debugging/logging purposes</param>
/// <param name="recordRequests">
/// Enables recording requests to use the imposter as a mock. See
/// <see href="http://www.mbtest.org/docs/api/mocks">here</see> for more details on Mountebank
Expand All @@ -52,7 +54,7 @@ public interface IClient
/// <returns>The newly created imposter</returns>
HttpImposter CreateHttpImposter(int? port = null, string name = null, bool recordRequests = false, HttpResponseFields defaultResponse = null, bool allowCORS = false);

/// <summary>
/// <summary>
/// Creates a new imposter on the specified port with the HTTPS protocol. The Submit method
/// must be called on the client in order to submit the imposter to mountebank. If the port
/// is blank, Mountebank will assign one which can be retrieved after Submit.
Expand All @@ -61,7 +63,7 @@ public interface IClient
/// The port the imposter will be set up to receive requests on, or null to allow
/// Mountebank to set the port.
/// </param>
/// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param>
/// <param name="name">The name the imposter will receive, useful for debugging/logging purposes</param>
/// <param name="key">The private key the imposter will use</param>
/// <param name="cert">The public certificate the imposer will use</param>
/// <param name="mutualAuthRequired">Whether or not the server requires mutual auth</param>
Expand All @@ -84,7 +86,7 @@ HttpsImposter CreateHttpsImposter(int? port = null, string name = null, string k
/// The port the imposter will be set up to receive requests on, or null to allow
/// Mountebank to set the port.
/// </param>
/// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param>
/// <param name="name">The name the imposter will receive, useful for debugging/logging purposes</param>
/// <param name="mode">The mode of the imposter, text or binary. This defines the encoding for request/response data</param>
/// <param name="recordRequests">
/// Enables recording requests to use the imposter as a mock. See
Expand All @@ -106,7 +108,7 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
/// The port the imposter will be set up to receive requests on, or null to allow
/// Mountebank to set the port.
/// </param>
/// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param>
/// <param name="name">The name the imposter will receive, useful for debugging/logging purposes</param>
/// <param name="recordRequests">
/// Enables recording requests to use the imposter as a mock. See
/// <see href="http://www.mbtest.org/docs/api/mocks">here</see> for more details on Mountebank
Expand All @@ -115,19 +117,18 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
/// <returns>The newly created imposter</returns>
SmtpImposter CreateSmtpImposter(int? port = null, string name = null, bool recordRequests = false);


/// <summary>
/// Retrieves the list of imposters
/// </summary>
/// <returns>The list of retrieved imposters</returns>

Task<IEnumerable<SimpleRetrievedImposter>> GetImpostersAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves an HttpImposter along with information about requests made to that
/// imposter if mountebank is running with the "--mock" flag.
/// </summary>
/// <param name="port">The port number of the imposter to retrieve</param>
/// <param name="cancellationToken"></param>
/// <returns>The retrieved imposter</returns>
/// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
/// <exception cref="MbDotNet.Exceptions.InvalidProtocolException">Thrown if the retrieved imposter was not an HTTP imposter</exception>
Expand All @@ -138,6 +139,7 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
/// imposter if mountebank is running with the "--mock" flag.
/// </summary>
/// <param name="port">The port number of the imposter to retrieve</param>
/// <param name="cancellationToken"></param>
/// <returns>The retrieved imposter</returns>
/// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
/// <exception cref="MbDotNet.Exceptions.InvalidProtocolException">Thrown if the retrieved imposter was not an HTTP imposter</exception>
Expand All @@ -148,6 +150,7 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
/// imposter if mountebank is running with the "--mock" flag.
/// </summary>
/// <param name="port">The port number of the imposter to retrieve</param>
/// <param name="cancellationToken"></param>
/// <returns>The retrieved imposter</returns>
/// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
/// <exception cref="MbDotNet.Exceptions.InvalidProtocolException">Thrown if the retrieved imposter was not an HTTP imposter</exception>
Expand All @@ -158,6 +161,7 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
/// imposter if Mountebank is running with the "--mock" flag.
/// </summary>
/// <param name="port">The port number of the imposter to retrieve</param>
/// <param name="cancellationToken"></param>
/// <returns>The retrieved imposter</returns>
/// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
/// <exception cref="MbDotNet.Exceptions.InvalidProtocolException">Thrown if the retrieved imposter was not an SMTP imposter</exception>
Expand All @@ -168,6 +172,7 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
/// of imposters that the client maintains.
/// </summary>
/// <param name="port">The port number of the imposter to be removed</param>
/// <param name="cancellationToken"></param>
Task DeleteImposterAsync(int port, CancellationToken cancellationToken = default);

/// <summary>
Expand All @@ -177,37 +182,41 @@ TcpImposter CreateTcpImposter(int? port = null, string name = null, TcpMode mode
Task DeleteAllImpostersAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Submits all pending imposters from the supplied collection to be created in mountebank.
/// Submits all pending imposters from the supplied collection to be created in mountebank.
/// <exception cref="MbDotNet.Exceptions.MountebankException">Thrown if unable to create the imposter.</exception>
/// </summary>
/// <param name="imposters">The imposters being submitted to mountebank</param>
/// <param name="cancellationToken"></param>
Task SubmitAsync(ICollection<Imposter> imposters, CancellationToken cancellationToken = default);

/// <summary>
/// Submits imposter to be created in mountebank.
/// Submits imposter to be created in mountebank.
/// <exception cref="MbDotNet.Exceptions.MountebankException">Thrown if unable to create the imposter.</exception>
/// </summary>
/// <param name="imposter">The imposter being submitted to mountebank</param>
/// <param name="cancellationToken"></param>
Task SubmitAsync(Imposter imposter, CancellationToken cancellationToken = default);

/// <summary>
/// Overwrites the stubs of an existing imposter without restarting it.
/// </summary>
/// <param name="imposter">The imposter to be updated with new stubs</param>
/// <param name="cancellationToken"></param>
/// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
Task UpdateImposterAsync(Imposter imposter, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes previously saved requests for an imposter
/// </summary>
/// <param name="port">The port of the imposter to delete request history</param>
/// <param name="cancellationToken"></param>
/// <exception cref="MbDotNet.Exceptions.ImposterNotFoundException">Thrown if no imposter was found on the specified port.</exception>
Task DeleteSavedRequestsAsync(int port, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the configuration information of Mountebank
/// </summary>
/// <returns>A Config object containing the configuration of Mountebank</returns>
/// <returns>A Config object containing the configuration of Mountebank</returns>
Task<Config> GetConfigAsync(CancellationToken cancellationToken = default);
}
}
12 changes: 12 additions & 0 deletions MbDotNet/Models/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@

namespace MbDotNet.Models
{
/// <summary>
/// The configuration of the Mountebank server
/// </summary>
public class Config
{
/// <summary>
/// The version of Mountebank that is running
/// </summary>
[JsonProperty("version")]
public string Version { get; set; }

/// <summary>
/// The command line options used to start Mountebank
/// </summary>
[JsonProperty("options")]
public Dictionary<string, dynamic> Options { get; set; }

/// <summary>
/// Information about the running Mountebank process
/// </summary>
[JsonProperty("process")]
public Dictionary<string, dynamic> Process { get; set; }
}
Expand Down
20 changes: 20 additions & 0 deletions MbDotNet/Models/Imposters/HttpImposter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using MbDotNet.Models.Responses.Fields;
using MbDotNet.Models.Stubs;
using Newtonsoft.Json;

namespace MbDotNet.Models.Imposters
{
/// <summary>
/// An imposter using the HTTP protocol
/// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "CORS is an abbreviation")]
public class HttpImposter : Imposter
{
/// <summary>
/// The stubs defined for this imposter
/// </summary>
[JsonProperty("stubs")]
public ICollection<HttpStub> Stubs { get; private set; }

Expand All @@ -22,6 +30,14 @@ public class HttpImposter : Imposter
[JsonProperty("allowCORS")]
public bool AllowCORS { get; private set; }

/// <summary>
/// Create a new HttpImposter instance
/// </summary>
/// <param name="port">An optional port for the imposter to listen on</param>
/// <param name="name">An optional name for the imposter</param>
/// <param name="recordRequests">Whether or not Mountebank should record requests made to the imposter, defaults to false</param>
/// <param name="defaultResponse">An optional default response for when no predicates match a request</param>
/// <param name="allowCORS">Enables CORS requests, defaults to false</param>
public HttpImposter(int? port, string name, bool recordRequests = false, HttpResponseFields defaultResponse = null, bool allowCORS = false)
: base(port, Enums.Protocol.Http, name, recordRequests)
{
Expand All @@ -30,6 +46,10 @@ public HttpImposter(int? port, string name, bool recordRequests = false, HttpRes
AllowCORS = allowCORS;
}

/// <summary>
/// Add an empty stub to this imposter
/// </summary>
/// <returns>The new stub</returns>
public HttpStub AddStub()
{
var stub = new HttpStub();
Expand Down
Loading

0 comments on commit 25bc398

Please sign in to comment.