-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds unit tests for plugin generation service
Signed-off-by: Vincent Biret <[email protected]>
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Kiota.Builder.Configuration; | ||
using Kiota.Builder.Plugins; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.OpenApi.Services; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Kiota.Builder.Tests.Plugins; | ||
public sealed class PluginsGenerationServiceTests : IDisposable | ||
{ | ||
private readonly HttpClient _httpClient = new(); | ||
[Fact] | ||
public void Defensive() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new PluginsGenerationService(null, OpenApiUrlTreeNode.Create(), new())); | ||
Assert.Throws<ArgumentNullException>(() => new PluginsGenerationService(new(), null, new())); | ||
Assert.Throws<ArgumentNullException>(() => new PluginsGenerationService(new(), OpenApiUrlTreeNode.Create(), null)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_httpClient.Dispose(); | ||
} | ||
|
||
[Fact] | ||
public async Task GeneratesManifest() | ||
{ | ||
var simpleDescriptionContent = @"openapi: 3.0.0 | ||
info: | ||
title: test | ||
version: 1.0 | ||
paths: | ||
/test: | ||
get: | ||
responses: | ||
'200': | ||
description: test"; | ||
var simpleDescriptionPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()) + ".yaml"; | ||
await File.WriteAllTextAsync(simpleDescriptionPath, simpleDescriptionContent); | ||
var mockLogger = new Mock<ILogger<PluginsGenerationService>>(); | ||
var openAPIDocumentDS = new OpenApiDocumentDownloadService(_httpClient, mockLogger.Object); | ||
var outputDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
var generationConfiguration = new GenerationConfiguration | ||
{ | ||
OutputPath = outputDirectory, | ||
OpenAPIFilePath = "openapiPath", | ||
PluginTypes = [PluginType.APIManifest], | ||
ClientClassName = "client", | ||
}; | ||
var (openAPIDocumentStream, _) = await openAPIDocumentDS.LoadStreamAsync(simpleDescriptionPath, generationConfiguration, null, false); | ||
var openApiDocument = await openAPIDocumentDS.GetDocumentFromStreamAsync(openAPIDocumentStream, generationConfiguration); | ||
var urlTreeNode = OpenApiUrlTreeNode.Create(openApiDocument, Constants.DefaultOpenApiLabel); | ||
|
||
var pluginsGenerationService = new PluginsGenerationService(openApiDocument, urlTreeNode, generationConfiguration); | ||
await pluginsGenerationService.GenerateManifestAsync(); | ||
|
||
Assert.True(File.Exists(Path.Combine(outputDirectory, "manifest.json"))); | ||
Assert.True(File.Exists(Path.Combine(outputDirectory, "openapi.yml"))); | ||
} | ||
} |