mirror of
https://github.com/ysoftdevs/wapifuzz.git
synced 2026-01-11 22:30:35 +01:00
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Threading;
|
|
using Microsoft.OpenApi.Models;
|
|
using NUnit.Framework;
|
|
using Models;
|
|
|
|
namespace Parser.Tests
|
|
{
|
|
public class EndpointParserTests
|
|
{
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
|
}
|
|
|
|
readonly OpenApiDocument _document = new OpenApiDocument {Paths = new OpenApiPaths()};
|
|
private void AddTwoTestingPaths()
|
|
{
|
|
_document.Paths.Add("/path1", new OpenApiPathItem
|
|
{
|
|
Operations = new Dictionary<OperationType, OpenApiOperation>
|
|
{
|
|
{ OperationType.Get, new OpenApiOperation
|
|
{
|
|
Responses = new OpenApiResponses
|
|
{
|
|
{ "200", new OpenApiResponse()}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
_document.Paths.Add("/path2", new OpenApiPathItem
|
|
{
|
|
Operations = new Dictionary<OperationType, OpenApiOperation>
|
|
{
|
|
{ OperationType.Get, new OpenApiOperation
|
|
{
|
|
Responses = new OpenApiResponses
|
|
{
|
|
{ "201", new OpenApiResponse()}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void DocumentWithoutAnyPathsShouldReturnEmptyList()
|
|
{
|
|
List<Endpoint> endpoints = EndpointParser.ParseAllEndpoints(_document);
|
|
|
|
Assert.IsEmpty(endpoints);
|
|
}
|
|
|
|
[Test]
|
|
public void DocumentWithTwoPathsEachHavingSingleResponseShouldReturnTwoEndpoints()
|
|
{
|
|
AddTwoTestingPaths();
|
|
|
|
List<Endpoint> endpoints = EndpointParser.ParseAllEndpoints(_document);
|
|
|
|
Assert.AreEqual(2, endpoints.Count);
|
|
}
|
|
}
|
|
}
|