Skip to content

No mocks were provided (#22) #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tasks": {
"test": "dotnet test",
"build": "dotnet build"
}
}
5 changes: 5 additions & 0 deletions ApiStub.FSharp/CE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System
open Microsoft.Extensions.Http
open Microsoft.AspNetCore.Routing.Template
open Microsoft.AspNetCore.Routing
open Microsoft.AspNetCore.Http

/// computation expression module (builder CE), contains `TestClient<T>` that wraps `WebApplicationFactory<T>`
module CE =
Expand Down Expand Up @@ -211,6 +212,10 @@ module CE =
s.ConfigureAll<HttpClientFactoryOptions>(fun options ->
options.HttpMessageHandlerBuilderActions.Add(fun builder ->
//builder.AdditionalHandlers.Add(httpMessageHandler) |> ignore

if httpMessageHandler = null then
failwith "no mocks were provided"

builder.PrimaryHandler <- httpMessageHandler)

options.HttpClientActions.Add(fun c ->
Expand Down
3 changes: 2 additions & 1 deletion test/ApiStub.FSharp.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Compile Include="BDDTests.fs" />
<Compile Include="BuilderExtensionsTests.fs" />
<Compile Include="StubberyTests.fs" />
<Compile Include="Issues.fs" />
<Content Include="swagger.json" />
</ItemGroup>
<ItemGroup>
Expand All @@ -35,4 +36,4 @@
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.3" />
</ItemGroup>
</Project>
</Project>
44 changes: 44 additions & 0 deletions test/Issues.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace ApiStub.FSharp.Tests

open Xunit
open fsharpintegrationtests
open Microsoft.AspNetCore.Mvc.Testing
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Hosting
open SwaggerProvider
open System.Threading.Tasks
open System.Net.Http
open System
open Microsoft.AspNetCore.TestHost
open Microsoft.Extensions.Http
open Microsoft.AspNetCore.Routing.Template
open Microsoft.AspNetCore.Routing.Patterns
open Microsoft.AspNetCore.Routing
open System.Net
open System.Text.Json
open Microsoft.AspNetCore.Http
open System.Net.Http.Json
open Swensen.Unquote
open ApiStub.FSharp.CE
open ApiStub.FSharp.BuilderExtensions
open ApiStub.FSharp.HttpResponseHelpers
open ApiStub.FSharp
open ApiStub.FSharp.BDD
open HttpResponseMessageExtensions
open Xunit.Abstractions

module IssuesTests =

let testce = new CE.TestClient<Startup>()

[<Fact>]
let ``test_no_mocks_declared_throws_exception`` () =
task {
let factory = testce.GetFactory()
let client = factory.CreateClient()

let! response = client.GetAsync("/Hello")
Assert.False(response.IsSuccessStatusCode)
let! responseString = response.Content.ReadAsStringAsync()
Assert.Contains("no mocks were provided", responseString)
}
Loading