Skip to content

Commit 1cc8b5b

Browse files
committed
Added IAggregateExceptionTestBuilder.cs and method for testing AggregateException to IShouldThrowTestBuilder (#73)
1 parent a3aea5c commit 1cc8b5b

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

src/MyWebApi/Builders/Actions/ShouldThrowTestBuilder.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public IExceptionTestBuilder Exception()
5454
return this.exceptionTestBuilder;
5555
}
5656

57+
/// <summary>
58+
/// Tests whether action throws any AggregateException.
59+
/// </summary>
60+
/// <returns>AggregateException test builder.</returns>
61+
public IAggregateExceptionTestBuilder AggregateException()
62+
{
63+
this.exceptionTestBuilder.OfType<AggregateException>();
64+
return new AggregateExceptionTestBuilder(
65+
this.Controller,
66+
this.ActionName,
67+
this.CaughtException as AggregateException);
68+
}
69+
5770
/// <summary>
5871
/// Tests whether action throws any HttpResponseException.
5972
/// </summary>

src/MyWebApi/Builders/Contracts/Actions/IShouldThrowTestBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public interface IShouldThrowTestBuilder : IBaseTestBuilder
3030
/// <returns>Exception test builder.</returns>
3131
IExceptionTestBuilder Exception();
3232

33+
/// <summary>
34+
/// Tests whether action throws any AggregateException.
35+
/// </summary>
36+
/// <returns>AggregateException test builder.</returns>
37+
IAggregateExceptionTestBuilder AggregateException();
38+
3339
/// <summary>
3440
/// Tests whether action throws any HttpResponseException.
3541
/// </summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// MyWebApi - ASP.NET Web API Fluent Testing Framework
2+
// Copyright (C) 2015 Ivaylo Kenov.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see http://www.gnu.org/licenses/.
16+
17+
namespace MyWebApi.Builders.Contracts.ExceptionErrors
18+
{
19+
public interface IAggregateExceptionTestBuilder : IExceptionTestBuilder
20+
{
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// MyWebApi - ASP.NET Web API Fluent Testing Framework
2+
// Copyright (C) 2015 Ivaylo Kenov.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see http://www.gnu.org/licenses/.
16+
17+
namespace MyWebApi.Builders.ExceptionErrors
18+
{
19+
using System;
20+
using System.Web.Http;
21+
using Contracts.ExceptionErrors;
22+
23+
public class AggregateExceptionTestBuilder : ExceptionTestBuilder, IAggregateExceptionTestBuilder
24+
{
25+
private readonly AggregateException aggregateException;
26+
27+
public AggregateExceptionTestBuilder(
28+
ApiController controller,
29+
string actionName,
30+
AggregateException caughtException)
31+
: base(controller, actionName, caughtException)
32+
{
33+
this.aggregateException = caughtException;
34+
}
35+
}
36+
}

src/MyWebApi/MyWebApi.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@
7272
<Compile Include="Builders\And\AndProvideTestBuilder.cs" />
7373
<Compile Include="Builders\And\AndProvideTestBuilder{TActionResult}.cs" />
7474
<Compile Include="Builders\And\AndTestBuilder.cs" />
75+
<Compile Include="Builders\Contracts\ExceptionErrors\IAggregateExceptionTestBuilder.cs" />
7576
<Compile Include="Builders\Contracts\HttpActionResults\Ok\IAndOkTestBuilder.cs" />
7677
<Compile Include="Builders\Contracts\HttpActionResults\Ok\IOkTestBuilder.cs" />
7778
<Compile Include="Builders\Contracts\HttpRequests\IAndHttpRequestMessageBuilder.cs" />
7879
<Compile Include="Builders\Contracts\HttpRequests\IHttpRequestMessageBuilder.cs" />
7980
<Compile Include="Builders\Contracts\HttpResponseMessages\IAndHttpResponseMessageTestBuilder.cs" />
8081
<Compile Include="Builders\Contracts\HttpResponseMessages\IHttpResponseMessageTestBuilder.cs" />
82+
<Compile Include="Builders\ExceptionErrors\AggregateExceptionTestBuilder.cs" />
8183
<Compile Include="Builders\HttpActionResults\BadRequest\BadRequestErrorMessageTestBuilder.cs" />
8284
<Compile Include="Builders\HttpActionResults\BadRequest\BadRequestTestBuilder.cs" />
8385
<Compile Include="Builders\Base\BaseTestBuilder.cs" />

0 commit comments

Comments
 (0)