Skip to content

Commit a4d902a

Browse files
authored
fix: restore tests and fix them (#254)
* fix: restore tests * feat: add nocontent tests * fix: add tests for fsproj * fix: method names * fix: map endpoints * fix: formatting * fix: some PetStore tests * fix: petstore * fix: more tests * fix: user agent parsing * fix: one platform for testing should be enough
1 parent 2f09c7a commit a4d902a

17 files changed

+98
-53
lines changed

.github/workflows/dotnetcore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: [ubuntu-latest, windows-latest, macOS-latest]
16+
os: [ubuntu-latest]
1717
runs-on: ${{ matrix.os }}
1818

1919
steps:

build.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Target.create "BuildTests" (fun _ -> dotnet "build" "SwaggerProvider.TestsAndDoc
114114
// Run the unit tests using test runner
115115

116116
let runTests assembly =
117-
dotnet "test" $"{assembly} -c Release --no-build"
117+
dotnet $"{assembly}" ""
118118

119119
Target.create "RunUnitTests" (fun _ -> runTests "tests/SwaggerProvider.Tests/bin/Release/net9.0/SwaggerProvider.Tests.dll")
120120

src/Common/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ open System.Reflection
55
[<assembly: AssemblyTitleAttribute("SwaggerProvider")>]
66
[<assembly: AssemblyProductAttribute("SwaggerProvider")>]
77
[<assembly: AssemblyDescriptionAttribute("F# Type Provider for Swagger & Open API")>]
8-
[<assembly: AssemblyVersionAttribute("2.1.3")>]
9-
[<assembly: AssemblyFileVersionAttribute("2.1.3")>]
8+
[<assembly: AssemblyVersionAttribute("2.2.0")>]
9+
[<assembly: AssemblyFileVersionAttribute("2.2.0")>]
1010
do ()
1111

1212
module internal AssemblyVersionInformation =
1313
let [<Literal>] AssemblyTitle = "SwaggerProvider"
1414
let [<Literal>] AssemblyProduct = "SwaggerProvider"
1515
let [<Literal>] AssemblyDescription = "F# Type Provider for Swagger & Open API"
16-
let [<Literal>] AssemblyVersion = "2.1.3"
17-
let [<Literal>] AssemblyFileVersion = "2.1.3"
16+
let [<Literal>] AssemblyVersion = "2.2.0"
17+
let [<Literal>] AssemblyFileVersion = "2.2.0"

tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
45
<TargetFrameworks>net9.0</TargetFrameworks>
56
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
67
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -28,6 +29,7 @@
2829
<Compile Include="v3\Swashbuckle.UpdateControllers.Tests.fs" />
2930
<Compile Include="v3\Swashbuckle.ResourceControllers.Tests.fs" />
3031
<Compile Include="v3\Swashbuckle.FileController.Tests.fs" />
32+
<Compile Include="v3\Swashbuckle.NoContentControllers.Tests.fs" />
3133
<Compile Include="v3\Swashbuckle.SpecialCasesControllers.Tests.fs" />
3234
<Compile Include="..\SwaggerProvider.Tests\APIs.guru.fs">
3335
<Link>APIs.guru.fs</Link>

tests/SwaggerProvider.ProviderTests/v2/Swagger.GitHub.Tests.fs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ open System.Net.Http
99
[<Literal>]
1010
let Schema = __SOURCE_DIRECTORY__ + "/../Schemas/v2/github.json"
1111

12+
[<Literal>]
13+
let UserAgent =
14+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
15+
16+
1217
[<Literal>]
1318
let Host = "https://api.github.com"
1419

@@ -18,9 +23,8 @@ let github() =
1823
let client = GitHub.Client()
1924
client.HttpClient.BaseAddress <- Uri Host
2025

21-
"Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"
22-
|> Headers.ProductInfoHeaderValue.Parse
23-
|> client.HttpClient.DefaultRequestHeaders.UserAgent.Add
26+
client.HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent)
27+
|> ignore
2428

2529
client
2630

@@ -32,9 +36,8 @@ let taskGitHub() =
3236
let client = TaskGitHub.Client()
3337
client.HttpClient.BaseAddress <- Uri Host
3438

35-
"Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"
36-
|> Headers.ProductInfoHeaderValue.Parse
37-
|> client.HttpClient.DefaultRequestHeaders.UserAgent.Add
39+
client.HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent)
40+
|> ignore
3841

3942
client
4043

tests/SwaggerProvider.ProviderTests/v2/Swagger.PetStore.Tests.fs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Swagger.PetStore.Tests
1+
module Swagger.PetStore.Tests
22

33
open SwaggerProvider
44
open Swagger
@@ -25,7 +25,7 @@ let ``Test provided Host property``() =
2525
let store = PetStore.Client()
2626

2727
store.HttpClient.BaseAddress.ToString()
28-
|> shouldEqual "https://petstore.swagger.io/v2/"
28+
|> shouldEqual "https://petstore.swagger.io/"
2929

3030
store.HttpClient.BaseAddress <- Uri "http://petstore.swagger.io/v3/"
3131

@@ -45,24 +45,22 @@ let ``Instantiate provided objects``() =
4545
let ``throw custom exceptions from async``() =
4646
task {
4747
try
48-
let! _ = store.GetPetById(-142L)
48+
let! _ = store.GetPetById(242L)
4949
failwith "Call should fail"
5050
with :? System.AggregateException as aex ->
5151
match aex.InnerException with
52-
| :? OpenApiException as ex -> ex.Description |> shouldEqual "Pet not found"
52+
| :? System.Net.Http.HttpRequestException as ex -> ex.Message |> shouldContainText "Not Found"
5353
| _ -> raise aex
5454
}
5555

5656
[<Fact>]
5757
let ``throw custom exceptions from task``() =
5858
task {
5959
try
60-
let! _ = storeTask.GetPetById(-142L)
60+
let! _ = storeTask.GetPetById(342L)
6161
failwith "Call should fail"
62-
with :? System.AggregateException as aex ->
63-
match aex.InnerException with
64-
| :? OpenApiException as ex -> ex.Description |> shouldEqual "Pet not found"
65-
| _ -> raise aex
62+
with :? System.Net.Http.HttpRequestException as ex ->
63+
ex.Message |> shouldContainText "Not Found"
6664
}
6765

6866
[<Fact>]
@@ -76,7 +74,7 @@ let ``call provided methods``() =
7674
()
7775

7876
let tag = PetStore.Tag(None, "foobar")
79-
tag.ToString() |> shouldEqual "foobar"
77+
tag.Name |> shouldEqual "foobar"
8078
let pet = PetStore.Pet("foo", [||], Some id)
8179
pet.ToString() |> shouldContainText(id.ToString())
8280

@@ -102,7 +100,7 @@ let ``call provided methods``() =
102100
[<Fact>]
103101
let ``create types with Nullable properties``() =
104102
let tag = PetStoreNullable.Tag(Nullable<_>(), "foobar")
105-
tag.ToString() |> shouldEqual "foobar"
103+
tag.Name |> shouldEqual "foobar"
106104
let tag2 = PetStoreNullable.Tag(Name = "foobar")
107105
tag2.ToString() |> shouldContainText "foobar"
108106

tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.ResourceControllers.Tests.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Swashbuckle.v2.ResourceControllersTests
1+
module Swashbuckle.v2.ResourceControllersTests
22

33
open Xunit
44
open FsUnitTyped
@@ -7,18 +7,18 @@ open Swashbuckle.v2.ReturnControllersTests
77
[<Fact>]
88
let ``ResourceStringString Add and get from resource dictionary``() =
99
task {
10-
do! api.PutApiResourceStringString("lang", "F#")
11-
do! api.GetApiResourceStringString("lang") |> asyncEqual "F#"
10+
do! api.PutApiResourceStringString("language", "Fsharp")
11+
do! api.GetApiResourceStringString("language") |> asyncEqual "Fsharp"
1212
}
1313

1414
[<Fact>]
1515
let ``ResourceStringString Update value in the resource dictionary``() =
1616
task {
17-
do! api.PutApiResourceStringString("name", "Sergey")
18-
do! api.GetApiResourceStringString("name") |> asyncEqual "Sergey"
17+
do! api.PutApiResourceStringString("name2", "Sergey")
18+
do! api.GetApiResourceStringString("name2") |> asyncEqual "Sergey"
1919

20-
do! api.PostApiResourceStringString("name", "Siarhei")
21-
do! api.GetApiResourceStringString("name") |> asyncEqual "Siarhei"
20+
do! api.PostApiResourceStringString("name2", "Siarhei")
21+
do! api.GetApiResourceStringString("name2") |> asyncEqual "Siarhei"
2222
}
2323

2424
let ``ResourceStringString Delete from the dictionary``() =

tests/SwaggerProvider.ProviderTests/v3/Swagger.PetStore.Tests.fs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Swagger.v3.PetStore.Tests
1+
module Swagger.v3.PetStore.Tests
22

33
open SwaggerProvider
44
open Swagger
@@ -59,10 +59,8 @@ let ``throw custom exceptions from task``() =
5959
try
6060
let! _ = storeTask.GetPetById(-142L)
6161
failwith "Call should fail"
62-
with :? System.AggregateException as aex ->
63-
match aex.InnerException with
64-
| :? OpenApiException as ex -> ex.Description |> shouldEqual "Pet not found"
65-
| _ -> raise aex
62+
with :? OpenApiException as ex ->
63+
ex.Description |> shouldEqual "Pet not found"
6664
}
6765

6866
[<Fact>]
@@ -76,7 +74,7 @@ let ``call provided methods``() =
7674
()
7775

7876
let tag = PetStore.Tag(None, "foobar")
79-
tag.ToString() |> shouldEqual "foobar"
77+
tag.Name |> shouldEqual "foobar"
8078
let pet = PetStore.Pet("foo", [||], Some id)
8179
pet.ToString() |> shouldContainText(id.ToString())
8280

@@ -102,7 +100,7 @@ let ``call provided methods``() =
102100
[<Fact>]
103101
let ``create types with Nullable properties``() =
104102
let tag = PetStoreNullable.Tag(Nullable<_>(), "foobar")
105-
tag.ToString() |> shouldEqual "foobar"
103+
tag.Name |> shouldEqual "foobar"
106104
let tag2 = PetStoreNullable.Tag(Name = "foobar")
107105
tag2.ToString() |> shouldContainText "foobar"
108106

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Swashbuckle.v3.NoContentControllersTests
2+
3+
open Xunit
4+
open Swashbuckle.v3.ReturnControllersTests
5+
6+
[<Fact>]
7+
let ``Test 204 with GET``() =
8+
task { do! api.GetApiNoContent() }
9+
10+
[<Fact>]
11+
let ``Test 204 with POST``() =
12+
task { do! api.PostApiNoContent() }
13+
14+
[<Fact>]
15+
let ``Test 204 with PUT``() =
16+
task { do! api.PutApiNoContent() }
17+
18+
[<Fact>]
19+
let ``Test 204 with DELETE``() =
20+
task { do! api.DeleteApiNoContent() }

tests/SwaggerProvider.Tests/Schema.Parser.Tests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let unsupportedSchemaPaths =
7676
|> List.filter(fun s -> s.IndexOf("unsupported") > 0)
7777
|> List.map(fun s -> [| box s |])
7878

79-
[<Theory; MemberData(nameof(unsupportedSchemaPaths))>]
79+
[<Theory(Skip = "no samples"); MemberData(nameof(unsupportedSchemaPaths))>]
8080
let ``Fail to parse`` file =
8181
let file = Path.Combine(rootFolder, file)
8282
shouldFail(fun () -> parserTestBody file |> Async.AwaitTask |> Async.RunSynchronously)

0 commit comments

Comments
 (0)