Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
engineering87 committed Oct 13, 2024
1 parent 8348a77 commit 352bf77
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/OpenSharpTrace.Test/Utilities/NetworkTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// (c) 2022 Francesco Del Re <francesco.delre.87@gmail.com>
// This code is licensed under MIT license (see LICENSE.txt for details)
using System;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using OpenSharpTrace.Utilities;

namespace OpenSharpTrace.Test.Utilities
Expand All @@ -15,8 +13,8 @@ public void CleanNotationAddress()
var address = "::ffff:10.18.1.1";
var cleanAddress = Network.CleanNotationAddress(address);

ClassicAssert.IsNotNull(cleanAddress);
ClassicAssert.IsTrue(cleanAddress == "10.18.1.1");
Assert.That(cleanAddress, Is.Not.Null);
Assert.That(cleanAddress, Is.EqualTo("10.18.1.1"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class WeatherForecastController : OpenSharpTraceController

private readonly ILogger<WeatherForecastController> _logger;

private static readonly List<WeatherForecast> WeatherForecasts = new List<WeatherForecast>();

// OpenSharpTrace integration for ITraceQueue

public WeatherForecastController(
Expand All @@ -43,6 +45,18 @@ public IEnumerable<WeatherForecast> Get()
.ToArray();
}

[HttpGet]
[Route("/GetById/{id}")]
public IActionResult GetById(int id)
{
if (id < 0 || id >= WeatherForecasts.Count)
{
return NotFound("Forecast not found.");
}

return Ok(WeatherForecasts[id]);
}

[HttpGet]
[Route("/GetBadRequest")]
public IActionResult GetBadRequest()
Expand All @@ -56,5 +70,44 @@ public IActionResult GetException()
{
throw new Exception("Generic exception");
}

[HttpPost]
[Route("/Add")]
public IActionResult Add([FromBody] WeatherForecast forecast)
{
if (forecast == null)
{
return BadRequest("Invalid forecast data.");
}

WeatherForecasts.Add(forecast);
return CreatedAtAction(nameof(GetById), new { id = WeatherForecasts.Count - 1 }, forecast);
}

[HttpPut]
[Route("/Update/{id}")]
public IActionResult Update(int id, [FromBody] WeatherForecast forecast)
{
if (id < 0 || id >= WeatherForecasts.Count || forecast == null)
{
return BadRequest("Invalid forecast data or ID.");
}

WeatherForecasts[id] = forecast;
return NoContent(); // 204 No Content
}

[HttpDelete]
[Route("/Delete/{id}")]
public IActionResult Delete(int id)
{
if (id < 0 || id >= WeatherForecasts.Count)
{
return NotFound("Forecast not found.");
}

WeatherForecasts.RemoveAt(id);
return NoContent(); // 204 No Content
}
}
}
2 changes: 1 addition & 1 deletion src/OpenSharpTrace/Utilities/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class Network
/// <returns></returns>
public static string CleanNotationAddress(string address)
{
if (address?.Substring(0, 7) == "::ffff:")
if (address?[..7] == "::ffff:")
{
return address.Substring(7);
}
Expand Down

0 comments on commit 352bf77

Please sign in to comment.