Skip to content

Commit acdad01

Browse files
committed
Add more validation tests
1 parent ad17ffb commit acdad01

9 files changed

Lines changed: 44 additions & 8 deletions

File tree

src/Dibix.Sdk.CodeGeneration/Parser/SqlStoredProcedureVisitor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,14 @@ private void ValidateJsonFileResult(SqlStatementDefinition definition)
198198
if (definition.GenerateResultClass)
199199
return;
200200

201-
SourceLocation location = definition.ResultType.Location;
202201
if (definition.ResultType is SchemaTypeReference schemaTypeReference)
203202
{
204203
SchemaDefinition schemaDefinition = SchemaRegistry.GetSchema(schemaTypeReference);
205-
location = schemaDefinition.Location;
206204
if (schemaDefinition is ObjectSchema { IsJsonFileResult: not null })
207205
return;
208206
}
209207

210-
Logger.LogError("When using the @FileResult Json option, the output contract should have the '$isJsonFileResult' property set to true", location);
208+
Logger.LogError("When using the @FileResult Json option, the output contract should have the '$isJsonFileResult' property set to true", definition.ResultType.Location);
211209
}
212210
#endregion
213211

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"JsonFileResultContractError": {
3+
"X": "uuid?",
4+
"FileName": "string",
5+
"Directions": "Direction*"
6+
}
7+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"Request": {
3+
"$isJsonFileResult": true,
34
"Id": "Entry",
4-
"Ids": "Entry*"
5+
"Ids": "Entry*",
6+
"UnusedProperty": "string"
57
}
68
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"UnusedContract": {
3+
"UnusedProperty": "string"
4+
}
5+
}

tests/Dibix.Sdk.Tests.Database/Dibix.Sdk.Tests.Database.sqlproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<Build Include="CodeAnalysis\dbx_codeanalysis_error_043.sql" />
164164
<Build Include="Tests\Syntax\dbx_tests_syntax_fileresultjson_gridresult_merge.sql" />
165165
<Build Include="Tests\Syntax\dbx_tests_syntax_fileresultjson_gridresult.sql" />
166+
<Build Include="Tests\Syntax\dbx_tests_syntax_fileresultjson_gridresult_merge_error.sql" />
166167
</ItemGroup>
167168
<ItemGroup>
168169
<Folder Include="CodeAnalysis" />
@@ -203,6 +204,8 @@
203204
<None Include="Contracts\NestedEnumerableContainer.json" />
204205
<None Include="Contracts\NestedEnumerableSubItem.json" />
205206
<None Include="Contracts\JsonFileResultContract.json" />
207+
<None Include="Contracts\UnusedContract.json" />
208+
<None Include="Contracts\JsonFileResultContractError.json" />
206209
</ItemGroup>
207210
<Import Condition="'$(NetCoreBuild)' == 'true'" Project="$(NETCoreTargetsPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
208211
<ItemGroup>

tests/Dibix.Sdk.Tests.Database/Endpoints/GenericEndpointWithErrors.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
{
108108
"method": "GET",
109109
"target": "EmptyWithParamsAndComplexUdt",
110-
"operationId": "GetEmptyWithParamsAndComplexUdtAndAmbiguousRoute",
111110
"childRoute": "ambiguous/route/{a}/{c}/{password}",
112111
"params": {
113112
"b": "QUERY.b",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- @Name FileResultJsonMergeGridResultError
2+
-- @Return ClrTypes:JsonFileResultContractError Mode:SingleOrDefault
3+
-- @Return ClrTypes:Direction Name:Directions
4+
-- @MergeGridResult
5+
-- @FileResult Json
6+
CREATE PROCEDURE [dbo].[dbx_tests_syntax_fileresultjson_gridresult_merge_error]
7+
AS
8+
BEGIN
9+
SELECT [x] = N'527B8008-AE6E-421F-91B2-5A0583070BCD', [filename] = N'the_file_result.json'
10+
11+
SELECT 1
12+
END

tests/Dibix.Sdk.Tests/CodeGeneration/CodeGenerationTaskTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ public void Endpoint_WithValidationErrors_Error()
554554
, @"Tests\Syntax\dbx_tests_syntax_empty_params.sql"
555555
, @"Tests\Syntax\dbx_tests_syntax_empty_params_udt.sql"
556556
, @"Tests\Syntax\dbx_tests_syntax_fileresult.sql"
557+
, @"Tests\Syntax\dbx_tests_syntax_fileresultjson_gridresult_merge_error.sql"
557558
, @"Tests\Syntax\dbx_tests_syntax_singleconcreteresult.sql"
558559
, @"Tests\Syntax\dbx_tests_syntax_singleconcreteresult_missingcolumn.sql"
559560
}
@@ -563,7 +564,9 @@ public void Endpoint_WithValidationErrors_Error()
563564
, @"Contracts\GenericContract.json"
564565
, @"Contracts\InputContract.json"
565566
, @"Contracts\Entry.json"
567+
, @"Contracts\JsonFileResultContractError.json"
566568
, @"Contracts\Request.json"
569+
, @"Contracts\UnusedContract.json"
567570
}
568571
, endpoints: new[] { @"Endpoints\GenericEndpointWithErrors.json" }
569572
, isEmbedded: false

tests/Dibix.Sdk.Tests/Resources/CodeGeneration/Endpoint_WithValidationErrors_Error.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
One or more errors occured during code generation:
2+
Tests\Syntax\dbx_tests_syntax_fileresultjson_gridresult_merge_error.sql(2,21,2,21):error:When using the @FileResult Json option, the output contract should have the '$isJsonFileResult' property set to true
23
Tests\Syntax\dbx_tests_syntax_singleconcreteresult_missingcolumn.sql(4,12,4,12):error:Property 'ImageUrl' on type 'Dibix.Sdk.Tests.DomainModel.GenericContract' not mapped
34
Endpoints\GenericEndpointWithErrors.json(9,15,9,15):error:Unknown property source 'WTF'
45
Endpoints\GenericEndpointWithErrors.json(6,18,6,18):error:Location of parameter 'password' cannot be inferred. Please declare the source of the parameter.
@@ -19,6 +20,10 @@ Endpoints\GenericEndpointWithErrors.json(109,18,109,18):error:Location of parame
1920
Endpoints\GenericEndpointWithErrors.json(10,19,10,19):error:Source 'ENV' does not support property 'MachinePassword'
2021
Endpoints\GenericEndpointWithErrors.json(11,21,11,21):error:Source 'CLAIM' does not support property 'None'
2122
Endpoints\GenericEndpointWithErrors.json(16,21,16,21):error:The parameter 'wtf' is a path parameter, therefore cannot be read using the 'QUERY' source
23+
Contracts\Request.json(3,6,3,6):error:Contract 'Dibix.Sdk.Tests.DomainModel.Request' has '$isJsonFileResult' set to true, but the contract is not used within a statement marked with the '@FileResult Json' option
24+
Contracts\Request.json(3,6,3,6):error:Contract 'Dibix.Sdk.Tests.DomainModel.Request' has '$isJsonFileResult' set to true, and therefore should implement a property 'FileName' of type 'string'
25+
Contracts\Request.json(6,6,6,6):error:Unused contract definition property: Dibix.Sdk.Tests.DomainModel.Request.UnusedProperty
26+
Contracts\UnusedContract.json(2,4,2,4):error:Unused contract definition: Dibix.Sdk.Tests.DomainModel.UnusedContract
2227
Endpoints\GenericEndpointWithErrors.json(6,18,6,18):error:Deep object query parameters are not supported: ids
2328
Endpoints\GenericEndpointWithErrors.json(6,18,6,18):error:Deep object query parameters are not supported: primitive
2429
Endpoints\GenericEndpointWithErrors.json(6,18,6,18):error:Deep object query parameters are not supported: nested
@@ -29,9 +34,11 @@ Endpoints\GenericEndpointWithErrors.json(58,27,58,27):error:The path segment 'ge
2934
Endpoints\GenericEndpointWithErrors.json(109,18,109,18):error:Deep object query parameters are not supported: ids
3035
Endpoints\GenericEndpointWithErrors.json(109,18,109,18):error:Deep object query parameters are not supported: nested
3136
Endpoints\GenericEndpointWithErrors.json(109,18,109,18):error:Deep object query parameters are not supported: primitivenested
32-
Endpoints\GenericEndpointWithErrors.json(122,18,122,18):error:Required nullable query parameters are not supported: 'c'. Either make the parameter optional by providing a default value, add it to the path/body or make it non-nullable.
33-
Endpoints\GenericEndpointWithErrors.json(152,8,152,8):error:HTTP method DELETE should not specify a body. For an endpoint, that is used to delete a resource, its business key should be part of the URL as path segments using the 'childRoute' property.
37+
Endpoints\GenericEndpointWithErrors.json(121,18,121,18):error:Required nullable query parameters are not supported: 'c'. Either make the parameter optional by providing a default value, add it to the path/body or make it non-nullable.
38+
Endpoints\GenericEndpointWithErrors.json(151,8,151,8):error:HTTP method DELETE should not specify a body. For an endpoint, that is used to delete a resource, its business key should be part of the URL as path segments using the 'childRoute' property.
3439
Endpoints\GenericEndpointWithErrors.json(86,5,86,5):error:Equivalent path defined: GET Tests/GenericEndpoint/ambiguous/route/{a}/{c}/{password}
3540
Endpoints\GenericEndpointWithErrors.json(96,5,96,5):error:Equivalent path defined: POST Tests/GenericEndpoint/ambiguous/route/{b}/{c}/{password}
3641
Endpoints\GenericEndpointWithErrors.json(86,5,86,5):error:Duplicate method defined within path: GET Tests/GenericEndpoint/ambiguous/route/{a}/{c}/{password}
37-
Endpoints\GenericEndpointWithErrors.json(107,5,107,5):error:Duplicate method defined within path: GET Tests/GenericEndpoint/ambiguous/route/{a}/{c}/{password}
42+
Endpoints\GenericEndpointWithErrors.json(107,5,107,5):error:Duplicate method defined within path: GET Tests/GenericEndpoint/ambiguous/route/{a}/{c}/{password}
43+
Endpoints\GenericEndpointWithErrors.json(6,18,6,18):error:Ambiguous action name 'EmptyWithParamsAndComplexUdt'. Please use the 'operationId' property to define a unique name when reusing accessor targets.
44+
Endpoints\GenericEndpointWithErrors.json(109,18,109,18):error:Ambiguous action name 'EmptyWithParamsAndComplexUdt'. Please use the 'operationId' property to define a unique name when reusing accessor targets.

0 commit comments

Comments
 (0)