Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5718ec0
Added NTLM authentication and small updates
mihaj Nov 19, 2020
e54faf7
Merge branch 'main' into develop
mihaj Dec 7, 2020
8e60581
Upload files with multipart content type
mihaj Dec 7, 2020
8db309a
Merge branch 'develop' of https://github.com/qatoolkit/qatoolkit-engi…
mihaj Dec 7, 2020
280b19a
Merge branch 'main' into develop
mihaj Dec 7, 2020
f0f9f5e
CreateHttpRequest override that accepts HttpRequest object
mihaj Dec 12, 2020
48787a2
Merge branch 'main' into develop
mihaj Dec 12, 2020
df94c4e
Merge branch 'develop' of https://github.com/qatoolkit/qatoolkit-engi…
mihaj Dec 12, 2020
2557cc8
Merge branch 'main' into develop
mihaj Dec 12, 2020
f05c3cd
Asserter has new methods ResponseStatusCodeIsSuccess and ResponseBody…
mihaj Dec 14, 2020
9dc1f90
Merge branch 'main' into develop
mihaj Dec 14, 2020
4f55262
HttpTester client now has WithPathReplacementValues, bug fix with que…
mihaj Dec 14, 2020
3a58192
Merge branch 'main' into develop
mihaj Dec 14, 2020
b3ba223
maintenance
mihaj Dec 30, 2020
3d5b02f
year update
mihaj Jan 2, 2021
9989309
Http duration added, XML deserializer for HTTP response content
mihaj Feb 22, 2021
4deb763
Merge branch 'main' into develop
mihaj Feb 22, 2021
c99d168
HTTP authentication with client certificate
mihaj Apr 13, 2021
c6e3ba2
Merge branch 'main' into develop
mihaj Apr 13, 2021
2bc133a
nuget updates
mihaj Aug 17, 2021
6b7ea84
Merge branch 'main' into develop
mihaj Aug 17, 2021
4787e81
nuget updates
mihaj Aug 17, 2021
5795435
Implementation of assert named ResponseContentTypeEquals (#32)
mihaj Nov 1, 2021
1c95e75
Merge branch 'main' into develop
mihaj Nov 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.3.2</Version>
<Version>0.3.3</Version>
</PropertyGroup>
</Project>
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ You can pass `X509Certificate2` objet to the `WithCertificateAuthentication` met
This is an implementation of the HTTP response message asserter, which can be used to assert different parameters.

Here is a list of Asserters:
- `ResponseContentContains`: HTTP body contains a string (ignores case)
- `RequestDurationEquals`: Verify request duration
- `ResponseStatusCodeEquals`: Verify if response code equals
- `ResponseHasHttpHeader`: HTTP response contains a header
- `ResponseStatusCodeIsSuccess`: HTTP response status code is one of 2xx
- `ResponseBodyIsEmpty`: HTTP response body is empty
- `ResponseContentContains`: HTTP body contains a string (ignores case).
- `RequestDurationEquals`: Verify request duration.
- `ResponseStatusCodeEquals`: Verify if response code equals to specified.
- `ResponseHasHttpHeader`: HTTP response contains a header.
- `ResponseStatusCodeIsSuccess`: HTTP response status code is one of 2xx.
- `ResponseBodyIsEmpty`: HTTP response body is empty.
- `ResponseContentTypeEquals`: Check if HTTP response media type equals to specified.

Asserter produces a list of `AssertResult`:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -34,6 +35,7 @@ public async Task HttpTestAsserterSimple_Success()
.ResponseContentContains("scott")
.RequestDurationEquals(duration, (x) => x < 2000)
.ResponseStatusCodeEquals(HttpStatusCode.OK)
.ResponseContentTypeEquals("application/json")
.ResponseHasHttpHeader("Date")
.AssertAll();

Expand Down Expand Up @@ -121,6 +123,7 @@ public async Task HttpTestAsserterHeaderMissing_Fails()
.RequestDurationEquals(duration, (x) => x < 2000)
.RequestDurationEquals(httpDuration, (x) => x < 1800)
.ResponseStatusCodeEquals(HttpStatusCode.OK)
.ResponseContentTypeEquals("application/json")
.ResponseHasHttpHeader(null)
.AssertAll());
}
Expand All @@ -146,6 +149,7 @@ public async Task HttpTestAsserterBodyNull_Fails()
Assert.Throws<ArgumentNullException>(() => asserter
.ResponseContentContains(null)
.RequestDurationEquals(duration, (x) => x < 1000)
.ResponseContentTypeEquals("application/json")
.ResponseStatusCodeEquals(HttpStatusCode.OK)
.AssertAll());
}
Expand All @@ -172,10 +176,11 @@ public async Task HttpTestAsserterAlternativeDurationPredicate_Success()
.ResponseContentContains("id")
.RequestDurationEquals(duration, (x) => (x > 100 && x < 1000))
.ResponseStatusCodeEquals(HttpStatusCode.OK)
.ResponseContentTypeEquals("application/json")
.ResponseStatusCodeIsSuccess()
.AssertAll();

Assert.Equal(5, assertResults.ToList().Count);
Assert.Equal(6, assertResults.ToList().Count);
foreach (var result in assertResults)
{
Assert.True(result.IsTrue, result.Message);
Expand Down
27 changes: 27 additions & 0 deletions src/QAToolKit.Engine.HttpTester/HttpTestAsserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mime;

namespace QAToolKit.Engine.HttpTester
{
Expand Down Expand Up @@ -59,6 +61,31 @@ public IHttpTestAsserter ResponseContentContains(string keyword, bool caseInsens

return this;
}

/// <summary>
/// Check if the response contains specified Content Type
/// </summary>
/// <param name="contentType"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public IHttpTestAsserter ResponseContentTypeEquals(string contentType)
{
if (contentType == null)
{
throw new ArgumentNullException($"{nameof(contentType)} is null.");
}

var bodyString = _httpResponseMessage.Content.Headers.ContentType;

_assertResults.Add(new AssertResult()
{
Name = nameof(ResponseContentTypeEquals),
Message = $"Response content-type equals '{contentType}'.",
IsTrue = _httpResponseMessage.Content.Headers.ContentType.MediaType == contentType
});

return this;
}

/// <summary>
/// Verify request duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http.Headers;

namespace QAToolKit.Engine.HttpTester.Interfaces
{
Expand Down Expand Up @@ -47,6 +48,12 @@ public interface IHttpTestAsserter
/// <returns></returns>
IHttpTestAsserter ResponseBodyIsEmpty();
/// <summary>
/// Check if the response contains specified Content Type
/// </summary>
/// <param name="contentType"></param>
/// <returns></returns>
IHttpTestAsserter ResponseContentTypeEquals(string contentType);
/// <summary>
/// Return all Assert messages of the Asserter
/// </summary>
/// <returns></returns>
Expand Down