-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Tests) Increase coverage on filters (#151)
* Add IPAddress to TestPayload in unit tests Added IPAddress property to the TestPayload class within the MessagePackQueueExtensionsTests. Adjusted the associated Equals and GetHashCode methods to include the new IPAddress property. This ensures proper comparison functionality and hash generation for the updated test payloads. * Prevent closing provided stream * Cover more equality test * Add Zip compress / decompress test * Include a websocket exchange in test case * Update test to include ws message * Add ws exchange in directory archiving tests * Remove ApplyXorSlow method from WsMessage The ApplyXorSlow method within WsMessage.cs file is no longer necessary and has therefore been removed. This function wasn't efficient and its functionality is covered by the ApplyXor method, contributing to cleaner and more maintainable code. * Add self-equality check in EqualityTesterBase . * Add test.json to Fluxzy.Tests.csproj. * Relocated MockedResponseExtensions to its own file. * Add GetHeaderValueOrDefault method to MockedResponseContent. * Add unit tests for mock response content. * Add unit tests for DefaultDnsSolver . * Initialize DNS resolution result . * Add NavigationTests and clean up Program.cs A new test file, NavigationTests.cs, has been introduced to cover CLI navigation. Concurrently, code in Program.cs has been streamlined for better clarity and readability. Unused environment variable options have been removed, and redundant spacing has been eliminated. * Add JsonConstructor to AgentLabelFilter * Add more filter tests * Increase default settings coverage * Use DefaultAgentProvider * Fix ApplyTagAction default scope * Add tests for non empty constructors filter type
- Loading branch information
Showing
24 changed files
with
676 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/Fluxzy.Core/Rules/Actions/HighLevelActions/MockedResponseExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak | ||
|
||
using Fluxzy.Clients.Mock; | ||
using Fluxzy.Rules.Extensions; | ||
|
||
namespace Fluxzy.Rules.Actions.HighLevelActions | ||
{ | ||
public static class MockedResponseExtensions | ||
{ | ||
/// <summary> | ||
/// Generates a mocked response for a file and configures it as a response action for a given action builder. | ||
/// </summary> | ||
/// <param name="actionBuilder">The action builder to configure.</param> | ||
/// <param name="fileName">The name of the file to generate a response from.</param> | ||
/// <param name="statusCode">The HTTP status code for the response (default is 200).</param> | ||
/// <param name="contentType">The content type of the response (default is null).</param> | ||
/// <param name="headers">Additional headers to be included in the response (default is null).</param> | ||
/// <returns>An instance of <see cref="IConfigureFilterBuilder"/> for further configuration.</returns> | ||
public static IConfigureFilterBuilder ReplyFile( | ||
this IConfigureActionBuilder actionBuilder, string fileName, | ||
int statusCode = 200, string? contentType = null, params (string, string)[] headers) | ||
{ | ||
var content = MockedResponseContent.CreateFromFile(fileName, statusCode, contentType); | ||
|
||
foreach (var (name, value) in headers) | ||
content.Headers.Add(new MockedResponseHeader(name, value)); | ||
|
||
actionBuilder.Do(new MockedResponseAction(content)); | ||
return new ConfigureFilterBuilderBuilder(actionBuilder.Setting); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the simulated response with text content. | ||
/// </summary> | ||
/// <param name="actionBuilder">The action builder.</param> | ||
/// <param name="text">The text content to be returned.</param> | ||
/// <param name="statusCode">The HTTP status code of the response. Default is 200.</param> | ||
/// <param name="contentType">The content type of the response. Default is "text/plain".</param> | ||
/// <param name="headers">The headers to be added to the response.</param> | ||
/// <returns>A configured filter builder.</returns> | ||
public static IConfigureFilterBuilder ReplyText( | ||
this IConfigureActionBuilder actionBuilder, string text, | ||
int statusCode = 200, string? contentType = "text/plain", params (string, string)[] headers) | ||
{ | ||
var content = MockedResponseContent.CreateFromString(text, statusCode, contentType ?? ""); | ||
|
||
foreach (var (name, value) in headers) | ||
content.Headers.Add(new MockedResponseHeader(name, value)); | ||
|
||
actionBuilder.Do(new MockedResponseAction(content)); | ||
return new ConfigureFilterBuilderBuilder(actionBuilder.Setting); | ||
} | ||
|
||
/// <summary> | ||
/// Configures a mocked response that returns a byte array content. | ||
/// </summary> | ||
/// <param name="actionBuilder">The action builder.</param> | ||
/// <param name="bytes">The byte array content to be returned.</param> | ||
/// <param name="statusCode">The HTTP status code to be returned. The default value is 200.</param> | ||
/// <param name="contentType">The content type of the response. The default value is "application/octet-stream".</param> | ||
/// <param name="headers">The additional headers to be included in the response.</param> | ||
/// <returns>The configure filter builder.</returns> | ||
public static IConfigureFilterBuilder ReplyByteArray( | ||
this IConfigureActionBuilder actionBuilder, byte[] bytes, | ||
int statusCode = 200, string? contentType = "application/octet-stream", params (string, string)[] headers) | ||
{ | ||
var content = MockedResponseContent.CreateFromByteArray(bytes, statusCode, contentType ?? ""); | ||
|
||
foreach (var (name, value) in headers) | ||
content.Headers.Add(new MockedResponseHeader(name, value)); | ||
|
||
actionBuilder.Do(new MockedResponseAction(content)); | ||
return new ConfigureFilterBuilderBuilder(actionBuilder.Setting); | ||
} | ||
|
||
/// <summary> | ||
/// Sets up a mocked response with JSON content. | ||
/// </summary> | ||
/// <param name="actionBuilder">The action builder.</param> | ||
/// <param name="json">The JSON content to be returned.</param> | ||
/// <param name="statusCode">The HTTP status code of the response. Default is 200.</param> | ||
/// <param name="headers">The custom headers to be included in the response.</param> | ||
/// <returns>A configure filter builder for further configuration.</returns> | ||
public static IConfigureFilterBuilder ReplyJson( | ||
this IConfigureActionBuilder actionBuilder, string json, | ||
int statusCode = 200, params (string, string)[] headers) | ||
{ | ||
var content = MockedResponseContent.CreateFromString(json, statusCode, "application/json"); | ||
|
||
foreach (var (name, value) in headers) | ||
content.Headers.Add(new MockedResponseHeader(name, value)); | ||
|
||
actionBuilder.Do(new MockedResponseAction(content)); | ||
|
||
return new ConfigureFilterBuilderBuilder(actionBuilder.Setting); | ||
} | ||
|
||
/// <summary> | ||
/// Generates a mocked response with JSON content from a file and configures the action builder to reply with the generated response. | ||
/// </summary> | ||
/// <param name="actionBuilder">The action builder to configure.</param> | ||
/// <param name="fileName">The name of the file that contains the JSON content.</param> | ||
/// <param name="statusCode">The status code to be set in the response. Default is 200.</param> | ||
/// <param name="headers">Additional headers to be included in the response.</param> | ||
/// <returns>A configure filter builder instance.</returns> | ||
public static IConfigureFilterBuilder ReplyJsonFile( | ||
this IConfigureActionBuilder actionBuilder, string fileName, | ||
int statusCode = 200, params (string, string)[] headers) | ||
{ | ||
var content = MockedResponseContent.CreateFromFile(fileName, statusCode, "application/json"); | ||
|
||
foreach (var (name, value) in headers) | ||
content.Headers.Add(new MockedResponseHeader(name, value)); | ||
|
||
actionBuilder.Do(new MockedResponseAction(content)); | ||
|
||
return new ConfigureFilterBuilderBuilder(actionBuilder.Setting); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.