Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ODS-6076] Update SmokeTest to use OpanAPI v3 #885

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 37 additions & 23 deletions Utilities/DataLoading/EdFi.LoadTools.Test/SmokeTests/APIGetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
// See the LICENSE and NOTICES files in the project root for more information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EdFi.LoadTools.ApiClient;
using EdFi.LoadTools.Engine;
using EdFi.LoadTools.SmokeTest.ApiTests;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using NUnit.Framework;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Swashbuckle.Swagger;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace EdFi.LoadTools.Test.SmokeTests
{
Expand All @@ -34,24 +36,32 @@ public class ApiGetTests
private const string PropertyName = "aProperty";

private const string Swagger =
@"{
paths: {
""TestNamespace/TestResource"": {
@"{
""openapi"": ""3.0.1"",
""info"": {},
""paths"": {
""/TestNamespace/TestResource"": {
""get"": {
""parameters"": [
{
""name"": ""TestIdentifier"",
""in"": ""query"",
""required"": false,
""type"": ""string""
""schema"": {
""type"": ""string""
}
}
],
""responses"": {
""200"": {
""schema"": {
""type"": ""array"",
""items"": {
""$ref"": ""#/definitions/edFi_academicWeek""
""content"":{
""application/json"": {
""schema"": {
""type"": ""array"",
""items"": {
""$ref"": ""#/components/schemas/edFi_academicWeek""
}
}
}
}
}
Expand All @@ -71,30 +81,34 @@ public class ApiGetTests
new JProperty("aProperty", "b"));

private readonly JArray _data = new JArray(Obj1, Obj2);
private readonly IOAuthSessionToken _token = Mock.Of<IOAuthSessionToken>(t => t.SessionToken == "something");

private readonly SwaggerDocument Doc = JsonConvert.DeserializeObject<SwaggerDocument>(Swagger);
private OpenApiDocument _doc;

private readonly IOAuthTokenHandler tokenHandler = Mock.Of<IOAuthTokenHandler>();
private readonly IOAuthTokenHandler _tokenHandler = Mock.Of<IOAuthTokenHandler>();

private Resource _resource;

[OneTimeSetUp]
public async Task Setup()
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Swagger)))
{
_doc = new OpenApiStreamReader().Read(ms, out var diag);
}

var config = new ConfigurationBuilder()
.SetBasePath(TestContext.CurrentContext.TestDirectory)
.AddJsonFile("appsettings.json", optional: true)
.AddEnvironmentVariables()
.Build();

Address = config.GetSection("TestingWebServerAddress").Value;

_doc.Servers.Add(new OpenApiServer { Url = $"{Address}data/v3" });
_resource = new Resource
{
Name = ResourceName,
BasePath = "",
Path = Doc.paths.Values.First()
BasePath = _doc.Servers.First().Url,
Path = _doc.Paths.Values.First()
};

// Create and start up the host
Expand Down Expand Up @@ -172,7 +186,7 @@ public async Task GetAll_should_store_results_in_dictionaryAsync()

var configuration = Mock.Of<IApiConfiguration>(cfg => cfg.Url == Address);

var subject = new GetAllTest(_resource, dictionary, configuration, tokenHandler);
var subject = new GetAllTest(_resource, dictionary, configuration, _tokenHandler);
var result = await subject.PerformTest();

Assert.IsNotNull(dictionary[ResourceName]);
Expand All @@ -185,7 +199,7 @@ public async Task GetSkipLimitTest_should_retrieve_second_objectAsync()
var dictionary = new Dictionary<string, JArray> { [ResourceName] = _data };

var configuration = Mock.Of<IApiConfiguration>(cfg => cfg.Url == Address);
var subject = new GetAllSkipLimitTest(_resource, dictionary, configuration, tokenHandler);
var subject = new GetAllSkipLimitTest(_resource, dictionary, configuration, _tokenHandler);
var result = await subject.PerformTest();

Assert.IsTrue(result);
Expand All @@ -197,7 +211,7 @@ public async Task GetByIdTest_should_retrieve_single_objectAsync()
var dictionary = new Dictionary<string, JArray> { [ResourceName] = _data };

var configuration = Mock.Of<IApiConfiguration>(cfg => cfg.Url == Address);
var subject = new GetByIdTest(_resource, dictionary, configuration, tokenHandler);
var subject = new GetByIdTest(_resource, dictionary, configuration, _tokenHandler);
var result = await subject.PerformTest();

Assert.IsTrue(result);
Expand All @@ -209,7 +223,7 @@ public async Task GetByExampleTest_should_retrieve_arrayAsync()
var dictionary = new Dictionary<string, JArray> { [ResourceName] = _data };

var configuration = Mock.Of<IApiConfiguration>(cfg => cfg.Url == Address);
var subject = new GetByExampleTest(_resource, dictionary, configuration, tokenHandler);
var subject = new GetByExampleTest(_resource, dictionary, configuration, _tokenHandler);
var result = await subject.PerformTest();

Assert.IsTrue(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using EdFi.LoadTools.Engine;
using EdFi.LoadTools.SmokeTest;
using EdFi.LoadTools.SmokeTest.PropertyBuilders;
using NUnit.Framework;
using Microsoft.OpenApi.Models;
using Moq;
using Swashbuckle.Swagger;
using NUnit.Framework;

// ReSharper disable InconsistentNaming
// ReSharper disable UnusedAutoPropertyAccessor.Local
Expand Down Expand Up @@ -59,9 +59,9 @@ public void ListPropertyBuilder_should_create_empty_list_when_required_is_true()

var propInfoMetadataLookup =
Mock.Of<IPropertyInfoMetadataLookup>(
x => x.GetMetadata(propInfo) == new Parameter
x => x.GetMetadata(propInfo) == new OpenApiParameter
{
required = true
Required = true
});

var builder = new ListPropertyBuilder(propInfoMetadataLookup);
Expand Down Expand Up @@ -111,9 +111,10 @@ public void StringPropertyBuilder_should_set_string_properties()

var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = true
Required = true,
Schema = new OpenApiSchema()
});

var builder = new StringPropertyBuilder(lookup);
Expand All @@ -135,9 +136,9 @@ public void TimeStringPropertyBuilder_should_set_string_properties()

var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = true
Required = true
});

var builder = new TimeStringPropertyBuilder(lookup);
Expand Down Expand Up @@ -176,9 +177,9 @@ public void DateTimePropertyBuilder_should_generate_a_value_for_a_required_prope

var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = true
Required = true
});
var builder = new DateTimePropertyBuilder(lookup);
Assert.IsTrue(builder.BuildProperty(obj, propInfo));
Expand All @@ -192,9 +193,9 @@ public void DateTimePropertyBuilder_should_not_generate_a_value_for_an_optional_
var propInfo = typeof(Class1).GetProperty("dateTimeProperty1");
var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = false
Required = false
});

var builder = new DateTimePropertyBuilder(lookup);
Expand Down Expand Up @@ -308,9 +309,9 @@ public void SimplePropertyBuilder_should_ignore_nullable_properties()

var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = false
Required = false
});

var builder = new SimplePropertyBuilder(lookup, Mock.Of<IDestructiveTestConfiguration>());
Expand All @@ -326,9 +327,10 @@ public void SimplePropertyBuilder_should_generate_a_value_if_required()

var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = true
Required = true,
Schema = new OpenApiSchema()
});

var builder = new SimplePropertyBuilder(lookup, Mock.Of<IDestructiveTestConfiguration>());
Expand All @@ -344,9 +346,9 @@ public void SimplePropertyBuilder_should_not_generate_a_value_if_optional()

var lookup = Mock.Of<IPropertyInfoMetadataLookup>(
f =>
f.GetMetadata(propInfo) == new Parameter
f.GetMetadata(propInfo) == new OpenApiParameter
{
required = false
Required = false
});

var builder = new SimplePropertyBuilder(lookup, Mock.Of<IDestructiveTestConfiguration>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

using System.Collections.Generic;
using System.Threading.Tasks;
using Swashbuckle.Swagger;
using Microsoft.OpenApi.Models;

namespace EdFi.LoadTools.ApiClient
{
public interface ISwaggerRetriever
{
Task<IDictionary<string, SwaggerDocument>> LoadMetadata();
Task<IDictionary<string, OpenApiDocument>> LoadMetadata();
}
}
Loading
Loading