Files
wapifuzz/parser/Parser.Tests/EndpointParserTests.cs
Jan Stárek 65b43ad7f0 Added .travisci file
Also few tests were fixed
2019-10-23 13:45:57 +02:00

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);
}
}
}