kreta/Kreta.WebApi/Naplo/Kreta.Naplo.WebApi/V3/Documentation/DummyExampleProvider.cs
2024-03-13 00:33:46 +01:00

62 lines
2.4 KiB
C#

using System;
using Kreta.BusinessLogic.Interfaces;
using Kreta.Client.CoreApi;
using Kreta.Naplo.Dto.V3.Interfaces;
using Kreta.Naplo.WebApi.V3.Documentation.Helper;
using Kreta.Naplo.WebApi.V3.Documentation.MockServices;
using Swashbuckle.Examples;
namespace Kreta.Naplo.WebApi.V3.Documentation
{
internal class DummyExampleProvider<TController, TDto> : IExamplesProvider where TController : new() where TDto : IDtoDocumentation, new()
{
public object GetExamples()
{
object response = ExampleHelper.TryGetExampleFeatureDefaultExampleModel();
if (response != null)
{
return response;
}
TDto dto = new TDto();
object[] parameterArray = dto.Example.RequestParameter == null ? new object[] { } : new[] { dto.Example.RequestParameter };
ExampleHelper.MockUser(dto.Example.MockUserName);
return new
{
RequestExample = dto.Example.RequestParameter,
RequestExampleUser = dto.Example.MockUserName,
ResponseExample = typeof(TController).GetMethod(dto.Example.MethodName).Invoke(new TController(), parameterArray)
};
}
}
internal class DummyExampleProviderWithDependencyInjection<TController, TDto> : IExamplesProvider where TDto : IDtoDocumentation, new()
{
private readonly IFileServiceHelper _fileServiceHelper = new FileServiceHelperMock();
private readonly ICoreApiClient _coreApiClient = new CoreApiClientMock();
public object GetExamples()
{
object response = ExampleHelper.TryGetExampleFeatureDefaultExampleModel();
if (response != null)
{
return response;
}
TDto dto = new TDto();
object[] parameterArray = dto.Example.RequestParameter == null ? new object[] { } : new[] { dto.Example.RequestParameter };
ExampleHelper.MockUser(dto.Example.MockUserName);
return new
{
RequestExample = dto.Example.RequestParameter,
RequestExampleUser = dto.Example.MockUserName,
ResponseExample = typeof(TController).GetMethod(dto.Example.MethodName).Invoke((TController)Activator.CreateInstance(typeof(TController), _fileServiceHelper, _coreApiClient), parameterArray)
};
}
}
}