Removed FromBody
This commit is contained in:
parent
db44756142
commit
de048b6842
40
.vscode/thunder-tests/thunderActivity.json
vendored
40
.vscode/thunder-tests/thunderActivity.json
vendored
@ -147,7 +147,45 @@
|
||||
"method": "GET",
|
||||
"sortNum": 0,
|
||||
"created": "2023-03-07T17:21:05.219Z",
|
||||
"modified": "2023-03-07T17:28:47.716Z",
|
||||
"modified": "2023-03-07T19:35:11.146Z",
|
||||
"headers": [],
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "json",
|
||||
"raw": "{\n \"PSN\": \"5296\",\n \"RDS\": \"578280\",\n \"Reactor\": \"37\",\n \"ID\": 1678216576\n}",
|
||||
"form": []
|
||||
},
|
||||
"tests": []
|
||||
},
|
||||
{
|
||||
"_id": "6d8098aa-eb50-422e-b38d-32709d985e8e",
|
||||
"colId": "history",
|
||||
"containerId": "",
|
||||
"name": "GetHeaders-Dev",
|
||||
"url": "http://mestsa008/api/export/headers",
|
||||
"method": "POST",
|
||||
"sortNum": 0,
|
||||
"created": "2023-03-07T17:21:05.219Z",
|
||||
"modified": "2023-03-08T16:39:11.451Z",
|
||||
"headers": [],
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "json",
|
||||
"raw": "{\n \"MesEntity\": \"CDE5\",\n \"Employee\": \"Operator\",\n \"Layer\": \"-\",\n \"PSN\": \"5008\",\n \"RDS\": \"579487\",\n \"Reactor\": \"61\",\n \"Recipe\": \"LSL8IN \\\\ 10PT_5mm\",\n \"Zone\": \"-\",\n \"Ticks\": 638137811504314166,\n \"ID\": 1678209360\n}",
|
||||
"form": []
|
||||
},
|
||||
"tests": []
|
||||
},
|
||||
{
|
||||
"_id": "61383ad6-ceb4-4d98-86c1-bf00c0e4204d",
|
||||
"colId": "history",
|
||||
"containerId": "",
|
||||
"name": "GetHeaders-localhost",
|
||||
"url": "http://localhost:5126/api/export/headers",
|
||||
"method": "GET",
|
||||
"sortNum": 0,
|
||||
"created": "2023-03-07T17:21:05.219Z",
|
||||
"modified": "2023-03-08T16:05:18.727Z",
|
||||
"headers": [],
|
||||
"params": [],
|
||||
"body": {
|
||||
|
@ -15,25 +15,60 @@ public class ExportController : Controller, IExportController<IActionResult>
|
||||
public ExportController(IExportRepository exportRepository) =>
|
||||
_ExportRepository = exportRepository;
|
||||
|
||||
private static HeaderCommon GetHeaderCommon(Stream stream)
|
||||
{
|
||||
HeaderCommon? result;
|
||||
if (!stream.CanRead)
|
||||
result = new();
|
||||
else
|
||||
{
|
||||
Task<string> task = new StreamReader(stream).ReadToEndAsync();
|
||||
result = string.IsNullOrEmpty(task.Result) ? null : JsonSerializer.Deserialize<HeaderCommon>(task.Result);
|
||||
result ??= new();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("export")]
|
||||
public IActionResult GetExport(HeaderCommon headerCommon) =>
|
||||
Content(_ExportRepository.GetExport(headerCommon));
|
||||
public IActionResult GetExport() =>
|
||||
Content(_ExportRepository.GetExport(GetHeaderCommon(Request.Body)));
|
||||
|
||||
[HttpGet]
|
||||
[Route("headers")]
|
||||
public IActionResult GetHeaders(HeaderCommon headerCommon) =>
|
||||
Json(_ExportRepository.GetHeaders(headerCommon), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
public IActionResult GetHeaders() =>
|
||||
Json(_ExportRepository.GetHeaders(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpGet]
|
||||
[Route("logistics")]
|
||||
public IActionResult GetLogistics(HeaderCommon headerCommon) =>
|
||||
Json(_ExportRepository.GetLogistics(headerCommon), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
public IActionResult GetLogistics() =>
|
||||
Json(_ExportRepository.GetLogistics(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpGet]
|
||||
[Route("pdsf")]
|
||||
[Route("processDataStandardFormat")]
|
||||
public IActionResult GetProcessDataStandardFormat(HeaderCommon headerCommon) =>
|
||||
Content(_ExportRepository.GetProcessDataStandardFormat(headerCommon));
|
||||
public IActionResult GetProcessDataStandardFormat() =>
|
||||
Content(_ExportRepository.GetProcessDataStandardFormat(GetHeaderCommon(Request.Body)));
|
||||
|
||||
[HttpPost]
|
||||
[Route("export")]
|
||||
public IActionResult PostExport() =>
|
||||
Content(_ExportRepository.GetExport(GetHeaderCommon(Request.Body)));
|
||||
|
||||
[HttpPost]
|
||||
[Route("headers")]
|
||||
public IActionResult PostHeaders() =>
|
||||
Json(_ExportRepository.GetHeaders(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpPost]
|
||||
[Route("logistics")]
|
||||
public IActionResult PostLogistics() =>
|
||||
Json(_ExportRepository.GetLogistics(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpPost]
|
||||
[Route("pdsf")]
|
||||
[Route("processDataStandardFormat")]
|
||||
public IActionResult PostProcessDataStandardFormat() =>
|
||||
Content(_ExportRepository.GetProcessDataStandardFormat(GetHeaderCommon(Request.Body)));
|
||||
|
||||
}
|
@ -30,9 +30,24 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
}
|
||||
|
||||
private static JToken GetJToken(Stream stream)
|
||||
{
|
||||
JToken jsonbody;
|
||||
if (!stream.CanRead)
|
||||
jsonbody = JToken.Parse("{}");
|
||||
else
|
||||
{
|
||||
if (stream.CanSeek)
|
||||
_ = stream.Seek(0, SeekOrigin.Begin);
|
||||
string json = new StreamReader(stream).ReadToEnd();
|
||||
jsonbody = JToken.Parse(json);
|
||||
}
|
||||
return jsonbody;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{tooltype}")]
|
||||
public IActionResult Post(string tooltype, [FromBody] JToken jsonbody)
|
||||
public IActionResult Post(string tooltype)
|
||||
{
|
||||
IPAddress? remoteIP = HttpContext.Connection.RemoteIpAddress;
|
||||
if (!_InboundRepository.IsIPAddressAllowed(_AppSettings.InboundApiAllowedIPList, remoteIP))
|
||||
@ -42,18 +57,7 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonbody is null || !jsonbody.Any())
|
||||
{
|
||||
if (!Request.Body.CanRead)
|
||||
jsonbody = JToken.Parse("{}");
|
||||
else
|
||||
{
|
||||
using Stream stream = Request.Body;
|
||||
_ = stream.Seek(0, SeekOrigin.Begin);
|
||||
string json = new StreamReader(stream).ReadToEnd();
|
||||
jsonbody = JToken.Parse(json);
|
||||
}
|
||||
}
|
||||
JToken jsonbody = GetJToken(Request.Body);
|
||||
DataResponse dataResponse = _InboundRepository.Data(_MetrologyRepository, _InboundDataService, tooltype, jsonbody);
|
||||
if (!dataResponse.Errors.Any())
|
||||
return Ok(dataResponse);
|
||||
|
@ -96,7 +96,6 @@ public class ExportRepository : IExportRepository
|
||||
};
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
Result<HeaderCommon[]> IExportRepository.GetLogistics(HeaderCommon headerCommon)
|
||||
|
@ -1,5 +1,3 @@
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
|
||||
namespace OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
public interface IExportController<T>
|
||||
@ -14,9 +12,13 @@ public interface IExportController<T>
|
||||
}
|
||||
|
||||
static string GetRouteName() => nameof(IExportController<T>)[1..^10];
|
||||
T GetExport(HeaderCommon headerCommon);
|
||||
T GetHeaders(HeaderCommon headerCommon);
|
||||
T GetLogistics(HeaderCommon headerCommon);
|
||||
T GetProcessDataStandardFormat(HeaderCommon headerCommon);
|
||||
T GetExport();
|
||||
T GetHeaders();
|
||||
T GetLogistics();
|
||||
T GetProcessDataStandardFormat();
|
||||
T PostExport();
|
||||
T PostHeaders();
|
||||
T PostLogistics();
|
||||
T PostProcessDataStandardFormat();
|
||||
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
public interface IInboundController<T>
|
||||
@ -11,7 +9,7 @@ public interface IInboundController<T>
|
||||
}
|
||||
|
||||
static string GetRouteName() => nameof(IInboundController<T>)[1..^10];
|
||||
T Post(string tooltype, JToken jsonbody);
|
||||
T Post(string tooltype);
|
||||
T AttachFile(string tooltype, long headerid, string datauniqueid = "");
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
using System.Text;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -39,6 +40,9 @@ public class UnitTestExportController
|
||||
private static HeaderCommon GetHeaderCommon() =>
|
||||
new() { PSN = "5008", Reactor = "61", RDS = "579487", ID = 1678209360 };
|
||||
|
||||
private static StringContent GetStringContent() =>
|
||||
new(System.Text.Json.JsonSerializer.Serialize(GetHeaderCommon()), Encoding.UTF8, "application/json");
|
||||
|
||||
[TestMethod]
|
||||
public void GetExport()
|
||||
{
|
||||
@ -55,12 +59,22 @@ public class UnitTestExportController
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/headers");
|
||||
string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/export");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetExport)}.txt"), result);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostExportApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/export", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetHeaders()
|
||||
{
|
||||
@ -84,6 +98,16 @@ public class UnitTestExportController
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostHeadersApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/headers", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetLogistics()
|
||||
{
|
||||
@ -100,13 +124,23 @@ public class UnitTestExportController
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/headers");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/logistics");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetLogistics)}.json"), json);
|
||||
Result<HeaderCommon[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostLogisticsApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/logistics", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetProcessDataStandardFormat()
|
||||
{
|
||||
@ -123,10 +157,20 @@ public class UnitTestExportController
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/headers");
|
||||
string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/processDataStandardFormat");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetProcessDataStandardFormat)}.pdsf"), result);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostProcessDataStandardFormatApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/processDataStandardFormat", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user