Skip to content

Commit 452fa51

Browse files
committed
fix: tag references unit tests
Signed-off-by: Vincent Biret <[email protected]>
1 parent 9eea9da commit 452fa51

26 files changed

+262
-39
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public IEnumerable<ODataPath> AllPaths
141141
/// Append tag.
142142
/// </summary>
143143
/// <param name="tagItem">The tag item.</param>
144-
public void AppendTag(OpenApiTag tagItem)
144+
internal void AppendTag(OpenApiTag tagItem)
145145
{
146146
Tags ??= [];
147147

src/Microsoft.OpenApi.OData.Reader/Operation/ODataTypeCastGetOperationHandler.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,13 @@ protected override void SetTags(OpenApiOperation operation)
258258

259259
if (tagName != null)
260260
{
261-
Context.AddExtensionToTag(tagName, Constants.xMsTocType, new OpenApiAny("page"), () => new OpenApiTag()
262-
{
263-
Name = tagName
264-
});
261+
if (IsSingleElement)
262+
Context.AppendTag(new OpenApiTag() { Name = tagName });
263+
else
264+
Context.AddExtensionToTag(tagName, Constants.xMsTocType, new OpenApiAny("page"), () => new OpenApiTag()
265+
{
266+
Name = tagName
267+
});
265268
operation.Tags.Add(new OpenApiTagReference(tagName, _document));
266269
}
267270

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmActionOperationHandlerTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,27 @@
44
// ------------------------------------------------------------
55

66
using System.Linq;
7+
using System.Reflection.Metadata;
78
using System.Xml.Linq;
89
using Microsoft.OData.Edm;
910
using Microsoft.OData.Edm.Csdl;
1011
using Microsoft.OpenApi.Extensions;
12+
using Microsoft.OpenApi.Models;
1113
using Microsoft.OpenApi.OData.Edm;
14+
using Microsoft.OpenApi.OData.Generator;
1215
using Microsoft.OpenApi.OData.Tests;
1316
using Xunit;
1417

1518
namespace Microsoft.OpenApi.OData.Operation.Tests
1619
{
1720
public class EdmActionOperationHandlerTests
1821
{
19-
private EdmActionOperationHandler _operationHandler = new EdmActionOperationHandler(new());
22+
public EdmActionOperationHandlerTests()
23+
{
24+
_operationHandler = new EdmActionOperationHandler(_openApiDocument);
25+
}
26+
private readonly OpenApiDocument _openApiDocument = new();
27+
private readonly EdmActionOperationHandler _operationHandler;
2028

2129
[Fact]
2230
public void CreateOperationForEdmActionReturnsCorrectOperation()
@@ -33,6 +41,7 @@ public void CreateOperationForEdmActionReturnsCorrectOperation()
3341

3442
// Act
3543
var operation = _operationHandler.CreateOperation(context, path);
44+
_openApiDocument.Tags = context.CreateTags();
3645

3746
// Assert
3847
Assert.NotNull(operation);
@@ -73,6 +82,7 @@ public void CreateOperationForEdmActionReturnsCorrectOperationHierarchicalClass(
7382

7483
// Act
7584
var operation = _operationHandler.CreateOperation(context, path);
85+
_openApiDocument.Tags = context.CreateTags();
7686

7787
// Assert
7888
Assert.NotNull(operation);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionImportOperationHandlerTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
using Microsoft.OData.Edm;
99
using Microsoft.OData.Edm.Csdl;
1010
using Microsoft.OpenApi.Extensions;
11+
using Microsoft.OpenApi.Models;
1112
using Microsoft.OpenApi.OData.Edm;
13+
using Microsoft.OpenApi.OData.Generator;
1214
using Microsoft.OpenApi.OData.Tests;
1315
using Xunit;
1416

1517
namespace Microsoft.OpenApi.OData.Operation.Tests
1618
{
1719
public class EdmFunctionImportOperationHandlerTests
1820
{
19-
private EdmFunctionImportOperationHandler _operationHandler = new EdmFunctionImportOperationHandler(new());
21+
public EdmFunctionImportOperationHandlerTests()
22+
{
23+
_operationHandler = new EdmFunctionImportOperationHandler(_openApiDocument);
24+
}
25+
private readonly OpenApiDocument _openApiDocument = new();
26+
private readonly EdmFunctionImportOperationHandler _operationHandler;
2027

2128
[Theory]
2229
[InlineData(true)]
@@ -36,6 +43,7 @@ public void CreateOperationForEdmFunctionImportReturnsCorrectOperation(bool useH
3643

3744
// Act
3845
var operation = _operationHandler.CreateOperation(context, path);
46+
_openApiDocument.Tags = context.CreateTags();
3947

4048
// Assert
4149
Assert.NotNull(operation);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111
using Microsoft.OpenApi.Extensions;
1212
using Microsoft.OpenApi.Models;
1313
using Microsoft.OpenApi.OData.Edm;
14+
using Microsoft.OpenApi.OData.Generator;
1415
using Microsoft.OpenApi.OData.Tests;
1516
using Xunit;
1617

1718
namespace Microsoft.OpenApi.OData.Operation.Tests
1819
{
1920
public class EdmFunctionOperationHandlerTests
2021
{
21-
private EdmFunctionOperationHandler _operationHandler = new(new());
22+
public EdmFunctionOperationHandlerTests()
23+
{
24+
_operationHandler = new EdmFunctionOperationHandler(_openApiDocument);
25+
}
26+
private readonly OpenApiDocument _openApiDocument = new();
27+
28+
private readonly EdmFunctionOperationHandler _operationHandler;
2229
#region OperationHandlerTests
2330
[Fact]
2431
public void SetsDeprecationInformation()
@@ -94,6 +101,7 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperation(bool useHTTPSta
94101

95102
// Act
96103
var operation = _operationHandler.CreateOperation(context, path);
104+
_openApiDocument.Tags = context.CreateTags();
97105

98106
// Assert
99107
Assert.NotNull(operation);
@@ -131,6 +139,7 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperationHierarchicalClas
131139

132140
// Act
133141
var operation = _operationHandler.CreateOperation(context, path);
142+
_openApiDocument.Tags = context.CreateTags();
134143

135144
// Assert
136145
Assert.NotNull(operation);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityDeleteOperationHandlerTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66
using System.Linq;
77
using Microsoft.OData.Edm;
88
using Microsoft.OpenApi.Extensions;
9+
using Microsoft.OpenApi.Models;
910
using Microsoft.OpenApi.OData.Edm;
11+
using Microsoft.OpenApi.OData.Generator;
1012
using Microsoft.OpenApi.OData.Tests;
1113
using Xunit;
1214

1315
namespace Microsoft.OpenApi.OData.Operation.Tests
1416
{
1517
public class EntityDeleteOperationHandlerTests
1618
{
17-
private readonly EntityDeleteOperationHandler _operationHandler = new EntityDeleteOperationHandler(new());
19+
public EntityDeleteOperationHandlerTests()
20+
{
21+
_operationHandler = new EntityDeleteOperationHandler(_openApiDocument);
22+
}
23+
private readonly OpenApiDocument _openApiDocument = new();
24+
private readonly EntityDeleteOperationHandler _operationHandler;
1825

1926
[Theory]
2027
[InlineData(true)]
@@ -33,6 +40,7 @@ public void CreateEntityDeleteOperationReturnsCorrectOperation(bool enableOperat
3340

3441
// Act
3542
var delete = _operationHandler.CreateOperation(context, path);
43+
_openApiDocument.Tags = context.CreateTags();
3644

3745
// Assert
3846
Assert.NotNull(delete);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityGetOperationHandlerTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
using System.Linq;
88
using Microsoft.OData.Edm;
99
using Microsoft.OpenApi.Extensions;
10+
using Microsoft.OpenApi.Models;
1011
using Microsoft.OpenApi.OData.Edm;
12+
using Microsoft.OpenApi.OData.Generator;
1113
using Microsoft.OpenApi.OData.Tests;
1214
using Xunit;
1315

1416
namespace Microsoft.OpenApi.OData.Operation.Tests
1517
{
1618
public class EntityGetOperationHandlerTests
1719
{
18-
private EntityGetOperationHandler _operationHandler = new EntityGetOperationHandler(new());
20+
public EntityGetOperationHandlerTests()
21+
{
22+
_operationHandler = new EntityGetOperationHandler(_openApiDocument);
23+
}
24+
private readonly OpenApiDocument _openApiDocument = new();
25+
26+
private readonly EntityGetOperationHandler _operationHandler;
1927

2028
[Theory]
2129
[InlineData(true, true)]
@@ -37,6 +45,8 @@ public void CreateEntityGetOperationReturnsCorrectOperation(bool enableOperation
3745

3846
// Act
3947
var get = _operationHandler.CreateOperation(context, path);
48+
_openApiDocument.Tags = context.CreateTags();
49+
4050

4151
// Assert
4252
Assert.NotNull(get);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPatchOperationHandlerTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
using System.Linq;
77
using Microsoft.OData.Edm;
88
using Microsoft.OpenApi.Extensions;
9+
using Microsoft.OpenApi.Models;
910
using Microsoft.OpenApi.OData.Edm;
11+
using Microsoft.OpenApi.OData.Generator;
1012
using Microsoft.OpenApi.OData.Tests;
1113
using Xunit;
1214

1315
namespace Microsoft.OpenApi.OData.Operation.Tests
1416
{
1517
public class EntityPatchOperationHandlerTests
1618
{
17-
private EntityPatchOperationHandler _operationHandler = new EntityPatchOperationHandler(new());
19+
public EntityPatchOperationHandlerTests()
20+
{
21+
_operationHandler = new EntityPatchOperationHandler(_openApiDocument);
22+
}
23+
private readonly OpenApiDocument _openApiDocument = new();
24+
25+
private readonly EntityPatchOperationHandler _operationHandler;
1826

1927
[Theory]
2028
[InlineData(true, true)]
@@ -36,6 +44,7 @@ public void CreateEntityPatchOperationReturnsCorrectOperation(bool enableOperati
3644

3745
// Act
3846
var patch = _operationHandler.CreateOperation(context, path);
47+
_openApiDocument.Tags = context.CreateTags();
3948

4049
// Assert
4150
Assert.NotNull(patch);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPutOperationHandlerTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
using System.Linq;
77
using Microsoft.OData.Edm;
88
using Microsoft.OpenApi.Extensions;
9+
using Microsoft.OpenApi.Models;
910
using Microsoft.OpenApi.OData.Edm;
11+
using Microsoft.OpenApi.OData.Generator;
1012
using Microsoft.OpenApi.OData.Tests;
1113
using Xunit;
1214

1315
namespace Microsoft.OpenApi.OData.Operation.Tests
1416
{
1517
public class EntityPutOperationHandlerTests
1618
{
17-
private EntityPutOperationHandler _operationHandler = new EntityPutOperationHandler(new());
19+
public EntityPutOperationHandlerTests()
20+
{
21+
_operationHandler = new EntityPutOperationHandler(_openApiDocument);
22+
}
23+
private readonly OpenApiDocument _openApiDocument = new();
24+
25+
private readonly EntityPutOperationHandler _operationHandler;
1826

1927
[Theory]
2028
[InlineData(true, true)]
@@ -36,6 +44,7 @@ public void CreateEntityPutOperationReturnsCorrectOperation(bool enableOperation
3644

3745
// Act
3846
var putOperation = _operationHandler.CreateOperation(context, path);
47+
_openApiDocument.Tags = context.CreateTags();
3948

4049
// Assert
4150
Assert.NotNull(putOperation);

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntitySetGetOperationHandlerTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
using Microsoft.OData.Edm;
1010
using Microsoft.OData.Edm.Csdl;
1111
using Microsoft.OpenApi.Extensions;
12+
using Microsoft.OpenApi.Models;
1213
using Microsoft.OpenApi.OData.Common;
1314
using Microsoft.OpenApi.OData.Edm;
15+
using Microsoft.OpenApi.OData.Generator;
1416
using Microsoft.OpenApi.OData.Tests;
1517
using Xunit;
1618

1719
namespace Microsoft.OpenApi.OData.Operation.Tests
1820
{
1921
public class EntitySetGetOperationHandlerTests
2022
{
21-
private EntitySetGetOperationHandler _operationHandler = new EntitySetGetOperationHandler(new());
23+
public EntitySetGetOperationHandlerTests()
24+
{
25+
_operationHandler = new EntitySetGetOperationHandler(_openApiDocument);
26+
}
27+
private readonly OpenApiDocument _openApiDocument = new();
28+
29+
private readonly EntitySetGetOperationHandler _operationHandler;
2230

2331
[Theory]
2432
[InlineData(true, true, true)]
@@ -41,6 +49,7 @@ public void CreateEntitySetGetOperationReturnsCorrectOperation(bool enableOperat
4149

4250
// Act
4351
var get = _operationHandler.CreateOperation(context, path);
52+
_openApiDocument.Tags = context.CreateTags();
4453

4554
// Assert
4655
Assert.NotNull(get);

0 commit comments

Comments
 (0)