Skip to content

Commit 7ec682b

Browse files
committed
Add csdl conversion tests
1 parent 73339e1 commit 7ec682b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.IO;
6+
using Microsoft.OpenApi.Hidi;
7+
using Microsoft.OpenApi.Services;
8+
using Xunit;
9+
10+
namespace Microsoft.OpenApi.Tests.Services
11+
{
12+
public class OpenApiCSDLConversionTests
13+
{
14+
[Fact]
15+
public void ReturnConvertedCSDLFile()
16+
{
17+
// Arrange
18+
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\Todo.xml");
19+
var fileInput = new FileInfo(filePath);
20+
var csdlStream = fileInput.OpenRead();
21+
22+
// Act
23+
var openApiDoc = OpenApiService.ConvertCsdlToOpenApi(csdlStream);
24+
var expectedPathCount = 5;
25+
26+
// Assert
27+
Assert.NotNull(openApiDoc);
28+
Assert.NotEmpty(openApiDoc.Paths);
29+
Assert.Equal(openApiDoc.Paths.Count, expectedPathCount);
30+
}
31+
32+
[Theory]
33+
[InlineData("Todos.Todo.UpdateTodo",null, 1)]
34+
[InlineData("Todos.Todo.ListTodo",null, 1)]
35+
[InlineData(null, "Todos.Todo", 4)]
36+
public void ReturnFilteredOpenApiDocumentBasedOnOperationIdsAndInputCsdlDocument(string operationIds, string tags, int expectedPathCount)
37+
{
38+
// Arrange
39+
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\Todo.xml");
40+
var fileInput = new FileInfo(filePath);
41+
var csdlStream = fileInput.OpenRead();
42+
43+
// Act
44+
var openApiDoc = OpenApiService.ConvertCsdlToOpenApi(csdlStream);
45+
var predicate = OpenApiFilterService.CreatePredicate(operationIds, tags);
46+
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(openApiDoc, predicate);
47+
48+
// Assert
49+
Assert.NotNull(subsetOpenApiDocument);
50+
Assert.NotEmpty(subsetOpenApiDocument.Paths);
51+
Assert.Equal(expectedPathCount, subsetOpenApiDocument.Paths.Count);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)