-
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) Add producer actions tests (#139)
* Add test on Certificate and FluxzySetting * Add ImageResultProducer unit test * Add ResponseBodySummaryProducer test cases A new set of unit tests has been added to validate the functionality of the ResponseBodySummaryProducer class. This additional test coverage checks if the result produced by the class correctly matches the expected content type or returns null depending on different URL cases. * Add new unit test for ResponseTextContentProducer A new unit test has been introduced in the Producers.cs file. This test checks the ResponseTextContentProducer's functionality by asserting whether a returned result is either null or not null based on different URLs. * Add SetCookieProducer unit test and disable auto-redirect A new unit test for the SetCookieProducer class has been added, testing its functionality against different URL input values. In addition, the auto-redirect option in the HttpClientHandler within the QuickArchiveBuilder has been disabled to ensure tests get more accurate results. * Update RequestJsonBodyProducer unit test The unit test for RequestJsonBodyProducer has been enhanced with two inputs scenarios. Now it can handle cases where the HttpRequestMessage content could be null or not. The Assertions will now apply based on the boolean 'pass' parameter. * Add ProducersActions tests and update HTTP request handling New unit tests for `ProducersActions` have been included. Additionally, decompression handling has been refined for `QuickArchiveBuilder` and the HTTP request raw header format has been updated in `Producers` tests. * Add ContentLength assertion in Producers unit test Added an assertion in the Producers.cs structure of the Fluxzy.Tests to ensure that the ContentLength attribute of the result is greater than 0. This is to prevent a situation where a result is obtained but there is no content within it. * Add unit test for ResponseBodyJsonProducer A new unit test has been added for the ResponseBodyJsonProducer class. This test checks whether the producer can correctly build and format responses based on different URLs. It uses Assert methods to verify the results. * Add new test case to ResponseBodyJsonProducer An additional test case has been added to the unit test for the method ResponseBodyJsonProducer. This ensures that the method correctly handles different inputs. * Add additional assertions in Producers unit tests . * Enhance ProducerContext unit test in Fluxzy.Tests. --------- Co-authored-by: fluxzy-ci <admin@fluxzy.io>
- Loading branch information
Showing
7 changed files
with
375 additions
and
11 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
87 changes: 87 additions & 0 deletions
87
test/Fluxzy.Tests/UnitTests/Formatters/ProducersActions.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,87 @@ | ||
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak | ||
|
||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Fluxzy.Formatters; | ||
using Fluxzy.Formatters.Producers.ProducerActions.Actions; | ||
using Fluxzy.Tests._Fixtures; | ||
using Xunit; | ||
|
||
namespace Fluxzy.Tests.UnitTests.Formatters | ||
{ | ||
public class ProducersActions : FormatterTestBase | ||
{ | ||
[Theory] | ||
[InlineData("https://example.com", true, true)] | ||
[InlineData("https://example.com", false, true)] | ||
[InlineData("https://sandbox.smartizy.com/swagger/index.html", false, true)] | ||
[InlineData("https://sandbox.smartizy.com/swagger/index.html", true, true)] | ||
public async Task SaveResponseBodyAction(string url, bool decode, bool pass) | ||
{ | ||
var randomFile = GetRegisteredRandomFile(); | ||
var outFile = GetRegisteredRandomFile(); | ||
var uri = new Uri(url); | ||
|
||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri); | ||
|
||
await QuickArchiveBuilder.MakeQuickArchive(requestMessage, randomFile, setting => { | ||
setting.UseBouncyCastle = true; | ||
} ); | ||
|
||
var archiveReaderProvider = new FromFileArchiveFileProvider(randomFile); | ||
|
||
var producerFactory = new ProducerFactory(archiveReaderProvider, FormatSettings.Default); | ||
|
||
var action = new SaveResponseBodyAction(producerFactory); | ||
|
||
var result = await action.Do(2, decode, outFile); | ||
|
||
if (pass) { | ||
Assert.True(result); | ||
Assert.True(System.IO.File.Exists(outFile)); | ||
} | ||
else { | ||
Assert.False(result); | ||
Assert.False(System.IO.File.Exists(outFile)); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://example.com", true)] | ||
[InlineData("https://example.com", false)] | ||
public async Task SaveRequestBodyAction(string url, bool pass) | ||
{ | ||
var randomFile = GetRegisteredRandomFile(); | ||
var outFile = GetRegisteredRandomFile(); | ||
var uri = new Uri(url); | ||
|
||
var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri); | ||
|
||
if (pass) { | ||
requestMessage.Content = new StringContent("Hello world"); | ||
} | ||
|
||
await QuickArchiveBuilder.MakeQuickArchive(requestMessage, randomFile, setting => { | ||
setting.UseBouncyCastle = true; | ||
} ); | ||
|
||
var archiveReaderProvider = new FromFileArchiveFileProvider(randomFile); | ||
|
||
var producerFactory = new ProducerFactory(archiveReaderProvider, FormatSettings.Default); | ||
|
||
var action = new SaveRequestBodyProducerAction(producerFactory); | ||
|
||
var result = await action.Do(2, outFile); | ||
|
||
if (pass) { | ||
Assert.True(result); | ||
Assert.True(System.IO.File.Exists(outFile)); | ||
} | ||
else { | ||
Assert.False(result); | ||
Assert.False(System.IO.File.Exists(outFile)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.