Skip to content

Commit 455cd82

Browse files
Remove direct dependecy to FluentAssertions.
1 parent 7a00e71 commit 455cd82

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
1616
<PackageVersion Include="Moq" Version="4.20.72" />
1717
<PackageVersion Include="PosInformatique.Moq.Analyzers" Version="1.11.0" />
18-
<PackageVersion Include="PosInformatique.FluentAssertions.Json" Version="1.4.0" />
18+
<PackageVersion Include="PosInformatique.FluentAssertions.Json" Version="1.5.0-rc.4" />
1919
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
2020
<PackageVersion Include="xunit" Version="2.8.1" />
2121
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="AzureFunctionsAssertionFailedException.cs" company="P.O.S Informatique">
3+
// Copyright (c) P.O.S Informatique. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace PosInformatique.Testing.Azure.Functions
8+
{
9+
/// <summary>
10+
/// Occurs when an Azure Functions assertions has been failed.
11+
/// </summary>
12+
public class AzureFunctionsAssertionFailedException : Exception
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="AzureFunctionsAssertionFailedException"/> class.
16+
/// </summary>
17+
public AzureFunctionsAssertionFailedException()
18+
: base()
19+
{
20+
}
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="AzureFunctionsAssertionFailedException"/> class
24+
/// with the specified <paramref name="message"/>.
25+
/// </summary>
26+
/// <param name="message">Message of the exception.</param>
27+
public AzureFunctionsAssertionFailedException(string message)
28+
: base(message)
29+
{
30+
}
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="AzureFunctionsAssertionFailedException"/> class
34+
/// with the specified <paramref name="message"/> and the <paramref name="innerException"/>.
35+
/// </summary>
36+
/// <param name="message">Message of the exception.</param>
37+
/// <param name="innerException">Inner exception related to the <see cref="AzureFunctionsAssertionFailedException"/> to create.</param>
38+
public AzureFunctionsAssertionFailedException(string message, Exception innerException)
39+
: base(message, innerException)
40+
{
41+
}
42+
}
43+
}

src/Testing.Azure.Functions.Http/HttpResponseDataAssertions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public HttpResponseDataAssertions WithEmptyBody()
5656

5757
if (byteRead != -1)
5858
{
59-
Services.ThrowException("The body of the response is not empty.");
59+
throw new AzureFunctionsAssertionFailedException("The body of the response is not empty.");
6060
}
6161

6262
return this;

src/Testing.Azure.Functions.Http/HttpResponseDataAssertionsExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ public static HttpResponseDataAssertions ShouldMatchRequest(this HttpResponseDat
2424
{
2525
if (response is not HttpResponseDataImplementation responseMock)
2626
{
27-
Services.ThrowException("The response does not originate from a HttpRequestDataMock object.");
28-
return default!;
27+
throw new AzureFunctionsAssertionFailedException("The response does not originate from a HttpRequestDataMock object.");
2928
}
3029

3130
if (!request.Mock.Responses.Contains(responseMock))
3231
{
33-
Services.ThrowException("The response does not originate from the request instance.");
32+
throw new AzureFunctionsAssertionFailedException("The response does not originate from the request instance.");
3433
}
3534

3635
return new HttpResponseDataAssertions(responseMock);

tests/Testing.Azure.Functions.Http.Tests/HttpResponseDataAssertionsExtensionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ShouldMatchRequest_ResponseDifferentRequest()
3333
var response = request.Object.CreateResponse();
3434

3535
response.Invoking(r => r.ShouldMatchRequest(otherRequest))
36-
.Should().ThrowExactly<XunitException>()
36+
.Should().ThrowExactly<AzureFunctionsAssertionFailedException>()
3737
.WithMessage("The response does not originate from the request instance.");
3838
}
3939

@@ -45,7 +45,7 @@ public void ShouldMatchRequest_ResponseNotCreatedFromMock()
4545
var response = new Mock<HttpResponseData>(MockBehavior.Strict, Mock.Of<FunctionContext>(MockBehavior.Strict));
4646

4747
response.Object.Invoking(r => r.ShouldMatchRequest(request))
48-
.Should().ThrowExactly<XunitException>()
48+
.Should().ThrowExactly<AzureFunctionsAssertionFailedException>()
4949
.WithMessage("The response does not originate from a HttpRequestDataMock object.");
5050

5151
response.VerifyAll();

tests/Testing.Azure.Functions.Http.Tests/HttpResponseDataAssertionsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void WithEmptyBody_Failed()
137137
assertions.WithEmptyBody();
138138
};
139139

140-
act.Should().ThrowExactly<XunitException>()
140+
act.Should().ThrowExactly<AzureFunctionsAssertionFailedException>()
141141
.WithMessage("The body of the response is not empty.");
142142

143143
response.Body.Position.Should().Be(position);

0 commit comments

Comments
 (0)